简体   繁体   English

导入外部JAR Eclipse

[英]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. 我有一个Maven项目,其中(通过“构建路径”)导入了一个外部JAR,它位于“引用的库”文件夹下。 How can I import it within my .java class file? 如何将其导入我的.java类文件中? I mean literally the code "import ??". 我的意思是说代码“ import?”。 The class is in com.example.demo package. 该类在com.example.demo包中。 Do I need to add a dependency somewhere (pom.xml)? 我是否需要在某处添加依赖项(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. 如果这是一个Maven项目,最好的方法是将该jar添加为pom.xml依赖项部分中的依赖项。 Then when you compile with maven it will use that dependency. 然后,当您使用maven进行编译时,它将使用该依赖关系。 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. 为了在eclipse中正确构建,您需要调用mvn eclipse:eclipse ,它将把pom.xml中的依赖项与eclipse项目的构建路径同步。

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. 如果该jar不是常见的jar,并且您无法在公共存储库中添加它(例如,您创建的某个jar),则需要首先使用所需的组和工件名称安装在maven存储库中。 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 否则,如果它是中央Maven存储库中公开可用的某个库,则maven将下载所需的jar并将其安装在您的本地存储库中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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