Reputation: 25156
I am using Java 1.6, Eclipse, and Ant.
The following is my target for creating a jar file and running it:
<!-- Settings -->
<property file="build.properties" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<!-- Compile -->
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
<classpath refid="classpath" />
</javac>
</target>
<!-- Package .jar -->
<target name="jar">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/App.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="main.App" />
</manifest>
</jar>
</target>
<!-- Run .jar -->
<target name="run">
<java jar="${jar.dir}/App.jar" fork="true" />
</target>
The problem is that when I run this jar (via Ant or command-line) I receive the error:
Exception in thread "main" java.lang.NoClassDefFoundError: net/xeoh/plugins/base/impl/PluginManagerFactory
[java] at plugins.PluginLoader.<clinit>(Unknown Source)
Some things that might be useful to know:
When I print my classpath, it shows that all the requisite JARs are there; it also shows up the Eclipse's GUI version of the class path.
I have tried cleaning the project (both via Eclipse and Ant) to no avail.
The library .jar that seems to be missing is not a .jar in a .jar (which seems to be a common problem).
This is the only error. Other classes seem to find the library alright...
Upvotes: 0
Views: 312
Reputation: 35048
You've set the compile classpath but the App.jar does not include your libs (only the classes you compiled) or a manifest classpath.
You'll need to do the following:
<target name="jar">
<mkdir dir="${jar.dir}" />
<manifestclasspath property="manifest.classpath"
jarfile="${jar.dir}/App.jar">
<classpath refid="classpath" />
</manifestclasspath>
<jar destfile="${jar.dir}/App.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="main.App" />
<attribute name="Class-Path" value="${manifest.classpath}" />.
</manifest>
</jar>
</target>
See also ant manifestclasspath task
Upvotes: 2