开发者

Exporting JAR projects that use a common project

I have 4 different Java Projects created in Eclipse.

One of them contains all my Utilities and Helper methods, that the other 3 projects use.

I don't want to copy that same package 3 times into each project, since I want to be able to just edit it in one place if I should have to. So, I have referenced the myUtilities project from all other 3 projects.

I'll be exporting the 3 main projects and they will be going to different servers to run independently as "java -jar myprojec开发者_高级运维t.jar"

Everytime I do an export, the myUtilities.jar is not getting compiled in the JAR. If I open the JAR, I can see it is not there. And this is going to be a problem when I move them to the other servers.

Is there a way to add the package into the source for the JAR? Or am I going to have to copy the myUtilities.jar into the JAVA_HOME of each server?

This is my current Manifest file:

Manifest-Version: 1.0
Main-Class: com.elcool.process.alpha.RetrieverMain


You can place a reference to the external utility jars (myUtility.jar in your question) in the manifest in your project (myproject.jar). The manifest is a text file within the jar of your project, and many build tools support adding information to it.

This way, you can compile your utility jar once, make a reference to it in your projects, and deploy it alongside the three main projects, perhaps in the same directory or a nearby subdirectory.


You should use "Export" -> "Runnable Jar" to have dependent projects included correctly.

There are three different kinds of runnable jars, depending on you want a single jar-file with all classes, a single jar file with dependent jars and a correct Class-Path in the manifest, and a single jar file with the dependent jars enclosed and a special classloader understanding this.


Copy into JAVA_HOME? That's not the way to do anything. You should never do that.

If it's a web project, you'll have to copy the JAR into the WEB-INF/lib for each project.

If it's not a web project, you'll have to package that JAR up with the main JAR and add it to the CLASSPATH. I'll assume that the main is either an executable JAR with a manifest or that you've got a script to execute the main so you can encapsulate the CLASSPATH into it.


You may also add Classpath references in the executable jar file MANIFEST.MF or for more experienced users use maven assembly plugin which will create artefact with all its dependencies packed within a single jar.


Everytime I do an export, the myUtilities.jar is not getting compiled in the JAR. If I open the JAR, I can see it is not there.

How do you create it? A jar file is just renamed zip with manifest file, so consider building it yourself in case your tool doesn't suit your need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜