开发者

how to create empty jar file that references other jars in classpath

HI,

I have a large number of jars that my j2ee app depends on, so I want to create a single jar file with开发者_Python百科 manifest attribute referencing those jar files in classpath. Then I will place this file in glassfish lib dir so that jars mentioned become in classpath for application.

the only problem is I dont know how to create this single jar file.

suggestions ?

regards


The jar program (used to create jars) has a -m entry used to specify a manifest file.

In this manifest file, you could specify the location of other jar files with the Class-Path attribute.

See here: http://download.oracle.com/javase/1.3/docs/guide/jar/jar.html

I personally haven't tried this, so I don't know how successful this would be.

You might want to just create a large jar file that contains all of your other jar files if you are concerned about this. I don't know if I would recommend this solution either.


What you are describing should work fine. When a jar is loaded that has a Class-Path entry in it's manifest.mf, all referenced jars will get added to the class path. If you happen to be using maven, they have a very simple way of adding the classpath to a jar's generated manifest.

All dependencies of the maven project will get added to the Class-Path entry.

Adding a classpath via maven.

If you choose to use the jar program, you can model your manifest off of the example from the above link.

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: ${user.name}
Build-Jdk: ${java.version}
Class-Path: plexus-utils-1.1.jar commons-lang-2.1.jar
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜