简体   繁体   English

如何在jar中添加jar包到项目中?

[英]How to add a jar package to project in eclipse?

I have added to my pom.xml a section that specifies the mainClass and allows it to essentially create an executable jar. 我在pom.xml中添加了一个部分,该部分指定mainClass并允许其本质上创建一个可执行jar。 I have included a bunch of dependencies that maven manages as well. 我已经包括了Maven管理的一堆依赖项。 It executes fine, but fails to run when it gets to a section of code that needs to know the location of a jar package that was made inhouse by somebody (ie, not from Maven). 它执行得很好,但是当它到达需要知道某人(例如,不是来自Maven)在内部制作的jar包的位置的一段代码时,便无法运行。 In the project in eclipse I had put the jar in src/lib and my code is in src/main/java. 在eclipse中的项目中,我将jar放在src / lib中,而我的代码在src / main / java中。 I had to select properties and Java Build Path and specify there the src/lib location for the jar to get it to even compile. 我必须选择属性和Java Build Path并在其中指定jar的src / lib位置才能使其进行编译。 However, trying to run java -jar name.jar has it fail and complain because it fails to import the classes from the src/lib jar. 但是,尝试运行java -jar name.jar会失败并抱怨,因为它无法从src / lib jar中导入类。 Since it is not a maven thing, how to I make sure this is a dependency for this project and that it is seen on the project's classpath? 由于这不是行家,我如何确保它是此项目的依赖项,并且可以在项目的类路径上看到它?

The thing with maven is that maven has to control all of the dependencies and that includes this jar you want to reference. 使用maven的事情是,maven必须控制所有依赖项,并且包括要引用的jar。 That doesn't mean that you have to build that other jar using maven, you could mvn install it in your local repository or use a tool like Artifactory to put it in a private remote repository. 这并不意味着您必须使用maven来构建其他jar,您可以将其mvn安装在本地存储库中,也可以使用Artifactory之类的工具将其放置在私有远程存储库中。 I know that installing regular jars via Artifactory creates a pom file for the jar and from then on you can treat the jar like any other maven dependency. 我知道通过Artifactory安装常规jar会为jar创建一个pom文件,然后您就可以像对待其他任何maven依赖项一样对待jar了。

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

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