简体   繁体   English

如何导出将在另一个Java项目中使用的jar以及jar使用的整个maven /外部依赖关系?

[英]How do I export a jar that will be used in another Java project, along with the entire maven/external dependencies that the jar uses?

Sorry if my title isn't clear. 抱歉,我的标题不清楚。

Some of my team members have built a jar for me to use, which we'll call B. That jar in turn uses a particular maven dependency (purejavacomm) which we'll call C. They gave me B by exporting it as a runnable jar, selecting the "Package required libraries" option. 我的一些团队成员已经构建了一个供我使用的jar,我们将其称为B。该jar又使用了一个特定的maven依赖项(purejavacomm),我们将其称为C。他们通过将B导出为可运行对象而给了我B jar,选择“打包所需的库”选项。 However, when I import B into my project and try to use it, I get a java.lang. 但是,当我将B导入我的项目并尝试使用它时,我得到了一个java.lang。 NoClassDefFoundError and a java.lang.ClassNotFoundException in regards to some classes in C (specifically a custom exception class). 关于C中的某些类(特别是自定义异常类),提供了NoClassDefFoundError和java.lang.ClassNotFoundException。 I'm guessing these classes are those which aren't explicitly called anywhere in B, which is why they're not packaged with it. 我猜这些类是在B的任何地方都没有显式调用的类,这就是为什么不将它们打包在一起的原因。

So unless I include the maven dependency for C in my own pom, I can't use B. Is it possible for them to export their B in such a way that I don't have to explicitly add C? 因此,除非我在自己的pom中包含对C的maven依赖项,否则我将无法使用B。它们是否有可能以不必显式添加C的方式导出B? ie Make sure that the entirety of C is included with B, not just the classes that are explicitly used? 即确保C的全部包含在B中,而不仅是显式使用的类?

We're using Eclipse and m2e, so we haven't run any of this through mavens command line statements. 我们正在使用Eclipse和m2e,因此我们还没有通过mavens命令行语句来运行这些工具。

I'm assuming your problem occurs at runtime. 我假设您的问题发生在运行时。 If you indicate the dependency for C in your pom.xml B as <scope>provided<scope> , and include C.jar in your run time environment (say under lib folder of project), you tell maven that you are taking care of your dependency for C.jar. 如果您在pom.xml B中将C的依赖项表示为<scope>provided<scope> ,并在运行时环境中包含C.jar(例如在项目的lib文件夹下),则告诉maven您正在照顾您对C.jar的依赖。 This will solve your problem. 这样可以解决您的问题。

You should use your own maven repository at your company (see Maven best practices ). 您应该在公司使用自己的Maven存储库(请参阅Maven最佳实践 )。

It works like a proxy for public repositories and in addition you can push your own internal JARs to your repo. 它像公共存储库的代理一样工作,此外,您还可以将自己的内部JAR推送到您的存储库中。

Then in your maven configuration you should point to only your corporate repo. 然后,在您的Maven配置中,您应该仅指向公司回购。 Then your team members can publish their JAR B into the repo and you only have to add the dependency to B in your own POM. 然后,您的团队成员可以将其JAR B发布到仓库中,而您只需要在您自己的POM中将依赖项添加到B。

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

相关问题 如何导出具有外部Jar依赖项的Eclipse项目? - How to export an Eclipse Project with External Jar dependencies? 如何创建一个由buildpath使用的依赖项的Maven项目jar? - How to create a Maven project jar with dependencies which are used by the buildpath? 如何在Eclipse中构建Java项目以创建外部JAR - How do I build a Java project in Eclipse, to create an external JAR 如何使用具有外部依赖项的maven创建和运行可执行jar? - How do I create and run an executable jar with maven that has external dependencies? 如何从Maven pom.xml构建项目的jar文件及其依赖项? - How to build a jar file of a project along with its dependencies from Maven pom.xml? 如何在Intellij的同一jar中导出JavaFX应用程序和依赖项? - How do I export a JavaFX Application and dependencies in the same jar in Intellij? 使用非提供的依赖项导出jar Eclipse Maven Project - Export jar Eclipse Maven Project with just non-provided dependencies 如何使用Ant为具有外部jar依赖项的Java项目构建可分发jar - How to build a distributable jar with Ant for a java project having external jar dependencies 如何将外部jar依赖项包含到Maven项目中? - How to include external jar dependency to maven project? 具有Maven依赖关系的Google Plus Java Cli Starter导出jar - Google Plus Java Cli Starter export jar with Maven Dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM