读书人

一个ant小疑点运行jar需要外部包多

发布时间: 2012-01-08 22:48:50 作者: rapoo

一个ant小问题,运行jar需要外部包,谢谢!
当需要用到外部包时,例如Oracle的classes12.jar等
用:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<project name= "HelloAnt " default= "dist " basedir= ". ">

<!-- set global properties for this build -->
<property name= "src " value= ". "/>
<property name= "build " value= "classes "/>
<property name= "distribute " value= "dist "/>
<property name= "outFile " value= "Testant "/>
<property name= "lib " value= "./lib "/>
<property name= "mainClass.name " value= "testa.TestAnt "/>


<path id= "lib.path ">
<fileset dir= "${lib} ">
<include name= "**/*.jar "/>
</fileset>
</path>

<path id= "project.classpath ">
<pathelement location= "${build} "/>
</path>

<target name= "init ">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir= "${build} "/>
</target>

<target name= "compile " depends= "init ">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir= "${src} " destdir= "${build} " >
<classpath refid= "lib.path "/>
</javac>

</target>

<target name= "dist " depends= "compile ">
<!-- Create the distribution directory -->
<mkdir dir= "${distribute}/lib "/>

<!-- Put everything in ${build} into the output JAR file -->
<!-- Add a timestamp to the output filename as well -->
<jar jarfile= "${distribute}/lib/${outFile}-${DSTAMP}.jar " basedir= "${build} ">
<manifest>
<attribute name= "Main-Class " value= "${mainClass.name} "/>
</manifest>
<fileset dir= "${lib} ">
<include name= "**/*.jar "/>
</fileset>
</jar>
</target>

<target name= "clean ">
<!-- Delete the ${build} and ${distribute} directory trees -->
<delete dir= "${build} "/>
<delete dir= "${distribute} "/>
</target>

<target name= "building " depends= "compile " >


<java classname= "testa.Table " failonerror= "true " fork= "true ">
<arg value= "-h "/>
<classpath refid= "project.classpath "/>
<classpath refid= "lib.path "/>
</java>
<echo> If you see this, it works!!! </echo>
</target>

<target name= "runjar " depends= "dist " description= "run HelloWorld in jar file ">
<java jar= "${distribute}/lib/${outFile}-${DSTAMP}.jar "
fork= "true "
failonerror= "true "
maxmemory= "128m "
>
<arg value= "-h "/>
<classpath refid= "project.classpath "/>
<classpath refid= "lib.path "/>
</java>
</target>


</project>

运行ant building正确,但是运行ant runjar总提示:
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

请问该如何解决?


[解决办法]
这个应该加在你工程的环境中就可以了.
[解决办法]
若不行换odbc14.jar试试

读书人网 >Java Web开发

热点推荐