musicmatze
musicmatze

Reputation: 4288

ant - how to include .java files in classpath

Please notice first: I don't need to include .jar files!

I want to include .java files from another java project with ant. But I don't know how and google has also no idea. My build.xml looks like this:

<project>

    <!-- Main properties -->
    <property name="projectname"    value="rasco" />
    <property name="mainclass"      value="de.beyermatthias.rasco.Rasco" />
    <property name="lib.dir"        value="./lib/java-speech-api/src/" />

    <path id="classpath">
            <pathelement path="${lib.dir}"/>
    </path>

    <!-- Tasks -->
    <!-- Clean Task -->
    <target name="clean">
            <delete dir="build" />
    </target>

    <!-- Compile Task -->
    <target name="compile" depends="clean" >
            <mkdir dir="build/classes" />
            <javac srcdir="src" destdir="build/classes/">
            </javac>
    </target>

    <!-- Jar Task -->
    <target name="jar" depends="compile" >
            <mkdir dir="build/jar" />
            <jar destfile="build/jar/${projectname}.jar" basedir="build/classes/">
                    <manifest>
                            <attribute name="Main-Class" value="${mainclass}" />
                    </manifest>
            </jar>
    </target>

    <!-- Run Task -->
    <target name="run">
            <java jar="build/jar/${projectname}.jar" fork="true" />
    </target>
</project>

My project hierarchy like this:

 .
 ├── build
 │   └── classes
 ├── build.xml
 ├── lib
 │   └── java-speech-api
 │       ├── CHANGELOG.markdown
 │       ├── CREDITS.markdown
 │       ├── java-speech-api.iml
 │       ├── README.markdown
 │       └── src
 │           ├── com
 │           │   └── darkprograms
 │           │       └── speech
 │           │           ├── microphone
 │           │           │   └── Microphone.java
 │           │           ├── recognizer
 │           │           │   ├── FlacEncoder.java
 │           │           │   ├── GoogleResponse.java
 │           │           │   └── Recognizer.java
 │           │           └── synthesiser
 │           │               └── Synthesiser.java
 │           └── META-INF
 │               └── MANIFEST.MF
 └── src
     └── de
         └── beyermatthias
             └── rasco
                 └── Rasco.java

Most tutorials talk about including .jar files in the classpath, but I need to include the .java files, as you can see. I hope you can help me.

Upvotes: 3

Views: 3999

Answers (2)

blachab
blachab

Reputation: 11

You can use multiple src elements in javac. This would look like:

<javac destdir="some_dir" classpath="some_classpath" ... >
   <src path="some_source" />
   <src path="some_other_source"/>
 </javac> 

Upvotes: 0

Dan D.
Dan D.

Reputation: 32391

You can include folders of compiled .class files, but not .java source files.

Upvotes: 3

Related Questions