将MySQL连接器添加到ANT build.xml以进行JAVA编译

时间:2012-05-21 06:24:24

标签: java ant

我需要编译并运行一个java文件 - ClosureBuilder.java它似乎是编译但显示包含来自lib文件夹的外部jar的错误,mysql-connector-java-5.0.8-bin.jar

    <property name="lib.dir"     value="lib"/>

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


<target name="init">

    <mkdir dir="build/classes" />
    <mkdir dir="dist" />
</target>
<target name="compile" depends="init">
    <javac srcdir="src" destdir="build/classes"  classpathref="classpath"/>
</target>
<target name="compress" depends="compile">
    <jar destfile="dist/ClosureBuilder.jar" basedir="build/classes" />
</target>

<target name="execute" depends="compile">
    <java classname="ClosureBuilder" fork="true" classpath="build/classes" >
    <classpath>
             <path refid="classpath"/>
             <path location="build/${ant.project.name}.jar"/>
     </classpath>
    </java>
</target>

控制台显示:

 [java] Exception in thread "main" com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
 [java] ** BEGIN NESTED EXCEPTION ** 
 [java] java.net.ConnectException
 [java] MESSAGE: Connection refused
 [java] STACKTRACE:
 [java] java.net.ConnectException: Connection refused
 [java]     at java.net.PlainSocketImpl.socketConnect(Native Method)
 [java]     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
 [java]     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
 [java]     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
 [java]     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
 [java]     at java.net.Socket.connect(Socket.java:529)
 [java]     at java.net.Socket.connect(Socket.java:478)
 [java]     at java.net.Socket.<init>(Socket.java:375)
 [java]     at java.net.Socket.<init>(Socket.java:218)
 [java]     at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
 [java]     at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
 [java]     at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
 [java]     at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
 [java]     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
 [java]     at java.sql.DriverManager.getConnection(DriverManager.java:582)
 [java]     at java.sql.DriverManager.getConnection(DriverManager.java:207)
 [java]     at ClosureBuilder.start(Unknown Source)
 [java]     at ClosureBuilder.main(Unknown Source)
 [java] ** END NESTED EXCEPTION **
 [java] Last packet sent to the server was 0 ms ago.
 [java]     at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
 [java]     at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
 [java]     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
 [java]     at java.sql.DriverManager.getConnection(DriverManager.java:582)
 [java]     at java.sql.DriverManager.getConnection(DriverManager.java:207)
 [java]     at ClosureBuilder.start(Unknown Source)
 [java]     at ClosureBuilder.main(Unknown Source)

1 个答案:

答案 0 :(得分:0)

你可以帮助你here。从ant

为连接DB定义属性的位置