korshyadoo
korshyadoo

Reputation: 337

Import jar file in ant build file

I'm trying to compile a project that imports a class from a jar but it's not working. Here's my main class:

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

Here's my 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>

And here is the error when I run 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 is located in a jar file in the lib folder, so why am I getting this error?

Upvotes: 2

Views: 3280

Answers (1)

user2088476
user2088476

Reputation: 613

set the classpath of the compile command to include the jasypt.jar

Upvotes: 3

Related Questions