I have a Maven project where I've imported an external JAR (via Build Path) and it's under Referenced libraries folder. How can I import it within my .java class file? I mean literally the code "import ??". The class is in com.example.demo package. Do I need to add a dependency somewhere (pom.xml)?
Asked
Active
Viewed 229 times
0
-
`import com.example.demo.NameOfClass` does not work? – JimmyB Nov 27 '18 at 10:01
1 Answers
0
If that's a maven project the best way would be to add that jar as a dependency in your pom.xml dependencies section. Then when you compile with maven it will use that dependency. In order to build properly in eclipse you need to call mvn eclipse:eclipse and it will sync the dependencies in the pom.xml with the build paths of the eclipse project.
If the jar is not a common one and you cannot add find it in the public repo (for example some jar that you have created) then you need to first install it in your maven repository with the required group and artefact name. Otherwise if it is some library which is publicly available in the central maven repository maven will download the required jar and install it in your local repository for you

Veselin Davidov
- 7,031
- 1
- 15
- 23
-
Okay, it is the second case. So I have installed it using the command from the first post here https://stackoverflow.com/questions/4323981/how-to-install-jars-in-maven-repository-which-is-eclipse-embedded It installed successfully, meaning I can see it in my .m2 repository. How do I now import it into my project? If I go and add it via Build Path, it shows in the Referenced libraries, this time with a version and all, but I still don't know how to use the classes from it. How do I import it in the code? Thanks – user1418018 Nov 27 '18 at 12:32