Ant构建文件也包括derby数据库jar

时间:2015-01-26 14:40:38

标签: java ant build

HY,

我有一个RMI,客户端服务器应用程序,它还需要在服务器端包含Derby数据库驱动程序

我的树结构如下所示:

s
│   buildcmmdc.xml
│   MyAnt.bat
│
├───lib
│       derbyclient.jar
│
└───src
    └───server
            derbyclient.jar
            ZodiacChinezesc.java
            Zodie.java
            ZodieImpl.java

我的Ant构建文件cmmdcbuild1.xml

<project name="Server" default="Install" basedir=".">
    <description>Server actions </description>

  <property name="path" location=".."/>
  <property name="lib-dir" location="${path}/s/lib"/>
  <property name="package" value="server"/>
  <property name="interface-jar" location="${path}/i/public/classes/zodie" />
  <property name="jar-file" value="zodie.jar" />
  <property name="service-class" value="ZodieImpl"  />
  <property name="port" value="1099"/>
  <property name="hostRMIRegistry" value="localhost"/>
  <property name="hostResources" value="localhost"/>
  <property name="DERBY_HOME" location="D:/soft/db-derby-10.11.1.1-bin"/>

  <target name="Install">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <delete dir="src"/>
    <mkdir dir="src"/>
    <delete dir="public"/>
    <mkdir dir="public"/>
    <delete dir="public/classes"/>
    <mkdir dir="public/classes"/>
  </target>

  <target name="Init">
    <mkdir dir="src/${package}"/>
    <mkdir dir="public/classes/${package}"/>
    <copy file="${interface-jar}/${jar-file}" todir="public/classes" />
  </target>

<path id="jars">
    <fileset dir="${lib-dir}"> <include name="*.jar"/> </fileset>
    <pathelement path="${DERBY_HOME}/lib/derby.jar" /> 
</path>

  <target name="Compile" depends="Init"
        description="compile the source " >
    <javac srcdir="src"
       includes="${package}/**" destdir="public/classes"
       classpath="public/classes/${jar-file}"
    classpathref="jars"
       includeantruntime="false"/>
    <unjar  src="public/classes/${jar-file}" dest="public/classes" />
  </target>

  <target name="Archive">
     <jar destfile="zodie.jar" basedir="public/classes">
       <include name="${package}/*"/>
       <include name="zodie/*"/>
     </jar>
  </target>

  <target name="Rmi">
     <exec executable="rmiregistry">
       <env key="classpath" value="public/classes"/>
       <arg value="${port}" />
     </exec>
  </target>

  <target name="Server">
     <java classname="${package}.${service-class}"
        classpath="${path}/s/public/classes" fork="true">  
        <jvmarg value="-Djava.rmi.server.codebase=file:${path}/s/public/classes/"/>    
        <!-- <jvmarg value="-Djava.security.policy=server.policy" />-->
        <!-- <jvmarg value="-Djava.rmi.server.hostname=guliguli" />-->
        <!--
        <jvmarg value="-Djava.rmi.server.codebase=http://${hostResources}:8080/rmi/zodie.jar" />
        -->
        <!--
        <jvmarg value="-Djava.rmi.server.codebase=ftp://${hostResources}:2121/rmi/zodie.jar" />
        -->
        <arg line="${hostRMIRegistry} ${port}"/>
     </java>
  </target> 
</project>

我看到不要将derbyclient.jar导入我的服务器端而且它找不到我的驱动程序。

如何修改构建以添加数据库驱动程序。

Sincereley,

`

1 个答案:

答案 0 :(得分:1)

在您的java标记中,使用classpathref属性,如下所示:

<java ..... classpathref="jars">