在ant构建文件中导入jar文件

时间:2013-03-31 16:13:56

标签: java ant build jar

我正在尝试编译一个从jar导入类的项目,但它无法正常工作。这是我的主要课程:

package sample.calendar;
import org.jasypt.util.password.*;
public class OutlookToGmailCalendarSync {
  public static void main(String[] args) {
    System.out.println("hi");
  }
}

这是我的build.xml:

<project name="MyCalendarSample" default="run" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <path id="path.class">
    <pathelement location="build"/>
    <fileset dir="lib">
       <include name="*.jar"/>
    </fileset>
  </path>

  <!--Run-->
  <target name="run" depends="compile"
   description="Runs the complied project">
    <java fork="true" classname="sample.calendar.OutlookToGmailCalendarSync">
      <classpath>
        <path refid="path.class"/>
      </classpath>
    </java>
  </target>

  <!--Compile-->
  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <!--Init-->
  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <mkdir dir="${build}"/>
  </target>

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

</project>

运行ant时出现错误:

compile:
    [javac] C:\java\my\build.xml:31: warning: 'includeantruntime' was not set, d
efaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 28 source files to C:\java\my\build
    [javac] C:\java\my\src\sample\calendar\OutlookToGmailCalendarSync.java:2: er
ror: package org.jasypt.util.password does not exist
    [javac] import org.jasypt.util.password.*;
    [javac] ^
    [javac] 1 error

org.jasypt.util.password位于lib文件夹中的jar文件中,为什么我会收到此错误?

1 个答案:

答案 0 :(得分:3)

设置compile command的类路径以包含jasypt.jar