开发者

How do you include .jar files in a Java library? [closed]

It's difficult to tell what is being asked here. This question is ambiguo开发者_运维技巧us, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 13 years ago.

How do you include .jar files in a Java library so that it can be imported directly in a program?


hmm. using ant the folloeing may help

<target name="CreateExecutableJarFileWithExternalLibrary">
    <jar destfile="MyApplication.jar">
        <zipfileset dir="classes" prefix="" />
        <zipfileset src="external.jar" />
        <manifest>
            <attribute name="Main-Class" value="mypackage.MyMainClass" />
        </manifest>
    </jar>
</target>

But you shall provide more information. In general I don't think that it's good style to provide a jar in a jar...


Sounds like you want to bundle your project, including dependencies, into a single jar file.

Try one of the following:

  • The unfortunately named Jar Jar Links
  • One Jar
  • I used to use Fat Jar Eclipse Plugin, which appears to be integrated into the latest Eclipse releases.


I think you want to include a classpath entry in the MANIFEST.MF. I can't believe this question hasn't been already answered on SO. Here are the instructions. Best way to to this ist using the ant snippet from tuergeist, because fiddling with the classpath entry is a bit cumbersome.

UPDATE: This works also inside a EAR file. Most container do allow referencing JAR files inside the ear itself. The container has to use a special class loader for this.


I think your question needs to be clarified.

But, either add them to your CLASSPATH environment variable or use -classpath on java.exe


To clarify, you can't enclose jars within jars. If you're build a .jar library, then you effectively have 2 options:

  1. build your .jar of your code, and specify the additional .jars to go alongside. They will have to be referenced on the classpath with your jar
  2. or, explode the additional .jars, and rejar with your code into one huge .jar. That has the pro of being simple to manage, and the downside that you should be careful exploding and recombining jars in case there are duplicate classes and you get the wrong one (or omit non .class resources etc.)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜