Compiling Java source with ant
I have a Java source package that is known to compile successfully. I am trying to compile a package with ant (build.xml file present). When I run ant, all Java import statements generate an error message like:
Import java.awt.geom.Path2D cannot be resolved "(specific message depends on what is being imported)
Obviously the package paths are undefined and I have no idea where the requested imports live on the filesystem. I guess if I know the paths in which the parameter $CLASSPATH
will get the program compiled. I am using opensuse 13.2 and my installed java info is:
java -version
openjdk version "1.8.0_45"
OpenJDK Runtime Environment (build 1.8.0_45-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
Can anyone point me to where to find java packages and how to get ant to compile sources?
Command line used to compile sources: ant
build.xml is in the same directory where ant is run, which also contains the src directory. This is a working project, I just don't know how to set up the default library locations (I'm not a Java type by any means).
Update.
I found the path to the openjdk libraries in / usr / lib 64 / jvm / java-1.8.0-openjdk-1.8.0 / jre / lib / rt.jar and tried to compile 2 different ways, but so far the import cannot be resolved for error messages.
Compiling with the -lib parameter doesn't work:
ant -lib / usr / lib64 / jvm / java-1.8.0-openjdk-1.8.0 / jre / lib / rt.jar
Setting the CLASSPATH environment variable doesn't work:
export CLASSPATH = / usr / lib64 / jvm / java-1.8.0-openjdk-1.8.0 / jre / lib / rt.jar
ant
Build.xml content:
<?xml version="1.0"?>
<project name="MazR" default="jar" basedir=".">
<property name="jar.file" value="${ant.project.name}.jar"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="dist.dir" value="dist"/>
<property name="applet.html" value="applet.html"/>
<taskdef resource="checkstyletask.properties"/>
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${dist.dir}"/>
</target>
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"
includeantruntime="false">
<compilerarg value="-Xlint"/>
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="${dist.dir}/${jar.file}" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="com.nullprogram.maze.RunMaze"/>
</manifest>
</jar>
<copy file="${applet.html}" tofile="${dist.dir}/index.html"/>
</target>
<target name="run" depends="jar">
<java jar="${dist.dir}/${jar.file}" fork="true"/>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
<delete file="${jar.file}"/>
</target>
<target name="check">
<checkstyle config="checkstyle.xml">
<fileset dir="src" includes="**/*.java"/>
</checkstyle>
</target>
<target name="format" description="Run the indenter on all source files.">
<apply executable="astyle">
<arg value="--mode=java"/>
<arg value="--suffix=none"/>
<fileset dir="${src.dir}" includes="**/*.java"/>
</apply>
</target>
<target name="applet" depends="jar" description="Run the applet version.">
<exec executable="appletviewer">
<arg value="${dist.dir}/index.html"/>
</exec>
</target>
<target name="javadoc" description="Generate Javadoc HTML.">
<javadoc destdir="${dist.dir}/javadoc">
<fileset dir="${src.dir}" includes="**/*.java" />
</javadoc>
</target>
</project>
Any idea why the import isn't working?
Thank!
Further update.
I added classpath definition to build.xml as shown below, but still no joy. I haven't used Java for many, many years, so I went out of my depth helping to desperately appreciate.
<property name="java.class.path" location="/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/lib/rt.jar"/>
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"
includeantruntime="false">
<compilerarg value="-Xlint"/>
<classpath>
<pathelement path="${java.class.path}/"/>
</classpath>
</javac>
</target>
source to share