简体   繁体   中英

Import external JAR Eclipse

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)?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM