ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominique Devienne" <ddevie...@gmail.com>
Subject Re: classpath problem using the java task
Date Wed, 05 Jul 2006 01:10:06 GMT
>From http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html#options

-jar
Execute a program encapsulated in a JAR file. The first argument is
the name of a JAR file instead of a startup class name. In order for
this option to work, the manifest of the JAR file must contain a line
of the form Main-Class: classname. Here, classname identifies the
class having the public static void main(String[] args) method that
serves as your application's starting point. See the Jar tool
reference page and the Jar trail of the Java Tutorial for information
about working with Jar files and Jar-file manifests.
When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored

The last sentence is what really matters, i.e. the <classpath> is
ignored when you use the 'jar' attribute, because that's the way SUN's
java executable works. --DD

On 7/4/06, Douglas Dunn <dkdunn@cox.net> wrote:
> Like many programmers, I pride myself in no wasting other programmer's time by always
making a best effort to find my own answers. BUT, I have just spend almost the entire Forth
of July trying to find out why this VERY BASIC ant project fails. The problem is that ant
cannot find the j2ee.jar extension delivered in the Java EE 5 (i.e. not part of the core API).
I've tried absolutely everything after hours and hours of exhaustive Internet research. Many,
many times it appeared I found the answer, but it would not work.
>
> So, here I am. Your help would be greatly appreciated.
>
> HERE IS THE ANT CODE. NOTHING FOLLOWS; PLEASE EMAIL ME IF YOU WOULD LIKE TO HELP AND
HAVE SOME IDEA. I CANNOT LIST EVERYTHING I HAVE TRIED, BUT BELIEVE ME I HAVE TRIED EVERYTHING
I COULD FIND WHILE RESEARCHING THE PROBLEM ON THE INTERNET. I EVEN WOULD BE GREATFUL FOR SOME
IDEA HOW TO PRINT THE CLASSPATH THE java TASK IS USING. I FOUND MANY WAYS TO DO THIS, BUT
NONE, NONE OF THEM WORKED FOR ME. THIS HAS BEEN A REALLY UGLY DAY, AND ON TOP OF IT I READ
SOME REALLY DISTURBING REPLIES FROM THE DEVELOPER'S AT ANT, REPLIES TO OTHER PEOPLE HAVING
SIMILAR PROBLEMS. MANY THANKS IN ADVANCE.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="TestHttpServlet"  basedir="." default="run">
>
>    <!-- property names for directories -->
>    <property name="src.dir"     value="src"/>
>    <property name="build.dir"   value="build"/>
>    <property name="classes.dir" value="${build.dir}/classes"/>
>    <property name="jar.dir"     value="${build.dir}/jar"/>
>
>    <!-- property name for the Main-Class in a JAR manifest -->
>    <property name="main-class"  value="TestHttpServlet"/>
>
>    <!-- AS Home -->
>    <property name="appserver-home"  value="c:SunAppServer"/>
>
>
>
>    <!-- CLEAN -->
>    <target name="clean" description="Delete all generated files">
>         <delete dir="${build.dir}" failonerror="false" />
>    </target>
>
>
>    <!-- COMPILE -->
>    <target name="compile" depends="clean"
>     description="Compiles all .java files in the src directory"
>    >
>        <mkdir dir="${classes.dir}"/>
>        <javac srcdir="${src.dir}" destdir="${classes.dir}" compiler="javac1.5"/>
>    </target>
>
>
>    <!-- COPY RESOURCES -->
>    <target name="copy" depends="compile"
>     description="Copies resource files in the src directory to the classes directory
in preparation for archiving"
>    >
>        <copy todir="${classes.dir}">
>        <fileset dir="${src.dir}" excludes="**/*.java"/>
>        </copy>
>    </target>
>
>
>    <!-- ARCHIVE -->
>    <target name="jar" depends="copy"
>            description="archive the .class files and other resources found in the src
directory, and create the manifest file"
>    >
>            <mkdir dir="${jar.dir}"/>
>            <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="build/classes">
>            <manifest>
>                <attribute name="Main-Class" value="${main-class}"/>
>            </manifest>
>        </jar>
>    </target>
>
>
>    <!-- TEST -->
>    <!-- NOTE: fork="true" MUST BE used when executing a .jar file -->
>    <target name="run" depends="jar"
>       description="Executes main(String[] args) to test build"
>    >
>       <java jar="${jar.dir}/${ant.project.name}.jar" fork="true">
>          <classpath>
>             <pathelement location="${appserver.home}/lib/j2ee.jar"/>
>          </classpath>
>       </java>
>   </target>
>
> </project>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message