开发者

Creating jar files using Eclipse

I need to create a jar file using eclipse IDE. But I am facing with a problem of adding referencing jars to the jar I am creating... after creating a jar for my project, when I run it using command prompt (I use command prompt because I need to input a file as a command line argument) it gives an exception saying "class not found" and that particular class is in that referencing jar file...

I tried to overcome my problem using the way instructed in the following link but still the problem exists...

http://开发者_JS百科www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

Can anyone please help me with this? Thanx in advance...


You can create a runnable jar that includes all dependencies using the Export wizard.

Go to "Export > Runnable JAR File", and select "Package required libraries into generated JAR".


Are you creating an executable jar? When creating an executable jar (ie: it has a main class, and a manifest) using eclipse, there is an option to include references.


You can use an ant script to do that for you:

<target name="dist" description="dist" depends="compile">
    <jar destfile="executable.jar">
            <manifest>
                    <attribute name="Main-Class" value="com.foo.MainClass"/>
            </manifest>     
        <fileset dir="build" />
        <zipfileset src="lib/commons-beanutils.jar"/>           
        <zipfileset src="lib/commons-logging-1.1.jar"/>
            <!-- Replace with your libraries -->
    </jar>  
</target>

http://www.coderslog.com/ANT_SCRIPTS_Executable_Jar_With_Dependencies


Note that the article you are referring to only tells you how to add the additional jars to your buildpath, so Eclipse can build your project. You still need some (or all) of them also on your classpath when running your application. The already provided answers give more information on how to actually add them to your application jar, but you can also simply reference to the (lib) map you've placed all the jars in with the -classpath argument. See http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html So basically you have to make sure that the jars you need are referenced both at runtime (using the classpath argument or using one of the other answers) as well as at build time (using the solution mentioned in the by you referred link).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜