问题描述
我有有在包com.nik.mypackage主要方法类的Java项目。仅一个库中引用这是someLib-5.0.2.jar
I have a java project with class having main method in package com.nik.mypackage. Only one library is referenced which is someLib-5.0.2.jar
这个库是在Eclipse lib文件夹,并添加到构建路径。
This library is in lib folder in eclipse and added to the build path.
我使用的是下面的ant脚本目标创建应用程序的可执行的JAR:
I am creating executable jar of the application using the below ant script target:
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<pathelement path="${classpath}"/>
<pathelement location="lib/someLib-5.0.2.jar"/>
</classpath>
</javac>
</target>
<target name="dist" depends="compile" description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<copy todir="${build}/lib" verbose="true" file="lib/someLib-5.0.2.jar" />
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/myProject-${DSTAMP}.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="com.nik.mypackage.MainClass"/>
<attribute name="Class-Path" value="../lib/someLib.jar"/>
</manifest>
</jar>
</target>
是越来越创建的JAR MyProject的-20111126.jar。但是,运行下面的命令:
The jar MyProject-20111126.jar is getting created. However, running the below command:
c:>java -jar MyProject-20111126.jar
抛出的NoClassDefFoundError在someLib.jar类
is throwing a NoClassDefFoundError for a class in someLib.jar
我在做什么错了?
感谢您阅读!
推荐答案
正如埃里克·罗森堡在评论中提及,我们不能内的其他jar文件窝jar文件。因此,我们需要对通货紧缩图书馆和应用程序捆绑罐单独的类。
As mentioned in the comment by Eric Rosenberg, we can not nest jar files inside other jar files. So we need to deflat the library and bundle individual classes in the app jar.
这篇关于NoClassDefFound错误罐子使用Ant构建创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!