简体   繁体   中英

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. However, when I import B into my project and try to use it, I get a java.lang. NoClassDefFoundError and a java.lang.ClassNotFoundException in regards to some classes in C (specifically a custom exception class). I'm guessing these classes are those which aren't explicitly called anywhere in B, which is why they're not packaged with it.

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? ie Make sure that the entirety of C is included with B, not just the classes that are explicitly used?

We're using Eclipse and m2e, so we haven't run any of this through mavens command line statements.

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. This will solve your problem.

You should use your own maven repository at your company (see Maven best practices ).

It works like a proxy for public repositories and in addition you can push your own internal JARs to your repo.

Then in your maven configuration you should point to only your corporate repo. 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.

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