1
我想執行使用ant創建的jar文件。但我無法找出爲什麼庫在執行jar時不可用。 我想加載德比嵌入式數據庫驅動,但一些我沒有得到類路徑中的derby.jar。當通過螞蟻執行jar時出現類路徑錯誤
錯誤,那是我得到是
[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)
一個
<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}/">
<classpath 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>