classpath error when executing a jar by ant
I am trying to execute a jar file created using ant. But i am not able to find out why libraries are not available while executing jar. I am trying to load derby embedded database driver but some how i am not getting derby.jar in classpath.
Error that i am getting is
[java] Unable to load the JDBC driver org.apache.derby.jdbc.EmbeddedDriver
[java] Please check your CLASSPATH.
[java] java.lang.ClassNotFoundExcepApplication Started
[java] tion: org.apache.derby.jdbc.EmbeddedDriver
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
a
<path id="jar.classpath">
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<path id="compiled-src.jar.classpath">
<path refid="jar.classpath" />
<pathelement location="${build.classes.dir}" />
</path>
<target name="jar" depends="compile-src" description="Create Jar">
<mkdir dir="${dist.dir}" />
<manifestclasspath property="lib.list" jarfile="${dist.dir}/">
<classp开发者_JS百科ath refid="jar.classpath" />
</manifestclasspath>
<jar destfile="${dist.dir}/${ant.project.name}.jar" basedir="${build.classes.dir}" >
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${lib.list}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar" description="Run application from jar">
<java jar="${dist.dir}/${ant.project.name}.jar" fork="true" />
</target>
The jarfile parameter to manifestclasspath needs to be a filename and not a directory name.
Try the following:
<manifestclasspath property="lib.list" jarfile="${dist.dir}/acme.jar">
<classpath refid="jar.classpath" />
</manifestclasspath>
My understanding of how the task works is that it generates a classpath relative to the jarfile name you provide (The filename does not have to exist)
精彩评论