You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dennis Putnam <da...@bellsouth.net> on 2019/02/13 18:26:09 UTC

Javac Run By Ant Script is Unable to Find External Jars

I had a working ant script until I made a number of source changes to my
Java project via Eclipse and egit. I obviously somehow inadvertently
changed something, somewhere, that is causing javac to not find
libraries (perhaps pushed something via git that is not part of the
source). There are some Maven libraries and external jars in the build
path (as displayed by Eclipse) but it seems they are not being found
with the ant script. This is the ant output:

    Buildfile: /usr/build/makejar.xml

    checkOS:

    if_linux:

    if_windows:

    setclass:

    incserial:
         [echo] update build requested
    [propertyfile] Updating property file:
    /usr/build/bin/KCBSEvents/resource/build.properties
         [echo] serial number: 1001

    jar:
         [echo] Using destination file /tmp/60286/KCBSEvents.jar
        [javac] Compiling 7 source files to /usr/build/bin
        [javac] /usr/build/src/KCBSEvents/DoSearch.java:11: error:
    package org.json.simple does not exist
        [javac] import org.json.simple.JSONObject;
        [javac]                       ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:48: error:
    package org.apache.commons.io does not exist
        [javac] import org.apache.commons.io.IOUtils;
        [javac]                             ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:49: error:
    package org.apache.http does not exist
        [javac] import org.apache.http.Consts;
        [javac]                       ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:50: error:
    package org.apache.http does not exist
        [javac] import org.apache.http.HttpResponse;
        [javac]                       ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:51: error:
    package org.apache.http.client does not exist
        [javac] import org.apache.http.client.HttpClient;
        [javac]                              ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:52: error:
    package org.apache.http.client.methods does not exist
        [javac] import org.apache.http.client.methods.HttpPost;
        [javac]                                      ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:53: error:
    package org.apache.http.entity does not exist
        [javac] import org.apache.http.entity.ContentType;
        [javac]                              ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:54: error:
    package org.apache.http.entity does not exist
        [javac] import org.apache.http.entity.StringEntity;
        [javac]                              ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:55: error:
    package org.apache.http.impl.client does not exist
        [javac] import org.apache.http.impl.client.HttpClients;
        [javac]                                   ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:56: error:
    package org.json.simple does not exist
        [javac] import org.json.simple.JSONObject;
        [javac]                       ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:57: error:
    package org.json.simple does not exist
        [javac] import org.json.simple.JSONArray;
        [javac]                       ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:58: error:
    package org.json.simple.parser does not exist
        [javac] import org.json.simple.parser.JSONParser;
        [javac]                              ^
        [javac] /usr/build/src/KCBSEvents/Helpers.java:362: error:
    cannot find symbol
        [javac]     public static ArrayList<JSONObject> getPage(String
    url) {
        [javac]                             ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:401: error:
    cannot find symbol
        [javac]     public static Comparator<JSONObject> sortJSON=new
    Comparator<JSONObject>() {
        [javac]                              ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/DoSearch.java:33: error:
    cannot find symbol
        [javac]                     ArrayList<JSONObject>
    json=Helpers.getPage(getURL);
        [javac]                               ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class DoSearch
        [javac] /usr/build/src/KCBSEvents/DoSearch.java:40: error:
    cannot find symbol
        [javac]                                     JSONObject
    evnt=json.get(i);
        [javac]                                     ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class DoSearch
        [javac] /usr/build/src/KCBSEvents/Helpers.java:320: error:
    cannot find symbol
        [javac]             HttpPost post=new
    HttpPost("http://www.mapquestapi.com/directions/v2/routematrix?inFormat=xml&outFormat=xml&key="+Registration.getInstance().getMapQuestKey());
        [javac]             ^
        [javac]   symbol:   class HttpPost
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:320: error:
    cannot find symbol
        [javac]             HttpPost post=new
    HttpPost("http://www.mapquestapi.com/directions/v2/routematrix?inFormat=xml&outFormat=xml&key="+Registration.getInstance().getMapQuestKey());
        [javac]                               ^
        [javac]   symbol:   class HttpPost
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:321: error:
    cannot find symbol
        [javac]             StringEntity entity = new
    StringEntity(xmlString, ContentType.create("text/xml", Consts.UTF_8));
        [javac]             ^
        [javac]   symbol:   class StringEntity
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:321: error:
    cannot find symbol
        [javac]             StringEntity entity = new
    StringEntity(xmlString, ContentType.create("text/xml", Consts.UTF_8));
        [javac]                                       ^
        [javac]   symbol:   class StringEntity
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:321: error:
    cannot find symbol
        [javac]             StringEntity entity = new
    StringEntity(xmlString, ContentType.create("text/xml", Consts.UTF_8));
       
    [javac]                                                                                             
    ^
        [javac]   symbol:   variable Consts
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:321: error:
    cannot find symbol
        [javac]             StringEntity entity = new
    StringEntity(xmlString, ContentType.create("text/xml", Consts.UTF_8));
       
    [javac]                                                               ^
        [javac]   symbol:   variable ContentType
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:324: error:
    cannot find symbol
        [javac]             HttpClient client = HttpClients.createDefault();
        [javac]             ^
        [javac]   symbol:   class HttpClient
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:324: error:
    cannot find symbol
        [javac]             HttpClient client = HttpClients.createDefault();
        [javac]                                 ^
        [javac]   symbol:   variable HttpClients
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:327: error:
    cannot find symbol
        [javac]                     HttpResponse response =
    client.execute(post);
        [javac]                     ^
        [javac]   symbol:   class HttpResponse
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:330: error:
    cannot find symbol
        [javac]                             body =
    IOUtils.toString(in,"UTF-8");
        [javac]                                    ^
        [javac]   symbol:   variable IOUtils
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:344: error:
    cannot find symbol
        [javac]                             body =
    IOUtils.toString(in,"UTF-8");
        [javac]                                    ^
        [javac]   symbol:   variable IOUtils
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:369: error:
    cannot find symbol
        [javac]                     ArrayList<JSONObject> array=new
    ArrayList<JSONObject>();
        [javac]                               ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:369: error:
    cannot find symbol
        [javac]                     ArrayList<JSONObject> array=new
    ArrayList<JSONObject>();
       
    [javac]                                                               ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:376: error:
    cannot find symbol
        [javac]                     JSONParser parser=new JSONParser();
        [javac]                     ^
        [javac]   symbol:   class JSONParser
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:376: error:
    cannot find symbol
        [javac]                     JSONParser parser=new JSONParser();
        [javac]                                           ^
        [javac]   symbol:   class JSONParser
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:378: error:
    cannot find symbol
        [javac]                             JSONObject json=(JSONObject)
    parser.parse(sb.toString());
        [javac]                             ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:378: error:
    cannot find symbol
        [javac]                             JSONObject json=(JSONObject)
    parser.parse(sb.toString());
        [javac]                                              ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:381: error:
    cannot find symbol
        [javac]                                    
    array.add((JSONObject) pair.getValue());
        [javac]                                                ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:385: error:
    cannot find symbol
        [javac]                             JSONArray json=(JSONArray)
    parser.parse(sb.toString());
        [javac]                             ^
        [javac]   symbol:   class JSONArray
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:385: error:
    cannot find symbol
        [javac]                             JSONArray json=(JSONArray)
    parser.parse(sb.toString());
        [javac]                                             ^
        [javac]   symbol:   class JSONArray
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:387: error:
    cannot find symbol
        [javac]                                    
    array.add((JSONObject) json.get(i));
        [javac]                                                ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:401: error:
    cannot find symbol
        [javac]     public static Comparator<JSONObject> sortJSON=new
    Comparator<JSONObject>() {
       
    [javac]                                                                 
    ^
        [javac]   symbol:   class JSONObject
        [javac]   location: class Helpers
        [javac] /usr/build/src/KCBSEvents/Helpers.java:404: error:
    cannot find symbol
        [javac]             public int compare(JSONObject arg0,
    JSONObject arg1) {
        [javac]                                ^
        [javac]   symbol: class JSONObject
        [javac] /usr/build/src/KCBSEvents/Helpers.java:404: error:
    cannot find symbol
        [javac]             public int compare(JSONObject arg0,
    JSONObject arg1) {
        [javac]                                                 ^
        [javac]   symbol: class JSONObject
        [javac] 40 errors

    BUILD FAILED
    /usr/build/makejar.xml:56: Compile failed; see the compiler error
    output for details.


Here is my ant script (makejar.xml):

    <?xml version="2.0" encoding="UTF-8"?>
    <project name="KCBSEvents" default="jar" basedir=".">
            <property name="build.properties" value="build.properties"/>
            <property name="resources" value="resource" />
            <property name="jardir" value="KCBSEvents" />
            <property name="KCBSDir" value="src/KCBSEvents" />
            <property name="member.number" value="000000" />
            <property name="member.name" value="" />
            <target name="checkOS">
                    <condition property="isWindows">
                            <os family="windows" />
                    </condition>
                    <condition property="isLinux">
                            <os family="unix" />
                    </condition>
            </target>
            <target name="if_windows" depends="checkOS" if="isWindows">
                    <property name="jarfile"
    value="C:\temp\KCBSEvents.jar" />
                    <property name="antcontrib"
    value="H:\html\Applets\ant-contrib" />
            </target>
            <target name="if_linux" depends="checkOS" if="isLinux">
                    <property name="jarfile"
    value="/tmp/${member.number}/KCBSEvents.jar" />
                    <property name="antcontrib"
    value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
            </target>
            <target name="setclass" depends="if_linux,if_windows">
                    <taskdef
    resource="net/sf/antcontrib/antcontrib.properties">
                            <classpath>
                                    <pathelement location="${antcontrib}" />
                            </classpath>
                    </taskdef>
            </target>
            <target name="incserial" depends="setclass">
                    <copy todir="bin/${jardir}/${resources}">
                            <fileset dir="${KCBSDir}/${resources}">
                                    <include name="${build.properties}" />
                            </fileset>
                            <filterchain>
                                    <expandproperties />
                            </filterchain>
                    </copy>
                    <if> <isset Property="build.number" /> <then>
                            <echo message="update build requested" />
                    </then> <else>
                            <echo message="new build requested" />
                            <buildnumber />
                    </else> </if>
                    <propertyfile
    file="bin/${jardir}/${resources}/${build.properties}">
                           <entry key="serialnumber"
    value="${build.number}" />
                            <entry key="membernumber"
    value="${member.number}" />
                            <entry key="name" value="${member.name}" />
                    </propertyfile>
                    <echo message="serial number: ${build.number}" />
            </target>
            <target name="jar" description="Compile serialized jar"
    depends="incserial,if_windows,if_linux">
                    <echo message="Using destination file ${jarfile}" />
                    <javac srcdir="src" destdir="bin"
    includeantruntime="false" />
                    <jar destfile="${jarfile}" basedir="bin"
    filesetmanifest="mergewithoutmain">
                            <manifest>
                                    <attribute name="Manifest-Version"
    value="1.0"/>
                                    <attribute name="Created-By"
    value="ant 1.9.2 on CentOS 7" />
                                    <attribute name="Main-Class"
    value="KCBSEvents.KCBSEvents" />
                            </manifest>
                            <fileset dir="${user.home}/.m2/repository" />
                            <zipfileset excludes="META-INF/*.SF"
    src="${user.home}/.m2/repository/commons-io/2.5/commons-io-2.5.jar"/>
                            <zipfileset excludes="META-INF/*.SF"
    src="${user.home}/.m2/repository/httpcomponents-client/httpclient-4.5.6.jar"/>
                            <zipfileset excludes="META-INF/*.SF"
    src="${user.home}/.m2/repository/httpcomponents-client/httpcore-4.4.10.jar"/>
                            <zipfileset excludes="META-INF/*.SF"
    src="${user.home}/.m2/repository/commons-logging/1.2/commons-logging-1.2.jar"/>
                            <zipfileset excludes="META-INF/*.SF"
    src="${user.home}/.m2/repository/commons-codec/1.10/commons-codec-1.10.jar"/>
                    </jar>
            </target>
    </project>

The zipfileset tags are seemingly being ignored and I don't know how it
knows to include the external jar (org.json.simple). Since this was
working I am guessing that something changed external to the ant script
but I don't know what or where to look. I don't know how the build path
that I see in Eclipse (which is correct and works) fits into all this.
I'm hoping someone can point me in the right direction. TIA.


Re: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Jan,

That was it. Thanks.

I had that at one time but I thought those were no longer necessary
since I added all the pom and maven stuff. Now I'm not sure what is
necessary but since it is working I'll leave it alone.

On 2/28/2019 10:10 AM, Jan Matèrne (jhm) wrote:
> I think Eclipse is creating a shaded jar, means a jar which contains all external jars.
>
> So you would have to download these jars and include their content in your final archive.
>
> You could use <zipfileset> for getting their content
>
>    <jar destfile="myjar.jar">
>
>       <fileset dir="classes"/>
>
>       <zipfileset src="lib/dependency1.jar"/>
>
>  
>
> Jan
>
>  
>
> Von: Dennis Putnam [mailto:dap1@bellsouth.net] 
> Gesendet: Donnerstag, 28. Februar 2019 10:53
> An: user@ant.apache.org
> Betreff: AW: Javac Run By Ant Script is Unable to Find External Jars
>
>  
>
> I've figured out what the problem is but I don't know what to do to fix it. When I export the jar from Eclipse, it has this set of directories:
>
> KCBSEvents
> META-INF
> mozilla
> org
> src
>
> That is the one that works. When I build the jar using ant (below), these are the directories present:
>
> KCBSEvents
> META-INF
>
> It is obvious now what the problem is. I just need to know how to get ant to include those same directories.
>
> On 2/21/2019 10:18 AM, Dennis Putnam wrote:
>
> I found an article on adding Maven dependencies to my ant script. While I'm getting a successful build but the same exception when I run the jar, I hope this is getting me closer. At least the pom.xml is in the build. I am wondering if the added fileset is right and working. Here is my latest:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="KCBSEvents" default="jar" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
>         <property name="build.properties" value="build.properties"/>
>         <property name="resources" value="resource" />
>         <property name="jardir" value="KCBSEvents" />
>         <property name="KCBSDir" value="src/KCBSEvents" />
>         <property name="member.number" value="000000" />
>         <property name="member.name" value="" />
>         <property name="jarpath" value="/${user.home}/.m2/repository" />
>         <path id="maven-ant-tasks.classpath" path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar" />
>         <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />
>         <artifact:pom id="pomfile" file="pom.xml" />
>         <artifact:dependencies filesetId="mvn-dependencies" pomRefId="pomfile" />
>         <path id="compile-jars">
>                 <multirootfileset basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
>                         <include name="commons-io-2.5.jar" />
>                         <include name="httpclient-4.5.6.jar" />
>                         <include name="httpcore-4.4.10.jar" />
>                         <include name="commons-logging-1.2.jar" />
>                         <include name="commons-codec-1.10.jar" />
>                         <include name="json-simple-1.1.1.jar" />
>                 </multirootfileset>
>                 <fileset refid="mvn-dependencies" />
>         </path>
>         <target name="checkOS">
>                 <condition property="isWindows">
>                         <os family="windows" />
>                 </condition>
>                 <condition property="isLinux">
>                         <os family="unix" />
>                 </condition>
>         </target>
>         <target name="if_windows" depends="checkOS" if="isWindows">
>                 <property name="jarfile" value="C:\temp\KCBSEvents.jar" />
>                 <property name="antcontrib" value="H:\html\Applets\ant-contrib" />
>         </target>
>         <target name="if_linux" depends="checkOS" if="isLinux">
>                 <property name="jarfile" value="/tmp/${member.number}/KCBSEvents.jar" />
>                 <property name="antcontrib" value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>         </target>
>         <target name="setclass" depends="if_linux,if_windows">
>                 <taskdef resource="net/sf/antcontrib/antcontrib.properties">
>                         <classpath>
>                                 <pathelement location="${antcontrib}" />
>                         </classpath>
>                 </taskdef>
>  </target>
>         <target name="incserial" depends="setclass">
>                 <copy todir="bin/${jardir}/${resources}">
>                         <fileset dir="${KCBSDir}/${resources}">
>                                 <include name="${build.properties}" />
>                         </fileset>
>                         <filterchain>
>                                 <expandproperties />
>                         </filterchain>
>                 </copy>
>                 <if> <isset Property="build.number" /> <then>
>                         <echo message="update build requested" />
>                 </then> <else>
>                         <echo message="new build requested" />
>                         <buildnumber />
>                 </else> </if>
>                 <propertyfile file="bin/${jardir}/${resources}/${build.properties}">
>                         <entry key="serialnumber" value="${build.number}" />
>                         <entry key="membernumber" value="${member.number}" />
>                         <entry key="name" value="${member.name}" />
>                 </propertyfile>
>                 <echo message="serial number: ${build.number}" />
>         </target>
>         <target name="jar" description="Compile serialized jar" depends="incserial,if_windows,if_linux">
>                 <echo message="Using destination file ${jarfile}" />
>                 <javac srcdir="src" destdir="bin" includeantruntime="false" classpathref="compile-jars" />
>                 <jar destfile="${jarfile}" basedir="bin" filesetmanifest="mergewithoutmain">
>                         <manifest>
>                                 <attribute name="Manifest-Version" value="1.0"/>
>                                 <attribute name="Created-By" value="ant 1.9.2 on CentOS 7" />
>                                 <attribute name="Main-Class" value="KCBSEvents.KCBSEvents" />
>                         </manifest>
>                 </jar>
>         </target>
> </project>
>
>
> On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote: 
>
> If you have created your JAR the first step is done.
>  
> Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
>  
>  
>  
> 1. Hard coded start script.
>  
> Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
>  
> @echo off
>  
> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
>  
>  
>  
> 2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
>  
>  
>  
> 3. Use Ant + <java><classpath> for starting
>  
>  
>  
> 4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
>  
>  
>  
> 5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
>  
>  
>  
> 6. Use a launcher which uses a dependency manager for getting the classpath
>  
>  
>  
>  
>  
>  
>  
> You don't have to replicate path definitions in your buildfile, you could (and should) use references:
>  
> <javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
>  
> <java><classpath refid="runtime.cp"/>
>  
>  
>  
>  
>  
> You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
>  
>  
>  
>  
>  
> Jan
>  
>  
>  
>
>  
>
>  
>
>



AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
I think Eclipse is creating a shaded jar, means a jar which contains all external jars.

So you would have to download these jars and include their content in your final archive.

You could use <zipfileset> for getting their content

   <jar destfile="myjar.jar">

      <fileset dir="classes"/>

      <zipfileset src="lib/dependency1.jar"/>

 

Jan

 

Von: Dennis Putnam [mailto:dap1@bellsouth.net] 
Gesendet: Donnerstag, 28. Februar 2019 10:53
An: user@ant.apache.org
Betreff: AW: Javac Run By Ant Script is Unable to Find External Jars

 

I've figured out what the problem is but I don't know what to do to fix it. When I export the jar from Eclipse, it has this set of directories:

KCBSEvents
META-INF
mozilla
org
src

That is the one that works. When I build the jar using ant (below), these are the directories present:

KCBSEvents
META-INF

It is obvious now what the problem is. I just need to know how to get ant to include those same directories.

On 2/21/2019 10:18 AM, Dennis Putnam wrote:

I found an article on adding Maven dependencies to my ant script. While I'm getting a successful build but the same exception when I run the jar, I hope this is getting me closer. At least the pom.xml is in the build. I am wondering if the added fileset is right and working. Here is my latest:

<?xml version="1.0" encoding="UTF-8"?>
<project name="KCBSEvents" default="jar" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
        <property name="build.properties" value="build.properties"/>
        <property name="resources" value="resource" />
        <property name="jardir" value="KCBSEvents" />
        <property name="KCBSDir" value="src/KCBSEvents" />
        <property name="member.number" value="000000" />
        <property name="member.name" value="" />
        <property name="jarpath" value="/${user.home}/.m2/repository" />
        <path id="maven-ant-tasks.classpath" path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar" />
        <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />
        <artifact:pom id="pomfile" file="pom.xml" />
        <artifact:dependencies filesetId="mvn-dependencies" pomRefId="pomfile" />
        <path id="compile-jars">
                <multirootfileset basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
                        <include name="commons-io-2.5.jar" />
                        <include name="httpclient-4.5.6.jar" />
                        <include name="httpcore-4.4.10.jar" />
                        <include name="commons-logging-1.2.jar" />
                        <include name="commons-codec-1.10.jar" />
                        <include name="json-simple-1.1.1.jar" />
                </multirootfileset>
                <fileset refid="mvn-dependencies" />
        </path>
        <target name="checkOS">
                <condition property="isWindows">
                        <os family="windows" />
                </condition>
                <condition property="isLinux">
                        <os family="unix" />
                </condition>
        </target>
        <target name="if_windows" depends="checkOS" if="isWindows">
                <property name="jarfile" value="C:\temp\KCBSEvents.jar" />
                <property name="antcontrib" value="H:\html\Applets\ant-contrib" />
        </target>
        <target name="if_linux" depends="checkOS" if="isLinux">
                <property name="jarfile" value="/tmp/${member.number}/KCBSEvents.jar" />
                <property name="antcontrib" value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
        </target>
        <target name="setclass" depends="if_linux,if_windows">
                <taskdef resource="net/sf/antcontrib/antcontrib.properties">
                        <classpath>
                                <pathelement location="${antcontrib}" />
                        </classpath>
                </taskdef>
 </target>
        <target name="incserial" depends="setclass">
                <copy todir="bin/${jardir}/${resources}">
                        <fileset dir="${KCBSDir}/${resources}">
                                <include name="${build.properties}" />
                        </fileset>
                        <filterchain>
                                <expandproperties />
                        </filterchain>
                </copy>
                <if> <isset Property="build.number" /> <then>
                        <echo message="update build requested" />
                </then> <else>
                        <echo message="new build requested" />
                        <buildnumber />
                </else> </if>
                <propertyfile file="bin/${jardir}/${resources}/${build.properties}">
                        <entry key="serialnumber" value="${build.number}" />
                        <entry key="membernumber" value="${member.number}" />
                        <entry key="name" value="${member.name}" />
                </propertyfile>
                <echo message="serial number: ${build.number}" />
        </target>
        <target name="jar" description="Compile serialized jar" depends="incserial,if_windows,if_linux">
                <echo message="Using destination file ${jarfile}" />
                <javac srcdir="src" destdir="bin" includeantruntime="false" classpathref="compile-jars" />
                <jar destfile="${jarfile}" basedir="bin" filesetmanifest="mergewithoutmain">
                        <manifest>
                                <attribute name="Manifest-Version" value="1.0"/>
                                <attribute name="Created-By" value="ant 1.9.2 on CentOS 7" />
                                <attribute name="Main-Class" value="KCBSEvents.KCBSEvents" />
                        </manifest>
                </jar>
        </target>
</project>


On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote: 

If you have created your JAR the first step is done.
 
Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
 
 
 
1. Hard coded start script.
 
Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
 
@echo off
 
java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
 
 
 
2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
 
 
 
3. Use Ant + <java><classpath> for starting
 
 
 
4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
 
 
 
5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
 
 
 
6. Use a launcher which uses a dependency manager for getting the classpath
 
 
 
 
 
 
 
You don't have to replicate path definitions in your buildfile, you could (and should) use references:
 
<javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
 
<java><classpath refid="runtime.cp"/>
 
 
 
 
 
You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
 
 
 
 
 
Jan
 
 
 

 

 


AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
I've figured out what the problem is but I don't know what to do to fix
it. When I export the jar from Eclipse, it has this set of directories:

KCBSEvents
META-INF
mozilla
org
src

That is the one that works. When I build the jar using ant (below),
these are the directories present:

KCBSEvents
META-INF

It is obvious now what the problem is. I just need to know how to get
ant to include those same directories.

On 2/21/2019 10:18 AM, Dennis Putnam wrote:
> I found an article on adding Maven dependencies to my ant script.
> While I'm getting a successful build but the same exception when I run
> the jar, I hope this is getting me closer. At least the pom.xml is in
> the build. I am wondering if the added *fileset* is right and working.
> Here is my latest:
>
>     <?xml version="1.0" encoding="UTF-8"?>
>     <project name="KCBSEvents" default="jar" basedir="."
>     *xmlns:artifact="antlib:org.apache.maven.artifact.ant"*>
>             <property name="build.properties" value="build.properties"/>
>             <property name="resources" value="resource" />
>             <property name="jardir" value="KCBSEvents" />
>             <property name="KCBSDir" value="src/KCBSEvents" />
>             <property name="member.number" value="000000" />
>             <property name="member.name" value="" />
>             <property name="jarpath"
>     value="/${user.home}/.m2/repository" />
>            *<path id="maven-ant-tasks.classpath"
>     path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar" />**
>     **        <typedef
>     resource="org/apache/maven/artifact/ant/antlib.xml"
>     uri="antlib:org.apache.maven.artifact.ant"
>     classpathref="maven-ant-tasks.classpath" />**
>     **        <artifact:pom id="pomfile" file="pom.xml" />**
>     **        <artifact:dependencies filesetId="mvn-dependencies"
>     pomRefId="pomfile" />*
>             <path id="compile-jars">
>                     <multirootfileset
>     basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
>                             <include name="commons-io-2.5.jar" />
>                             <include name="httpclient-4.5.6.jar" />
>                             <include name="httpcore-4.4.10.jar" />
>                             <include name="commons-logging-1.2.jar" />
>                             <include name="commons-codec-1.10.jar" />
>                             <include name="json-simple-1.1.1.jar" />
>                     </multirootfileset>
>                     *<fileset refid="mvn-dependencies" />*
>             </path>
>             <target name="checkOS">
>                     <condition property="isWindows">
>                             <os family="windows" />
>                     </condition>
>                     <condition property="isLinux">
>                             <os family="unix" />
>                     </condition>
>             </target>
>             <target name="if_windows" depends="checkOS" if="isWindows">
>                     <property name="jarfile"
>     value="C:\temp\KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="H:\html\Applets\ant-contrib" />
>             </target>
>             <target name="if_linux" depends="checkOS" if="isLinux">
>                     <property name="jarfile"
>     value="/tmp/${member.number}/KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>             </target>
>             <target name="setclass" depends="if_linux,if_windows">
>                     <taskdef
>     resource="net/sf/antcontrib/antcontrib.properties">
>                             <classpath>
>                                     <pathelement
>     location="${antcontrib}" />
>                             </classpath>
>                     </taskdef>
>      </target>
>             <target name="incserial" depends="setclass">
>                     <copy todir="bin/${jardir}/${resources}">
>                             <fileset dir="${KCBSDir}/${resources}">
>                                     <include name="${build.properties}" />
>                             </fileset>
>                             <filterchain>
>                                     <expandproperties />
>                             </filterchain>
>                     </copy>
>                     <if> <isset Property="build.number" /> <then>
>                             <echo message="update build requested" />
>                     </then> <else>
>                             <echo message="new build requested" />
>                             <buildnumber />
>                     </else> </if>
>                     <propertyfile
>     file="bin/${jardir}/${resources}/${build.properties}">
>                             <entry key="serialnumber"
>     value="${build.number}" />
>                             <entry key="membernumber"
>     value="${member.number}" />
>                             <entry key="name" value="${member.name}" />
>                     </propertyfile>
>                     <echo message="serial number: ${build.number}" />
>             </target>
>             <target name="jar" description="Compile serialized jar"
>     depends="incserial,if_windows,if_linux">
>                     <echo message="Using destination file ${jarfile}" />
>                     <javac srcdir="src" destdir="bin"
>     includeantruntime="false" classpathref="compile-jars" />
>                     <jar destfile="${jarfile}" basedir="bin"
>     filesetmanifest="mergewithoutmain">
>                             <manifest>
>                                     <attribute name="Manifest-Version"
>     value="1.0"/>
>                                     <attribute name="Created-By"
>     value="ant 1.9.2 on CentOS 7" />
>                                     <attribute name="Main-Class"
>     value="KCBSEvents.KCBSEvents" />
>                             </manifest>
>                     </jar>
>             </target>
>     </project>
>
>
> On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote:
>> If you have created your JAR the first step is done.
>>
>> Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
>>
>>  
>>
>> 1. Hard coded start script.
>>
>> Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
>>
>> @echo off
>>
>> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
>>
>>  
>>
>> 2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
>>
>>  
>>
>> 3. Use Ant + <java><classpath> for starting
>>
>>  
>>
>> 4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
>>
>>  
>>
>> 5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
>>
>>  
>>
>> 6. Use a launcher which uses a dependency manager for getting the classpath
>>
>>  
>>
>>  
>>
>>  
>>
>> You don't have to replicate path definitions in your buildfile, you could (and should) use references:
>>
>> <javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
>>
>> <java><classpath refid="runtime.cp"/>
>>
>>  
>>
>>  
>>
>> You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
>>
>>  
>>
>>  
>>
>> Jan
>>
>>  
>>
>


Re: AW: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Jan,

I need to take a timeout. In my machinations I've created a new problem
that seems unrelated to ant. I'm trying to resolve that via the Eclipse
forum. I don't know if this new problem is masking the original one or
if it is related. I'll have to get back to you when I know which.

On 2/25/2019 9:15 AM, Jan Matèrne (jhm) wrote:
> A little sample:
> * src\java\org\apache\ant\Application.java
>   Sample application which uses Log4J2 as external dependency
> * src\resources\log4j2.xml
>   Configuration file for Log4J2
> * build.xml
>   Ant buildscript
>
> Run the script with "ant".
> Then start the application with "java -jar lib\Application.jar".
> The app will prompt all given arguments via Log4J2-Logger.
>
> Have a look at the "build" target and the resulting manifest inside the jar.
>
>
> Jan
>
>
> Application.java
> ----8-<------8-<------8-<------8-<------8-<--
> package org.apache.ant;
>
> import java.util.stream.Stream;
> import org.apache.logging.log4j.LogManager;
> import org.apache.logging.log4j.Logger;
>
>
> public class Application {
>
>     public static void main(String[] args) {
>         Logger logger = LogManager.getLogger(Application.class);
>         if (args.length == 0) {
>             logger.info("Application started without any argument.");
>         } else {
>             logger.info("Application started with %d arguments:%n", args.length);
>             Stream.of(args)
>                   .map( s -> "- '"+s+"'" )
>                   .forEach(logger::info);
>         }
>     }
>
> }
> ----8-<------8-<------8-<------8-<------8-<--
>
>
> log4j2.xml
> ----8-<------8-<------8-<------8-<------8-<--
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
>     <Appenders>
>         <Console name="Console" target="SYSTEM_OUT">
>             <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
>         </Console>
>     </Appenders>
>     <Loggers>
>         <Root level="debug">
>             <AppenderRef ref="Console"/>
>         </Root>
>     </Loggers>
> </Configuration>
> ----8-<------8-<------8-<------8-<------8-<--
>
>
> build.xml
> ----8-<------8-<------8-<------8-<------8-<--
> <project name="Application" default="build">
>
>     <property name="build.dir" value="build"/>
>     <property name="src.dir" value="src"/>
>     <property name="lib.dir" value="lib"/>
>     <property name="main.class" value="org.apache.ant.Application"/>
>     
>     <property name="classes.dir" value="${build.dir}/classes"/>
>     <property name="java.src" value="${src.dir}/java"/>
>     <property name="resources.src" value="${src.dir}/resources"/>
>
>
>     <target name="clean">
>         <delete dir="${build.dir}"/>
>     </target>
>
>     <target name="download-dependencies">
>         <mkdir dir="${lib.dir}"/>
>         <!-- Performance improvement: don't download multiple times -->
>         <!-- TODO: available+get as macro -->
>         <available property="log4j-core.present" file="${lib.dir}/log4j-core-2.11.2.jar"/>
>         <get xmlns:unless="ant:unless"
>             unless:set="log4j-core.present"
>             src="https://search.maven.org/remotecontent?filepath=org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar"
>             dest="${lib.dir}/log4j-core-2.11.2.jar" />
>         <available property="log4j-api.present" file="${lib.dir}/log4j-api-2.11.2.jar"/>
>         <get xmlns:unless="ant:unless"
>             unless:set="log4j-api.present"
>             src="https://search.maven.org/remotecontent?filepath=org/apache/logging/log4j/log4j-api/2.11.2/log4j-api-2.11.2.jar"
>             dest="${lib.dir}/log4j-api-2.11.2.jar" />
>     </target>
>
>     <target name="compile" depends="download-dependencies">
>         <mkdir dir="${classes.dir}"/>
>         <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
>             <classpath id="cp.runtime">
>                 <fileset dir="${lib.dir}" includes="**/*.jar"/>
>             </classpath>
>         </javac>
>     </target>
>
>     <target name="build" depends="compile">
>         <manifestclasspath property="jar.classpath"
>                            jarfile="${build.dir}/${ant.project.name}.jar">
>             <classpath refid="cp.runtime"/>
>         </manifestclasspath>
>         <jar destfile="${build.dir}/${ant.project.name}.jar">
>             <fileset dir="${classes.dir}"/>
>             <fileset dir="${resources.src}"/>
>             <manifest>
>                 <attribute name="Main-Class" value="${main.class}"/>
>                 <attribute name="Class-Path" value="${jar.classpath}"/>
>             </manifest>
>         </jar>
>     </target>
>
> </project>
> ----8-<------8-<------8-<------8-<------8-<--
>
>
>> -----Ursprüngliche Nachricht-----
>> Von: Jan Matèrne (jhm) [mailto:apache@materne.de]
>> Gesendet: Montag, 25. Februar 2019 14:08
>> An: 'Ant Users List'
>> Betreff: AW: AW: Javac Run By Ant Script is Unable to Find External
>> Jars
>>
>> Could you post the content of the manifest file and your directory
>> structure?
>>
>> I suppose that the paths are not correct …
>>
>>
>>
>> Jan
>>
>>
>>
>> Von: Dennis Putnam [mailto:dap1@bellsouth.net]
>> Gesendet: Montag, 25. Februar 2019 13:09
>> An: user@ant.apache.org
>> Betreff: Re: AW: Javac Run By Ant Script is Unable to Find External
>> Jars
>>
>>
>>
>> My apologies again but I have not made any progress on this problem. Is
>> there perhaps a better forum I should be using at this point? I did
>> make one discovery. It appears that although the application works in
>> Eclipse when I try to export it to a runnable jar using the Eclipse
>> wizard, the resulting jar fails as well. It seems to me that the
>> problem is not ant specific but something in the app build per se.
>>
>> On 2/21/2019 10:18 AM, Dennis Putnam wrote:
>>
>> I found an article on adding Maven dependencies to my ant script. While
>> I'm getting a successful build but the same exception when I run the
>> jar, I hope this is getting me closer. At least the pom.xml is in the
>> build. I am wondering if the added fileset is right and working. Here
>> is my latest:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <project name="KCBSEvents" default="jar" basedir="."
>> xmlns:artifact="antlib:org.apache.maven.artifact.ant">
>>         <property name="build.properties" value="build.properties"/>
>>         <property name="resources" value="resource" />
>>         <property name="jardir" value="KCBSEvents" />
>>         <property name="KCBSDir" value="src/KCBSEvents" />
>>         <property name="member.number" value="000000" />
>>         <property name="member.name" value="" />
>>         <property name="jarpath" value="/${user.home}/.m2/repository"
>> />
>>         <path id="maven-ant-tasks.classpath" path="/lib/jvm-
>> exports/maven-ant-tasks-2.1.3.jar" />
>>         <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
>> uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-
>> tasks.classpath" />
>>         <artifact:pom id="pomfile" file="pom.xml" />
>>         <artifact:dependencies filesetId="mvn-dependencies"
>> pomRefId="pomfile" />
>>         <path id="compile-jars">
>>                 <multirootfileset basedirs="${jarpath}/commons-
>> io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-
>> logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-
>> 1.1.1">
>>                         <include name="commons-io-2.5.jar" />
>>                         <include name="httpclient-4.5.6.jar" />
>>                         <include name="httpcore-4.4.10.jar" />
>>                         <include name="commons-logging-1.2.jar" />
>>                         <include name="commons-codec-1.10.jar" />
>>                         <include name="json-simple-1.1.1.jar" />
>>                 </multirootfileset>
>>                 <fileset refid="mvn-dependencies" />
>>         </path>
>>         <target name="checkOS">
>>                 <condition property="isWindows">
>>                         <os family="windows" />
>>                 </condition>
>>                 <condition property="isLinux">
>>                         <os family="unix" />
>>                 </condition>
>>         </target>
>>         <target name="if_windows" depends="checkOS" if="isWindows">
>>                 <property name="jarfile" value="C:\temp\KCBSEvents.jar"
>> />
>>                 <property name="antcontrib" value="H:\html\Applets\ant-
>> contrib" />
>>         </target>
>>         <target name="if_linux" depends="checkOS" if="isLinux">
>>                 <property name="jarfile"
>> value="/tmp/${member.number}/KCBSEvents.jar" />
>>                 <property name="antcontrib"
>> value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>>         </target>
>>         <target name="setclass" depends="if_linux,if_windows">
>>                 <taskdef
>> resource="net/sf/antcontrib/antcontrib.properties">
>>                         <classpath>
>>                                 <pathelement location="${antcontrib}"
>> />
>>                         </classpath>
>>                 </taskdef>
>>  </target>
>>         <target name="incserial" depends="setclass">
>>                 <copy todir="bin/${jardir}/${resources}">
>>                         <fileset dir="${KCBSDir}/${resources}">
>>                                 <include name="${build.properties}" />
>>                         </fileset>
>>                         <filterchain>
>>                                 <expandproperties />
>>                         </filterchain>
>>                 </copy>
>>                 <if> <isset Property="build.number" /> <then>
>>                         <echo message="update build requested" />
>>                 </then> <else>
>>                         <echo message="new build requested" />
>>                         <buildnumber />
>>                 </else> </if>
>>                 <propertyfile
>> file="bin/${jardir}/${resources}/${build.properties}">
>>                         <entry key="serialnumber"
>> value="${build.number}" />
>>                         <entry key="membernumber"
>> value="${member.number}" />
>>                         <entry key="name" value="${member.name}" />
>>                 </propertyfile>
>>                 <echo message="serial number: ${build.number}" />
>>         </target>
>>         <target name="jar" description="Compile serialized jar"
>> depends="incserial,if_windows,if_linux">
>>                 <echo message="Using destination file ${jarfile}" />
>>                 <javac srcdir="src" destdir="bin"
>> includeantruntime="false" classpathref="compile-jars" />
>>                 <jar destfile="${jarfile}" basedir="bin"
>> filesetmanifest="mergewithoutmain">
>>                         <manifest>
>>                                 <attribute name="Manifest-Version"
>> value="1.0"/>
>>                                 <attribute name="Created-By" value="ant
>> 1.9.2 on CentOS 7" />
>>                                 <attribute name="Main-Class"
>> value="KCBSEvents.KCBSEvents" />
>>                         </manifest>
>>                 </jar>
>>         </target>
>> </project>
>>
>>
>> On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote:
>>
>> If you have created your JAR the first step is done.
>>
>> Starting the JAR could be done in several ways. Common is that you have
>> to have all external classes on the runtime classpath:
>>
>>
>>
>> 1. Hard coded start script.
>>
>> Write a bash/bat-Script with the java command with all cp settings,
>> e.g. (bat)
>>
>> @echo off
>>
>> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar
>> org.acme.Main %*
>>
>>
>>
>> 2. Wrapper script which collects all JARs in a dynamic way (see
>> ant.bat|ant.sh)
>>
>>
>>
>> 3. Use Ant + <java><classpath> for starting
>>
>>
>>
>> 4. Create a runnable JAR which references the external JARs (manifest:
>> main-class + classpath)
>>
>>
>>
>> 5. Create a shaded jar (uber jar, fat jar): include all classes from
>> external jars into your jar
>>
>>
>>
>> 6. Use a launcher which uses a dependency manager for getting the
>> classpath
>>
>>
>>
>>
>>
>>
>>
>> You don't have to replicate path definitions in your buildfile, you
>> could (and should) use references:
>>
>> <javac><classpath id="runtime.cp"><fileset dir="lib"
>> includes="**/*.jar"/>…
>>
>> <java><classpath refid="runtime.cp"/>
>>
>>
>>
>>
>>
>> You mave have a look at http://ant.apache.org/manual/tutorial-
>> HelloWorldWithAnt.html
>>
>>
>>
>>
>>
>> Jan
>>
>>
>>
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



AW: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
A little sample:
* src\java\org\apache\ant\Application.java
  Sample application which uses Log4J2 as external dependency
* src\resources\log4j2.xml
  Configuration file for Log4J2
* build.xml
  Ant buildscript

Run the script with "ant".
Then start the application with "java -jar lib\Application.jar".
The app will prompt all given arguments via Log4J2-Logger.

Have a look at the "build" target and the resulting manifest inside the jar.


Jan


Application.java
----8-<------8-<------8-<------8-<------8-<--
package org.apache.ant;

import java.util.stream.Stream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public class Application {

    public static void main(String[] args) {
        Logger logger = LogManager.getLogger(Application.class);
        if (args.length == 0) {
            logger.info("Application started without any argument.");
        } else {
            logger.info("Application started with %d arguments:%n", args.length);
            Stream.of(args)
                  .map( s -> "- '"+s+"'" )
                  .forEach(logger::info);
        }
    }

}
----8-<------8-<------8-<------8-<------8-<--


log4j2.xml
----8-<------8-<------8-<------8-<------8-<--
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>
----8-<------8-<------8-<------8-<------8-<--


build.xml
----8-<------8-<------8-<------8-<------8-<--
<project name="Application" default="build">

    <property name="build.dir" value="build"/>
    <property name="src.dir" value="src"/>
    <property name="lib.dir" value="lib"/>
    <property name="main.class" value="org.apache.ant.Application"/>
    
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="java.src" value="${src.dir}/java"/>
    <property name="resources.src" value="${src.dir}/resources"/>


    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="download-dependencies">
        <mkdir dir="${lib.dir}"/>
        <!-- Performance improvement: don't download multiple times -->
        <!-- TODO: available+get as macro -->
        <available property="log4j-core.present" file="${lib.dir}/log4j-core-2.11.2.jar"/>
        <get xmlns:unless="ant:unless"
            unless:set="log4j-core.present"
            src="https://search.maven.org/remotecontent?filepath=org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar"
            dest="${lib.dir}/log4j-core-2.11.2.jar" />
        <available property="log4j-api.present" file="${lib.dir}/log4j-api-2.11.2.jar"/>
        <get xmlns:unless="ant:unless"
            unless:set="log4j-api.present"
            src="https://search.maven.org/remotecontent?filepath=org/apache/logging/log4j/log4j-api/2.11.2/log4j-api-2.11.2.jar"
            dest="${lib.dir}/log4j-api-2.11.2.jar" />
    </target>

    <target name="compile" depends="download-dependencies">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
            <classpath id="cp.runtime">
                <fileset dir="${lib.dir}" includes="**/*.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="build" depends="compile">
        <manifestclasspath property="jar.classpath"
                           jarfile="${build.dir}/${ant.project.name}.jar">
            <classpath refid="cp.runtime"/>
        </manifestclasspath>
        <jar destfile="${build.dir}/${ant.project.name}.jar">
            <fileset dir="${classes.dir}"/>
            <fileset dir="${resources.src}"/>
            <manifest>
                <attribute name="Main-Class" value="${main.class}"/>
                <attribute name="Class-Path" value="${jar.classpath}"/>
            </manifest>
        </jar>
    </target>

</project>
----8-<------8-<------8-<------8-<------8-<--


> -----Ursprüngliche Nachricht-----
> Von: Jan Matèrne (jhm) [mailto:apache@materne.de]
> Gesendet: Montag, 25. Februar 2019 14:08
> An: 'Ant Users List'
> Betreff: AW: AW: Javac Run By Ant Script is Unable to Find External
> Jars
> 
> Could you post the content of the manifest file and your directory
> structure?
> 
> I suppose that the paths are not correct …
> 
> 
> 
> Jan
> 
> 
> 
> Von: Dennis Putnam [mailto:dap1@bellsouth.net]
> Gesendet: Montag, 25. Februar 2019 13:09
> An: user@ant.apache.org
> Betreff: Re: AW: Javac Run By Ant Script is Unable to Find External
> Jars
> 
> 
> 
> My apologies again but I have not made any progress on this problem. Is
> there perhaps a better forum I should be using at this point? I did
> make one discovery. It appears that although the application works in
> Eclipse when I try to export it to a runnable jar using the Eclipse
> wizard, the resulting jar fails as well. It seems to me that the
> problem is not ant specific but something in the app build per se.
> 
> On 2/21/2019 10:18 AM, Dennis Putnam wrote:
> 
> I found an article on adding Maven dependencies to my ant script. While
> I'm getting a successful build but the same exception when I run the
> jar, I hope this is getting me closer. At least the pom.xml is in the
> build. I am wondering if the added fileset is right and working. Here
> is my latest:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="KCBSEvents" default="jar" basedir="."
> xmlns:artifact="antlib:org.apache.maven.artifact.ant">
>         <property name="build.properties" value="build.properties"/>
>         <property name="resources" value="resource" />
>         <property name="jardir" value="KCBSEvents" />
>         <property name="KCBSDir" value="src/KCBSEvents" />
>         <property name="member.number" value="000000" />
>         <property name="member.name" value="" />
>         <property name="jarpath" value="/${user.home}/.m2/repository"
> />
>         <path id="maven-ant-tasks.classpath" path="/lib/jvm-
> exports/maven-ant-tasks-2.1.3.jar" />
>         <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
> uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-
> tasks.classpath" />
>         <artifact:pom id="pomfile" file="pom.xml" />
>         <artifact:dependencies filesetId="mvn-dependencies"
> pomRefId="pomfile" />
>         <path id="compile-jars">
>                 <multirootfileset basedirs="${jarpath}/commons-
> io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-
> logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-
> 1.1.1">
>                         <include name="commons-io-2.5.jar" />
>                         <include name="httpclient-4.5.6.jar" />
>                         <include name="httpcore-4.4.10.jar" />
>                         <include name="commons-logging-1.2.jar" />
>                         <include name="commons-codec-1.10.jar" />
>                         <include name="json-simple-1.1.1.jar" />
>                 </multirootfileset>
>                 <fileset refid="mvn-dependencies" />
>         </path>
>         <target name="checkOS">
>                 <condition property="isWindows">
>                         <os family="windows" />
>                 </condition>
>                 <condition property="isLinux">
>                         <os family="unix" />
>                 </condition>
>         </target>
>         <target name="if_windows" depends="checkOS" if="isWindows">
>                 <property name="jarfile" value="C:\temp\KCBSEvents.jar"
> />
>                 <property name="antcontrib" value="H:\html\Applets\ant-
> contrib" />
>         </target>
>         <target name="if_linux" depends="checkOS" if="isLinux">
>                 <property name="jarfile"
> value="/tmp/${member.number}/KCBSEvents.jar" />
>                 <property name="antcontrib"
> value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>         </target>
>         <target name="setclass" depends="if_linux,if_windows">
>                 <taskdef
> resource="net/sf/antcontrib/antcontrib.properties">
>                         <classpath>
>                                 <pathelement location="${antcontrib}"
> />
>                         </classpath>
>                 </taskdef>
>  </target>
>         <target name="incserial" depends="setclass">
>                 <copy todir="bin/${jardir}/${resources}">
>                         <fileset dir="${KCBSDir}/${resources}">
>                                 <include name="${build.properties}" />
>                         </fileset>
>                         <filterchain>
>                                 <expandproperties />
>                         </filterchain>
>                 </copy>
>                 <if> <isset Property="build.number" /> <then>
>                         <echo message="update build requested" />
>                 </then> <else>
>                         <echo message="new build requested" />
>                         <buildnumber />
>                 </else> </if>
>                 <propertyfile
> file="bin/${jardir}/${resources}/${build.properties}">
>                         <entry key="serialnumber"
> value="${build.number}" />
>                         <entry key="membernumber"
> value="${member.number}" />
>                         <entry key="name" value="${member.name}" />
>                 </propertyfile>
>                 <echo message="serial number: ${build.number}" />
>         </target>
>         <target name="jar" description="Compile serialized jar"
> depends="incserial,if_windows,if_linux">
>                 <echo message="Using destination file ${jarfile}" />
>                 <javac srcdir="src" destdir="bin"
> includeantruntime="false" classpathref="compile-jars" />
>                 <jar destfile="${jarfile}" basedir="bin"
> filesetmanifest="mergewithoutmain">
>                         <manifest>
>                                 <attribute name="Manifest-Version"
> value="1.0"/>
>                                 <attribute name="Created-By" value="ant
> 1.9.2 on CentOS 7" />
>                                 <attribute name="Main-Class"
> value="KCBSEvents.KCBSEvents" />
>                         </manifest>
>                 </jar>
>         </target>
> </project>
> 
> 
> On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote:
> 
> If you have created your JAR the first step is done.
> 
> Starting the JAR could be done in several ways. Common is that you have
> to have all external classes on the runtime classpath:
> 
> 
> 
> 1. Hard coded start script.
> 
> Write a bash/bat-Script with the java command with all cp settings,
> e.g. (bat)
> 
> @echo off
> 
> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar
> org.acme.Main %*
> 
> 
> 
> 2. Wrapper script which collects all JARs in a dynamic way (see
> ant.bat|ant.sh)
> 
> 
> 
> 3. Use Ant + <java><classpath> for starting
> 
> 
> 
> 4. Create a runnable JAR which references the external JARs (manifest:
> main-class + classpath)
> 
> 
> 
> 5. Create a shaded jar (uber jar, fat jar): include all classes from
> external jars into your jar
> 
> 
> 
> 6. Use a launcher which uses a dependency manager for getting the
> classpath
> 
> 
> 
> 
> 
> 
> 
> You don't have to replicate path definitions in your buildfile, you
> could (and should) use references:
> 
> <javac><classpath id="runtime.cp"><fileset dir="lib"
> includes="**/*.jar"/>…
> 
> <java><classpath refid="runtime.cp"/>
> 
> 
> 
> 
> 
> You mave have a look at http://ant.apache.org/manual/tutorial-
> HelloWorldWithAnt.html
> 
> 
> 
> 
> 
> Jan
> 
> 
> 
> 
> 
> 
> 



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


AW: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Could you post the content of the manifest file and your directory structure?

I suppose that the paths are not correct …

 

Jan

 

Von: Dennis Putnam [mailto:dap1@bellsouth.net] 
Gesendet: Montag, 25. Februar 2019 13:09
An: user@ant.apache.org
Betreff: Re: AW: Javac Run By Ant Script is Unable to Find External Jars

 

My apologies again but I have not made any progress on this problem. Is there perhaps a better forum I should be using at this point? I did make one discovery. It appears that although the application works in Eclipse when I try to export it to a runnable jar using the Eclipse wizard, the resulting jar fails as well. It seems to me that the problem is not ant specific but something in the app build per se.

On 2/21/2019 10:18 AM, Dennis Putnam wrote:

I found an article on adding Maven dependencies to my ant script. While I'm getting a successful build but the same exception when I run the jar, I hope this is getting me closer. At least the pom.xml is in the build. I am wondering if the added fileset is right and working. Here is my latest:

<?xml version="1.0" encoding="UTF-8"?>
<project name="KCBSEvents" default="jar" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
        <property name="build.properties" value="build.properties"/>
        <property name="resources" value="resource" />
        <property name="jardir" value="KCBSEvents" />
        <property name="KCBSDir" value="src/KCBSEvents" />
        <property name="member.number" value="000000" />
        <property name="member.name" value="" />
        <property name="jarpath" value="/${user.home}/.m2/repository" />
        <path id="maven-ant-tasks.classpath" path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar" />
        <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />
        <artifact:pom id="pomfile" file="pom.xml" />
        <artifact:dependencies filesetId="mvn-dependencies" pomRefId="pomfile" />
        <path id="compile-jars">
                <multirootfileset basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
                        <include name="commons-io-2.5.jar" />
                        <include name="httpclient-4.5.6.jar" />
                        <include name="httpcore-4.4.10.jar" />
                        <include name="commons-logging-1.2.jar" />
                        <include name="commons-codec-1.10.jar" />
                        <include name="json-simple-1.1.1.jar" />
                </multirootfileset>
                <fileset refid="mvn-dependencies" />
        </path>
        <target name="checkOS">
                <condition property="isWindows">
                        <os family="windows" />
                </condition>
                <condition property="isLinux">
                        <os family="unix" />
                </condition>
        </target>
        <target name="if_windows" depends="checkOS" if="isWindows">
                <property name="jarfile" value="C:\temp\KCBSEvents.jar" />
                <property name="antcontrib" value="H:\html\Applets\ant-contrib" />
        </target>
        <target name="if_linux" depends="checkOS" if="isLinux">
                <property name="jarfile" value="/tmp/${member.number}/KCBSEvents.jar" />
                <property name="antcontrib" value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
        </target>
        <target name="setclass" depends="if_linux,if_windows">
                <taskdef resource="net/sf/antcontrib/antcontrib.properties">
                        <classpath>
                                <pathelement location="${antcontrib}" />
                        </classpath>
                </taskdef>
 </target>
        <target name="incserial" depends="setclass">
                <copy todir="bin/${jardir}/${resources}">
                        <fileset dir="${KCBSDir}/${resources}">
                                <include name="${build.properties}" />
                        </fileset>
                        <filterchain>
                                <expandproperties />
                        </filterchain>
                </copy>
                <if> <isset Property="build.number" /> <then>
                        <echo message="update build requested" />
                </then> <else>
                        <echo message="new build requested" />
                        <buildnumber />
                </else> </if>
                <propertyfile file="bin/${jardir}/${resources}/${build.properties}">
                        <entry key="serialnumber" value="${build.number}" />
                        <entry key="membernumber" value="${member.number}" />
                        <entry key="name" value="${member.name}" />
                </propertyfile>
                <echo message="serial number: ${build.number}" />
        </target>
        <target name="jar" description="Compile serialized jar" depends="incserial,if_windows,if_linux">
                <echo message="Using destination file ${jarfile}" />
                <javac srcdir="src" destdir="bin" includeantruntime="false" classpathref="compile-jars" />
                <jar destfile="${jarfile}" basedir="bin" filesetmanifest="mergewithoutmain">
                        <manifest>
                                <attribute name="Manifest-Version" value="1.0"/>
                                <attribute name="Created-By" value="ant 1.9.2 on CentOS 7" />
                                <attribute name="Main-Class" value="KCBSEvents.KCBSEvents" />
                        </manifest>
                </jar>
        </target>
</project>


On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote: 

If you have created your JAR the first step is done.
 
Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
 
 
 
1. Hard coded start script.
 
Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
 
@echo off
 
java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
 
 
 
2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
 
 
 
3. Use Ant + <java><classpath> for starting
 
 
 
4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
 
 
 
5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
 
 
 
6. Use a launcher which uses a dependency manager for getting the classpath
 
 
 
 
 
 
 
You don't have to replicate path definitions in your buildfile, you could (and should) use references:
 
<javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
 
<java><classpath refid="runtime.cp"/>
 
 
 
 
 
You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
 
 
 
 
 
Jan
 
 
 

 

 


Re: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
My apologies again but I have not made any progress on this problem. Is
there perhaps a better forum I should be using at this point? I did make
one discovery. It appears that although the application works in Eclipse
when I try to export it to a runnable jar using the Eclipse wizard, the
resulting jar fails as well. It seems to me that the problem is not ant
specific but something in the app build per se.

On 2/21/2019 10:18 AM, Dennis Putnam wrote:
> I found an article on adding Maven dependencies to my ant script.
> While I'm getting a successful build but the same exception when I run
> the jar, I hope this is getting me closer. At least the pom.xml is in
> the build. I am wondering if the added *fileset* is right and working.
> Here is my latest:
>
>     <?xml version="1.0" encoding="UTF-8"?>
>     <project name="KCBSEvents" default="jar" basedir="."
>     *xmlns:artifact="antlib:org.apache.maven.artifact.ant"*>
>             <property name="build.properties" value="build.properties"/>
>             <property name="resources" value="resource" />
>             <property name="jardir" value="KCBSEvents" />
>             <property name="KCBSDir" value="src/KCBSEvents" />
>             <property name="member.number" value="000000" />
>             <property name="member.name" value="" />
>             <property name="jarpath"
>     value="/${user.home}/.m2/repository" />
>            *<path id="maven-ant-tasks.classpath"
>     path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar" />**
>     **        <typedef
>     resource="org/apache/maven/artifact/ant/antlib.xml"
>     uri="antlib:org.apache.maven.artifact.ant"
>     classpathref="maven-ant-tasks.classpath" />**
>     **        <artifact:pom id="pomfile" file="pom.xml" />**
>     **        <artifact:dependencies filesetId="mvn-dependencies"
>     pomRefId="pomfile" />*
>             <path id="compile-jars">
>                     <multirootfileset
>     basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
>                             <include name="commons-io-2.5.jar" />
>                             <include name="httpclient-4.5.6.jar" />
>                             <include name="httpcore-4.4.10.jar" />
>                             <include name="commons-logging-1.2.jar" />
>                             <include name="commons-codec-1.10.jar" />
>                             <include name="json-simple-1.1.1.jar" />
>                     </multirootfileset>
>                     *<fileset refid="mvn-dependencies" />*
>             </path>
>             <target name="checkOS">
>                     <condition property="isWindows">
>                             <os family="windows" />
>                     </condition>
>                     <condition property="isLinux">
>                             <os family="unix" />
>                     </condition>
>             </target>
>             <target name="if_windows" depends="checkOS" if="isWindows">
>                     <property name="jarfile"
>     value="C:\temp\KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="H:\html\Applets\ant-contrib" />
>             </target>
>             <target name="if_linux" depends="checkOS" if="isLinux">
>                     <property name="jarfile"
>     value="/tmp/${member.number}/KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>             </target>
>             <target name="setclass" depends="if_linux,if_windows">
>                     <taskdef
>     resource="net/sf/antcontrib/antcontrib.properties">
>                             <classpath>
>                                     <pathelement
>     location="${antcontrib}" />
>                             </classpath>
>                     </taskdef>
>      </target>
>             <target name="incserial" depends="setclass">
>                     <copy todir="bin/${jardir}/${resources}">
>                             <fileset dir="${KCBSDir}/${resources}">
>                                     <include name="${build.properties}" />
>                             </fileset>
>                             <filterchain>
>                                     <expandproperties />
>                             </filterchain>
>                     </copy>
>                     <if> <isset Property="build.number" /> <then>
>                             <echo message="update build requested" />
>                     </then> <else>
>                             <echo message="new build requested" />
>                             <buildnumber />
>                     </else> </if>
>                     <propertyfile
>     file="bin/${jardir}/${resources}/${build.properties}">
>                             <entry key="serialnumber"
>     value="${build.number}" />
>                             <entry key="membernumber"
>     value="${member.number}" />
>                             <entry key="name" value="${member.name}" />
>                     </propertyfile>
>                     <echo message="serial number: ${build.number}" />
>             </target>
>             <target name="jar" description="Compile serialized jar"
>     depends="incserial,if_windows,if_linux">
>                     <echo message="Using destination file ${jarfile}" />
>                     <javac srcdir="src" destdir="bin"
>     includeantruntime="false" classpathref="compile-jars" />
>                     <jar destfile="${jarfile}" basedir="bin"
>     filesetmanifest="mergewithoutmain">
>                             <manifest>
>                                     <attribute name="Manifest-Version"
>     value="1.0"/>
>                                     <attribute name="Created-By"
>     value="ant 1.9.2 on CentOS 7" />
>                                     <attribute name="Main-Class"
>     value="KCBSEvents.KCBSEvents" />
>                             </manifest>
>                     </jar>
>             </target>
>     </project>
>
>
> On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote:
>> If you have created your JAR the first step is done.
>>
>> Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
>>
>>  
>>
>> 1. Hard coded start script.
>>
>> Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
>>
>> @echo off
>>
>> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
>>
>>  
>>
>> 2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
>>
>>  
>>
>> 3. Use Ant + <java><classpath> for starting
>>
>>  
>>
>> 4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
>>
>>  
>>
>> 5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
>>
>>  
>>
>> 6. Use a launcher which uses a dependency manager for getting the classpath
>>
>>  
>>
>>  
>>
>>  
>>
>> You don't have to replicate path definitions in your buildfile, you could (and should) use references:
>>
>> <javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
>>
>> <java><classpath refid="runtime.cp"/>
>>
>>  
>>
>>  
>>
>> You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
>>
>>  
>>
>>  
>>
>> Jan
>>
>>  
>>
>


Re: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
I found an article on adding Maven dependencies to my ant script. While
I'm getting a successful build but the same exception when I run the
jar, I hope this is getting me closer. At least the pom.xml is in the
build. I am wondering if the added *fileset* is right and working. Here
is my latest:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="KCBSEvents" default="jar" basedir="."
    *xmlns:artifact="antlib:org.apache.maven.artifact.ant"*>
            <property name="build.properties" value="build.properties"/>
            <property name="resources" value="resource" />
            <property name="jardir" value="KCBSEvents" />
            <property name="KCBSDir" value="src/KCBSEvents" />
            <property name="member.number" value="000000" />
            <property name="member.name" value="" />
            <property name="jarpath" value="/${user.home}/.m2/repository" />
           *<path id="maven-ant-tasks.classpath"
    path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar" />**
    **        <typedef
    resource="org/apache/maven/artifact/ant/antlib.xml"
    uri="antlib:org.apache.maven.artifact.ant"
    classpathref="maven-ant-tasks.classpath" />**
    **        <artifact:pom id="pomfile" file="pom.xml" />**
    **        <artifact:dependencies filesetId="mvn-dependencies"
    pomRefId="pomfile" />*
            <path id="compile-jars">
                    <multirootfileset
    basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
                            <include name="commons-io-2.5.jar" />
                            <include name="httpclient-4.5.6.jar" />
                            <include name="httpcore-4.4.10.jar" />
                            <include name="commons-logging-1.2.jar" />
                            <include name="commons-codec-1.10.jar" />
                            <include name="json-simple-1.1.1.jar" />
                    </multirootfileset>
                    *<fileset refid="mvn-dependencies" />*
            </path>
            <target name="checkOS">
                    <condition property="isWindows">
                            <os family="windows" />
                    </condition>
                    <condition property="isLinux">
                            <os family="unix" />
                    </condition>
            </target>
            <target name="if_windows" depends="checkOS" if="isWindows">
                    <property name="jarfile"
    value="C:\temp\KCBSEvents.jar" />
                    <property name="antcontrib"
    value="H:\html\Applets\ant-contrib" />
            </target>
            <target name="if_linux" depends="checkOS" if="isLinux">
                    <property name="jarfile"
    value="/tmp/${member.number}/KCBSEvents.jar" />
                    <property name="antcontrib"
    value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
            </target>
            <target name="setclass" depends="if_linux,if_windows">
                    <taskdef
    resource="net/sf/antcontrib/antcontrib.properties">
                            <classpath>
                                    <pathelement location="${antcontrib}" />
                            </classpath>
                    </taskdef>
     </target>
            <target name="incserial" depends="setclass">
                    <copy todir="bin/${jardir}/${resources}">
                            <fileset dir="${KCBSDir}/${resources}">
                                    <include name="${build.properties}" />
                            </fileset>
                            <filterchain>
                                    <expandproperties />
                            </filterchain>
                    </copy>
                    <if> <isset Property="build.number" /> <then>
                            <echo message="update build requested" />
                    </then> <else>
                            <echo message="new build requested" />
                            <buildnumber />
                    </else> </if>
                    <propertyfile
    file="bin/${jardir}/${resources}/${build.properties}">
                            <entry key="serialnumber"
    value="${build.number}" />
                            <entry key="membernumber"
    value="${member.number}" />
                            <entry key="name" value="${member.name}" />
                    </propertyfile>
                    <echo message="serial number: ${build.number}" />
            </target>
            <target name="jar" description="Compile serialized jar"
    depends="incserial,if_windows,if_linux">
                    <echo message="Using destination file ${jarfile}" />
                    <javac srcdir="src" destdir="bin"
    includeantruntime="false" classpathref="compile-jars" />
                    <jar destfile="${jarfile}" basedir="bin"
    filesetmanifest="mergewithoutmain">
                            <manifest>
                                    <attribute name="Manifest-Version"
    value="1.0"/>
                                    <attribute name="Created-By"
    value="ant 1.9.2 on CentOS 7" />
                                    <attribute name="Main-Class"
    value="KCBSEvents.KCBSEvents" />
                            </manifest>
                    </jar>
            </target>
    </project>


On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote:
> If you have created your JAR the first step is done.
>
> Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
>
>  
>
> 1. Hard coded start script.
>
> Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
>
> @echo off
>
> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
>
>  
>
> 2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
>
>  
>
> 3. Use Ant + <java><classpath> for starting
>
>  
>
> 4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
>
>  
>
> 5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
>
>  
>
> 6. Use a launcher which uses a dependency manager for getting the classpath
>
>  
>
>  
>
>  
>
> You don't have to replicate path definitions in your buildfile, you could (and should) use references:
>
> <javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
>
> <java><classpath refid="runtime.cp"/>
>
>  
>
>  
>
> You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
>
>  
>
>  
>
> Jan
>
>  
>


Re: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Jan,

Thanks. I'm using option 4. At least that is what my build file is
supposed to be doing. The problem is while the build is successful there
is something wrong with the jar produced. I suspect the Maven
dependencies are not linked in correctly in the compiled jar because the
pom.xml is not being included in the build.

On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote:
> If you have created your JAR the first step is done.
>
> Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:
>
>  
>
> 1. Hard coded start script.
>
> Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
>
> @echo off
>
> java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
>
>  
>
> 2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)
>
>  
>
> 3. Use Ant + <java><classpath> for starting
>
>  
>
> 4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
>
>  
>
> 5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar
>
>  
>
> 6. Use a launcher which uses a dependency manager for getting the classpath
>
>  
>
>  
>
>  
>
> You don't have to replicate path definitions in your buildfile, you could (and should) use references:
>
> <javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
>
> <java><classpath refid="runtime.cp"/>
>
>  
>
>  
>
> You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
>
>  
>
>  
>
> Jan
>
>  
>
>  
>
> Von: Dennis Putnam [mailto:dap1@bellsouth.net] 
> Gesendet: Dienstag, 19. Februar 2019 15:40
> An: user@ant.apache.org
> Betreff: Re: Javac Run By Ant Script is Unable to Find External Jars
>
>  
>
> Hi Jaikiran,
>
> Thanks for the reply. Here is my command:
>
> /bin/ant -v -Dmember.number=$number -Dmember.name=\"$name\" -f makejar.xml
>
> I assume it is using ant's java task based on the build file (makejar.xml). I'm a bit confused. Doesn't all the necessary classpath info come from the build xml? Since the Maven pom.xml is never referenced anywhere in the build file and the Maven dependency causes that exception, it seems to me that is where the problem lies. Doesn't the pom.xml need to be referenced somewhere?
>
> In any case, how do I set up a classpath for the ant command (-lib) since I have multiple paths? Do I have to copy all my jars into a single directory? Why is duplication of these paths even necessary? This seems like it is getting far afield since I did not have to do all that before I messed up the build file classpath.
>
> On 2/18/2019 11:03 PM, Jaikiran Pai wrote:
>
> Hi Dennis,
>  
> I think you are almost there to get this working. How are you running
> this Java application? Are you using Ant's java task? What does it look
> like? Just like you did with javac, the java task will need to know what
> classpath to use while running the application. As long as you setup
> your classpath to contain all these necessary jar files, you should no
> longer see those exceptions.
>  
> -Jaikiran
>  
> On 18/02/19 8:15 PM, Dennis Putnam wrote:
>
> Hi Matt and Jan,
>  
> Thanks to both of you as I am closer but I think I am still missing a
> piece. I am now getting a successful build but the resulting jar is
> not finding the classes in the external jars. When I run the jar I get
> this exception:
>  
>     Exception in thread "main" java.lang.NoClassDefFoundError:
>     org/apache/http/HttpEntity
>             at KCBSEvents.Registration.isRegistered(Unknown Source)
>             at KCBSEvents.KCBSEvents.main(Unknown Source)
>     Caused by: java.lang.ClassNotFoundException:
>     org.apache.http.HttpEntity
>             at java.net.URLClassLoader.findClass(Unknown Source)
>             at java.lang.ClassLoader.loadClass(Unknown Source)
>             at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>             at java.lang.ClassLoader.loadClass(Unknown Source)
>             ... 2 more
>  
>  
> That happens to be the first attempt to execute one of the external
> jar classes which is a Maven dependency. Here is my new build.xml:
>  
>     <?xml version="1.0" encoding="UTF-8"?>
>     <project name="KCBSEvents" default="jar" basedir=".">
>             <property name="build.properties" value="build.properties"/>
>             <property name="resources" value="resource" />
>             <property name="jardir" value="KCBSEvents" />
>             <property name="KCBSDir" value="src/KCBSEvents" />
>             <property name="member.number" value="000000" />
>             <property name="member.name" value="" />
>            *<property name="jarpath"
>     value="/${user.home}/.m2/repository" />**
>     **        <path id="compile-jars">**
>     **                <multirootfileset
>     basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">**
>     **                        <include name="commons-io-2.5.jar" />**
>     **                        <include name="httpclient-4.5.6.jar" />**
>     **                        <include name="httpcore-4.4.10.jar" />**
>     **                        <include name="commons-logging-1.2.jar" />**
>     **                        <include name="commons-codec-1.10.jar" />**
>     **                        <include name="json-simple-1.1.1.jar" />**
>     **                </multirootfileset>**
>     **        </path>*
>             <target name="checkOS">
>                     <condition property="isWindows">
>                             <os family="windows" />
>                     </condition>
>                     <condition property="isLinux">
>                             <os family="unix" />
>                     </condition>
>             </target>
>             <target name="if_windows" depends="checkOS" if="isWindows">
>                     <property name="jarfile"
>     value="C:\temp\KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="H:\html\Applets\ant-contrib" />
>             </target>
>             <target name="if_linux" depends="checkOS" if="isLinux">
>                     <property name="jarfile"
>     value="/tmp/${member.number}/KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>             </target>
>             <target name="setclass" depends="if_linux,if_windows">
>                     <taskdef
>     resource="net/sf/antcontrib/antcontrib.properties">
>                             <classpath>
>                                     <pathelement
>     location="${antcontrib}" />
>                             </classpath>
>                     </taskdef>
>             </target>
>             <target name="incserial" depends="setclass">
>                     <copy todir="bin/${jardir}/${resources}">
>                             <fileset dir="${KCBSDir}/${resources}">
>                                     <include name="${build.properties}" />
>                             </fileset>
>                             <filterchain>
>                                     <expandproperties />
>                             </filterchain>
>                     </copy>
>                     <if> <isset Property="build.number" /> <then>
>                             <echo message="update build requested" />
>                     </then> <else>
>                             <echo message="new build requested" />
>                             <buildnumber />
>                     </else> </if>
>                     <propertyfile
>     file="bin/${jardir}/${resources}/${build.properties}">
>                             <entry key="serialnumber"
>     value="${build.number}" />
>                             <entry key="membernumber"
>     value="${member.number}" />
>                             <entry key="name" value="${member.name}" />
>                     </propertyfile>
>                     <echo message="serial number: ${build.number}" />
>             </target>
>             <target name="jar" description="Compile serialized jar"
>     depends="incserial,if_windows,if_linux">
>                     <echo message="Using destination file ${jarfile}" />
>                     <javac srcdir="src" destdir="bin"
>     includeantruntime="false" *classpathref="compile-jars"* />
>                     <jar destfile="${jarfile}" basedir="bin"
>     filesetmanifest="mergewithoutmain">
>                             <manifest>
>                                     <attribute name="Manifest-Version"
>     value="1.0"/>
>                                     <attribute name="Created-By"
>     value="ant 1.9.2 on CentOS 7" />
>                                     <attribute name="Main-Class"
>     value="KCBSEvents.KCBSEvents" />
>                             </manifest>
>                             *<!-- zipfilesets removed -->*
>                     </jar>
>             </target>
>     </project>
>  
> Does this come back to my question about needing the zipfileset
> elements for the Maven jars? I don't know how the pom.xml for Maven
> gets pulled into this either.
>  
> On 2/17/2019 12:45 PM, Matt Bertolini wrote:
>
> Hi Dennis,
>  
> I think you might be mixing up Eclipse concepts and Ant concepts and that
> might be causing some extra confusion. Based on your original email, the
> compiler is having issues finding your third-party dependencies. I believe
> Jaikiran is correct in saying that the <javac> task needs to be given some
> sort of classpath. The .classpath file is an Eclipse concept and unless
> there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
> file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
> <javac> task has a default value for the classpath attribute. If no
> classpath or classpathref is specified then the compiler is not passed any
> classpath information.
>  
> I would start by locating the folder where your third-party dependencies
> are and create a <path> element containing them like this:
>  
> <path id="compile-classpath">
>     <fileset dir="/the/path/to/your/third/party/jars"/>
> </path>
>  
> Once you have a path defined you can pass the classpath to the <javac> task
> using a refid like this:
>  
> <javac srcdir="src" destdir="bin" includeantruntime="false"
> classpathref="compile-classpath"/>
>  
> Try that and see how it goes.
>  
> Matt Bertolini
>  
>  
>
>  
>
>  
>
>  
>
>



AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
If you have created your JAR the first step is done.

Starting the JAR could be done in several ways. Common is that you have to have all external classes on the runtime classpath:

 

1. Hard coded start script.

Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)

@echo off

java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*

 

2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|ant.sh)

 

3. Use Ant + <java><classpath> for starting

 

4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)

 

5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your jar

 

6. Use a launcher which uses a dependency manager for getting the classpath

 

 

 

You don't have to replicate path definitions in your buildfile, you could (and should) use references:

<javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…

<java><classpath refid="runtime.cp"/>

 

 

You mave have a look at http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

 

 

Jan

 

 

Von: Dennis Putnam [mailto:dap1@bellsouth.net] 
Gesendet: Dienstag, 19. Februar 2019 15:40
An: user@ant.apache.org
Betreff: Re: Javac Run By Ant Script is Unable to Find External Jars

 

Hi Jaikiran,

Thanks for the reply. Here is my command:

/bin/ant -v -Dmember.number=$number -Dmember.name=\"$name\" -f makejar.xml

I assume it is using ant's java task based on the build file (makejar.xml). I'm a bit confused. Doesn't all the necessary classpath info come from the build xml? Since the Maven pom.xml is never referenced anywhere in the build file and the Maven dependency causes that exception, it seems to me that is where the problem lies. Doesn't the pom.xml need to be referenced somewhere?

In any case, how do I set up a classpath for the ant command (-lib) since I have multiple paths? Do I have to copy all my jars into a single directory? Why is duplication of these paths even necessary? This seems like it is getting far afield since I did not have to do all that before I messed up the build file classpath.

On 2/18/2019 11:03 PM, Jaikiran Pai wrote:

Hi Dennis,
 
I think you are almost there to get this working. How are you running
this Java application? Are you using Ant's java task? What does it look
like? Just like you did with javac, the java task will need to know what
classpath to use while running the application. As long as you setup
your classpath to contain all these necessary jar files, you should no
longer see those exceptions.
 
-Jaikiran
 
On 18/02/19 8:15 PM, Dennis Putnam wrote:

Hi Matt and Jan,
 
Thanks to both of you as I am closer but I think I am still missing a
piece. I am now getting a successful build but the resulting jar is
not finding the classes in the external jars. When I run the jar I get
this exception:
 
    Exception in thread "main" java.lang.NoClassDefFoundError:
    org/apache/http/HttpEntity
            at KCBSEvents.Registration.isRegistered(Unknown Source)
            at KCBSEvents.KCBSEvents.main(Unknown Source)
    Caused by: java.lang.ClassNotFoundException:
    org.apache.http.HttpEntity
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 2 more
 
 
That happens to be the first attempt to execute one of the external
jar classes which is a Maven dependency. Here is my new build.xml:
 
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="KCBSEvents" default="jar" basedir=".">
            <property name="build.properties" value="build.properties"/>
            <property name="resources" value="resource" />
            <property name="jardir" value="KCBSEvents" />
            <property name="KCBSDir" value="src/KCBSEvents" />
            <property name="member.number" value="000000" />
            <property name="member.name" value="" />
           *<property name="jarpath"
    value="/${user.home}/.m2/repository" />**
    **        <path id="compile-jars">**
    **                <multirootfileset
    basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">**
    **                        <include name="commons-io-2.5.jar" />**
    **                        <include name="httpclient-4.5.6.jar" />**
    **                        <include name="httpcore-4.4.10.jar" />**
    **                        <include name="commons-logging-1.2.jar" />**
    **                        <include name="commons-codec-1.10.jar" />**
    **                        <include name="json-simple-1.1.1.jar" />**
    **                </multirootfileset>**
    **        </path>*
            <target name="checkOS">
                    <condition property="isWindows">
                            <os family="windows" />
                    </condition>
                    <condition property="isLinux">
                            <os family="unix" />
                    </condition>
            </target>
            <target name="if_windows" depends="checkOS" if="isWindows">
                    <property name="jarfile"
    value="C:\temp\KCBSEvents.jar" />
                    <property name="antcontrib"
    value="H:\html\Applets\ant-contrib" />
            </target>
            <target name="if_linux" depends="checkOS" if="isLinux">
                    <property name="jarfile"
    value="/tmp/${member.number}/KCBSEvents.jar" />
                    <property name="antcontrib"
    value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
            </target>
            <target name="setclass" depends="if_linux,if_windows">
                    <taskdef
    resource="net/sf/antcontrib/antcontrib.properties">
                            <classpath>
                                    <pathelement
    location="${antcontrib}" />
                            </classpath>
                    </taskdef>
            </target>
            <target name="incserial" depends="setclass">
                    <copy todir="bin/${jardir}/${resources}">
                            <fileset dir="${KCBSDir}/${resources}">
                                    <include name="${build.properties}" />
                            </fileset>
                            <filterchain>
                                    <expandproperties />
                            </filterchain>
                    </copy>
                    <if> <isset Property="build.number" /> <then>
                            <echo message="update build requested" />
                    </then> <else>
                            <echo message="new build requested" />
                            <buildnumber />
                    </else> </if>
                    <propertyfile
    file="bin/${jardir}/${resources}/${build.properties}">
                            <entry key="serialnumber"
    value="${build.number}" />
                            <entry key="membernumber"
    value="${member.number}" />
                            <entry key="name" value="${member.name}" />
                    </propertyfile>
                    <echo message="serial number: ${build.number}" />
            </target>
            <target name="jar" description="Compile serialized jar"
    depends="incserial,if_windows,if_linux">
                    <echo message="Using destination file ${jarfile}" />
                    <javac srcdir="src" destdir="bin"
    includeantruntime="false" *classpathref="compile-jars"* />
                    <jar destfile="${jarfile}" basedir="bin"
    filesetmanifest="mergewithoutmain">
                            <manifest>
                                    <attribute name="Manifest-Version"
    value="1.0"/>
                                    <attribute name="Created-By"
    value="ant 1.9.2 on CentOS 7" />
                                    <attribute name="Main-Class"
    value="KCBSEvents.KCBSEvents" />
                            </manifest>
                            *<!-- zipfilesets removed -->*
                    </jar>
            </target>
    </project>
 
Does this come back to my question about needing the zipfileset
elements for the Maven jars? I don't know how the pom.xml for Maven
gets pulled into this either.
 
On 2/17/2019 12:45 PM, Matt Bertolini wrote:

Hi Dennis,
 
I think you might be mixing up Eclipse concepts and Ant concepts and that
might be causing some extra confusion. Based on your original email, the
compiler is having issues finding your third-party dependencies. I believe
Jaikiran is correct in saying that the <javac> task needs to be given some
sort of classpath. The .classpath file is an Eclipse concept and unless
there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
<javac> task has a default value for the classpath attribute. If no
classpath or classpathref is specified then the compiler is not passed any
classpath information.
 
I would start by locating the folder where your third-party dependencies
are and create a <path> element containing them like this:
 
<path id="compile-classpath">
    <fileset dir="/the/path/to/your/third/party/jars"/>
</path>
 
Once you have a path defined you can pass the classpath to the <javac> task
using a refid like this:
 
<javac srcdir="src" destdir="bin" includeantruntime="false"
classpathref="compile-classpath"/>
 
Try that and see how it goes.
 
Matt Bertolini
 
 

 

 

 


Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Jaikiran,

Thanks for the reply. Here is my command:

    /bin/ant -v -Dmember.number=$number -Dmember.name=\"$name\" -f
    makejar.xml

I assume it is using ant's java task based on the build file
(makejar.xml). I'm a bit confused. Doesn't all the necessary classpath
info come from the build xml? Since the Maven pom.xml is never
referenced anywhere in the build file and the Maven dependency causes
that exception, it seems to me that is where the problem lies. Doesn't
the pom.xml need to be referenced somewhere?

In any case, how do I set up a classpath for the ant command (-lib)
since I have multiple paths? Do I have to copy all my jars into a single
directory? Why is duplication of these paths even necessary? This seems
like it is getting far afield since I did not have to do all that before
I messed up the build file classpath.

On 2/18/2019 11:03 PM, Jaikiran Pai wrote:
> Hi Dennis,
>
> I think you are almost there to get this working. How are you running
> this Java application? Are you using Ant's java task? What does it look
> like? Just like you did with javac, the java task will need to know what
> classpath to use while running the application. As long as you setup
> your classpath to contain all these necessary jar files, you should no
> longer see those exceptions.
>
> -Jaikiran
>
> On 18/02/19 8:15 PM, Dennis Putnam wrote:
>> Hi Matt and Jan,
>>
>> Thanks to both of you as I am closer but I think I am still missing a
>> piece. I am now getting a successful build but the resulting jar is
>> not finding the classes in the external jars. When I run the jar I get
>> this exception:
>>
>>     Exception in thread "main" java.lang.NoClassDefFoundError:
>>     org/apache/http/HttpEntity
>>             at KCBSEvents.Registration.isRegistered(Unknown Source)
>>             at KCBSEvents.KCBSEvents.main(Unknown Source)
>>     Caused by: java.lang.ClassNotFoundException:
>>     org.apache.http.HttpEntity
>>             at java.net.URLClassLoader.findClass(Unknown Source)
>>             at java.lang.ClassLoader.loadClass(Unknown Source)
>>             at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>>             at java.lang.ClassLoader.loadClass(Unknown Source)
>>             ... 2 more
>>
>>
>> That happens to be the first attempt to execute one of the external
>> jar classes which is a Maven dependency. Here is my new build.xml:
>>
>>     <?xml version="1.0" encoding="UTF-8"?>
>>     <project name="KCBSEvents" default="jar" basedir=".">
>>             <property name="build.properties" value="build.properties"/>
>>             <property name="resources" value="resource" />
>>             <property name="jardir" value="KCBSEvents" />
>>             <property name="KCBSDir" value="src/KCBSEvents" />
>>             <property name="member.number" value="000000" />
>>             <property name="member.name" value="" />
>>            *<property name="jarpath"
>>     value="/${user.home}/.m2/repository" />**
>>     **        <path id="compile-jars">**
>>     **                <multirootfileset
>>     basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">**
>>     **                        <include name="commons-io-2.5.jar" />**
>>     **                        <include name="httpclient-4.5.6.jar" />**
>>     **                        <include name="httpcore-4.4.10.jar" />**
>>     **                        <include name="commons-logging-1.2.jar" />**
>>     **                        <include name="commons-codec-1.10.jar" />**
>>     **                        <include name="json-simple-1.1.1.jar" />**
>>     **                </multirootfileset>**
>>     **        </path>*
>>             <target name="checkOS">
>>                     <condition property="isWindows">
>>                             <os family="windows" />
>>                     </condition>
>>                     <condition property="isLinux">
>>                             <os family="unix" />
>>                     </condition>
>>             </target>
>>             <target name="if_windows" depends="checkOS" if="isWindows">
>>                     <property name="jarfile"
>>     value="C:\temp\KCBSEvents.jar" />
>>                     <property name="antcontrib"
>>     value="H:\html\Applets\ant-contrib" />
>>             </target>
>>             <target name="if_linux" depends="checkOS" if="isLinux">
>>                     <property name="jarfile"
>>     value="/tmp/${member.number}/KCBSEvents.jar" />
>>                     <property name="antcontrib"
>>     value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>>             </target>
>>             <target name="setclass" depends="if_linux,if_windows">
>>                     <taskdef
>>     resource="net/sf/antcontrib/antcontrib.properties">
>>                             <classpath>
>>                                     <pathelement
>>     location="${antcontrib}" />
>>                             </classpath>
>>                     </taskdef>
>>             </target>
>>             <target name="incserial" depends="setclass">
>>                     <copy todir="bin/${jardir}/${resources}">
>>                             <fileset dir="${KCBSDir}/${resources}">
>>                                     <include name="${build.properties}" />
>>                             </fileset>
>>                             <filterchain>
>>                                     <expandproperties />
>>                             </filterchain>
>>                     </copy>
>>                     <if> <isset Property="build.number" /> <then>
>>                             <echo message="update build requested" />
>>                     </then> <else>
>>                             <echo message="new build requested" />
>>                             <buildnumber />
>>                     </else> </if>
>>                     <propertyfile
>>     file="bin/${jardir}/${resources}/${build.properties}">
>>                             <entry key="serialnumber"
>>     value="${build.number}" />
>>                             <entry key="membernumber"
>>     value="${member.number}" />
>>                             <entry key="name" value="${member.name}" />
>>                     </propertyfile>
>>                     <echo message="serial number: ${build.number}" />
>>             </target>
>>             <target name="jar" description="Compile serialized jar"
>>     depends="incserial,if_windows,if_linux">
>>                     <echo message="Using destination file ${jarfile}" />
>>                     <javac srcdir="src" destdir="bin"
>>     includeantruntime="false" *classpathref="compile-jars"* />
>>                     <jar destfile="${jarfile}" basedir="bin"
>>     filesetmanifest="mergewithoutmain">
>>                             <manifest>
>>                                     <attribute name="Manifest-Version"
>>     value="1.0"/>
>>                                     <attribute name="Created-By"
>>     value="ant 1.9.2 on CentOS 7" />
>>                                     <attribute name="Main-Class"
>>     value="KCBSEvents.KCBSEvents" />
>>                             </manifest>
>>                             *<!-- zipfilesets removed -->*
>>                     </jar>
>>             </target>
>>     </project>
>>
>> Does this come back to my question about needing the zipfileset
>> elements for the Maven jars? I don't know how the pom.xml for Maven
>> gets pulled into this either.
>>
>> On 2/17/2019 12:45 PM, Matt Bertolini wrote:
>>> Hi Dennis,
>>>
>>> I think you might be mixing up Eclipse concepts and Ant concepts and that
>>> might be causing some extra confusion. Based on your original email, the
>>> compiler is having issues finding your third-party dependencies. I believe
>>> Jaikiran is correct in saying that the <javac> task needs to be given some
>>> sort of classpath. The .classpath file is an Eclipse concept and unless
>>> there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
>>> file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
>>> <javac> task has a default value for the classpath attribute. If no
>>> classpath or classpathref is specified then the compiler is not passed any
>>> classpath information.
>>>
>>> I would start by locating the folder where your third-party dependencies
>>> are and create a <path> element containing them like this:
>>>
>>> <path id="compile-classpath">
>>>     <fileset dir="/the/path/to/your/third/party/jars"/>
>>> </path>
>>>
>>> Once you have a path defined you can pass the classpath to the <javac> task
>>> using a refid like this:
>>>
>>> <javac srcdir="src" destdir="bin" includeantruntime="false"
>>> classpathref="compile-classpath"/>
>>>
>>> Try that and see how it goes.
>>>
>>> Matt Bertolini
>>>
>>>


Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Jaikiran Pai <ja...@apache.org>.
Hi Dennis,

I think you are almost there to get this working. How are you running
this Java application? Are you using Ant's java task? What does it look
like? Just like you did with javac, the java task will need to know what
classpath to use while running the application. As long as you setup
your classpath to contain all these necessary jar files, you should no
longer see those exceptions.

-Jaikiran

On 18/02/19 8:15 PM, Dennis Putnam wrote:
> Hi Matt and Jan,
>
> Thanks to both of you as I am closer but I think I am still missing a
> piece. I am now getting a successful build but the resulting jar is
> not finding the classes in the external jars. When I run the jar I get
> this exception:
>
>     Exception in thread "main" java.lang.NoClassDefFoundError:
>     org/apache/http/HttpEntity
>             at KCBSEvents.Registration.isRegistered(Unknown Source)
>             at KCBSEvents.KCBSEvents.main(Unknown Source)
>     Caused by: java.lang.ClassNotFoundException:
>     org.apache.http.HttpEntity
>             at java.net.URLClassLoader.findClass(Unknown Source)
>             at java.lang.ClassLoader.loadClass(Unknown Source)
>             at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>             at java.lang.ClassLoader.loadClass(Unknown Source)
>             ... 2 more
>
>
> That happens to be the first attempt to execute one of the external
> jar classes which is a Maven dependency. Here is my new build.xml:
>
>     <?xml version="1.0" encoding="UTF-8"?>
>     <project name="KCBSEvents" default="jar" basedir=".">
>             <property name="build.properties" value="build.properties"/>
>             <property name="resources" value="resource" />
>             <property name="jardir" value="KCBSEvents" />
>             <property name="KCBSDir" value="src/KCBSEvents" />
>             <property name="member.number" value="000000" />
>             <property name="member.name" value="" />
>            *<property name="jarpath"
>     value="/${user.home}/.m2/repository" />**
>     **        <path id="compile-jars">**
>     **                <multirootfileset
>     basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">**
>     **                        <include name="commons-io-2.5.jar" />**
>     **                        <include name="httpclient-4.5.6.jar" />**
>     **                        <include name="httpcore-4.4.10.jar" />**
>     **                        <include name="commons-logging-1.2.jar" />**
>     **                        <include name="commons-codec-1.10.jar" />**
>     **                        <include name="json-simple-1.1.1.jar" />**
>     **                </multirootfileset>**
>     **        </path>*
>             <target name="checkOS">
>                     <condition property="isWindows">
>                             <os family="windows" />
>                     </condition>
>                     <condition property="isLinux">
>                             <os family="unix" />
>                     </condition>
>             </target>
>             <target name="if_windows" depends="checkOS" if="isWindows">
>                     <property name="jarfile"
>     value="C:\temp\KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="H:\html\Applets\ant-contrib" />
>             </target>
>             <target name="if_linux" depends="checkOS" if="isLinux">
>                     <property name="jarfile"
>     value="/tmp/${member.number}/KCBSEvents.jar" />
>                     <property name="antcontrib"
>     value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
>             </target>
>             <target name="setclass" depends="if_linux,if_windows">
>                     <taskdef
>     resource="net/sf/antcontrib/antcontrib.properties">
>                             <classpath>
>                                     <pathelement
>     location="${antcontrib}" />
>                             </classpath>
>                     </taskdef>
>             </target>
>             <target name="incserial" depends="setclass">
>                     <copy todir="bin/${jardir}/${resources}">
>                             <fileset dir="${KCBSDir}/${resources}">
>                                     <include name="${build.properties}" />
>                             </fileset>
>                             <filterchain>
>                                     <expandproperties />
>                             </filterchain>
>                     </copy>
>                     <if> <isset Property="build.number" /> <then>
>                             <echo message="update build requested" />
>                     </then> <else>
>                             <echo message="new build requested" />
>                             <buildnumber />
>                     </else> </if>
>                     <propertyfile
>     file="bin/${jardir}/${resources}/${build.properties}">
>                             <entry key="serialnumber"
>     value="${build.number}" />
>                             <entry key="membernumber"
>     value="${member.number}" />
>                             <entry key="name" value="${member.name}" />
>                     </propertyfile>
>                     <echo message="serial number: ${build.number}" />
>             </target>
>             <target name="jar" description="Compile serialized jar"
>     depends="incserial,if_windows,if_linux">
>                     <echo message="Using destination file ${jarfile}" />
>                     <javac srcdir="src" destdir="bin"
>     includeantruntime="false" *classpathref="compile-jars"* />
>                     <jar destfile="${jarfile}" basedir="bin"
>     filesetmanifest="mergewithoutmain">
>                             <manifest>
>                                     <attribute name="Manifest-Version"
>     value="1.0"/>
>                                     <attribute name="Created-By"
>     value="ant 1.9.2 on CentOS 7" />
>                                     <attribute name="Main-Class"
>     value="KCBSEvents.KCBSEvents" />
>                             </manifest>
>                             *<!-- zipfilesets removed -->*
>                     </jar>
>             </target>
>     </project>
>
> Does this come back to my question about needing the zipfileset
> elements for the Maven jars? I don't know how the pom.xml for Maven
> gets pulled into this either.
>
> On 2/17/2019 12:45 PM, Matt Bertolini wrote:
>> Hi Dennis,
>>
>> I think you might be mixing up Eclipse concepts and Ant concepts and that
>> might be causing some extra confusion. Based on your original email, the
>> compiler is having issues finding your third-party dependencies. I believe
>> Jaikiran is correct in saying that the <javac> task needs to be given some
>> sort of classpath. The .classpath file is an Eclipse concept and unless
>> there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
>> file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
>> <javac> task has a default value for the classpath attribute. If no
>> classpath or classpathref is specified then the compiler is not passed any
>> classpath information.
>>
>> I would start by locating the folder where your third-party dependencies
>> are and create a <path> element containing them like this:
>>
>> <path id="compile-classpath">
>>     <fileset dir="/the/path/to/your/third/party/jars"/>
>> </path>
>>
>> Once you have a path defined you can pass the classpath to the <javac> task
>> using a refid like this:
>>
>> <javac srcdir="src" destdir="bin" includeantruntime="false"
>> classpathref="compile-classpath"/>
>>
>> Try that and see how it goes.
>>
>> Matt Bertolini
>>
>>
>

Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Matt and Jan,

Thanks to both of you as I am closer but I think I am still missing a
piece. I am now getting a successful build but the resulting jar is not
finding the classes in the external jars. When I run the jar I get this
exception:

    Exception in thread "main" java.lang.NoClassDefFoundError:
    org/apache/http/HttpEntity
            at KCBSEvents.Registration.isRegistered(Unknown Source)
            at KCBSEvents.KCBSEvents.main(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 2 more


That happens to be the first attempt to execute one of the external jar
classes which is a Maven dependency. Here is my new build.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="KCBSEvents" default="jar" basedir=".">
            <property name="build.properties" value="build.properties"/>
            <property name="resources" value="resource" />
            <property name="jardir" value="KCBSEvents" />
            <property name="KCBSDir" value="src/KCBSEvents" />
            <property name="member.number" value="000000" />
            <property name="member.name" value="" />
           *<property name="jarpath"
    value="/${user.home}/.m2/repository" />**
    **        <path id="compile-jars">**
    **                <multirootfileset
    basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">**
    **                        <include name="commons-io-2.5.jar" />**
    **                        <include name="httpclient-4.5.6.jar" />**
    **                        <include name="httpcore-4.4.10.jar" />**
    **                        <include name="commons-logging-1.2.jar" />**
    **                        <include name="commons-codec-1.10.jar" />**
    **                        <include name="json-simple-1.1.1.jar" />**
    **                </multirootfileset>**
    **        </path>*
            <target name="checkOS">
                    <condition property="isWindows">
                            <os family="windows" />
                    </condition>
                    <condition property="isLinux">
                            <os family="unix" />
                    </condition>
            </target>
            <target name="if_windows" depends="checkOS" if="isWindows">
                    <property name="jarfile"
    value="C:\temp\KCBSEvents.jar" />
                    <property name="antcontrib"
    value="H:\html\Applets\ant-contrib" />
            </target>
            <target name="if_linux" depends="checkOS" if="isLinux">
                    <property name="jarfile"
    value="/tmp/${member.number}/KCBSEvents.jar" />
                    <property name="antcontrib"
    value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
            </target>
            <target name="setclass" depends="if_linux,if_windows">
                    <taskdef
    resource="net/sf/antcontrib/antcontrib.properties">
                            <classpath>
                                    <pathelement location="${antcontrib}" />
                            </classpath>
                    </taskdef>
            </target>
            <target name="incserial" depends="setclass">
                    <copy todir="bin/${jardir}/${resources}">
                            <fileset dir="${KCBSDir}/${resources}">
                                    <include name="${build.properties}" />
                            </fileset>
                            <filterchain>
                                    <expandproperties />
                            </filterchain>
                    </copy>
                    <if> <isset Property="build.number" /> <then>
                            <echo message="update build requested" />
                    </then> <else>
                            <echo message="new build requested" />
                            <buildnumber />
                    </else> </if>
                    <propertyfile
    file="bin/${jardir}/${resources}/${build.properties}">
                            <entry key="serialnumber"
    value="${build.number}" />
                            <entry key="membernumber"
    value="${member.number}" />
                            <entry key="name" value="${member.name}" />
                    </propertyfile>
                    <echo message="serial number: ${build.number}" />
            </target>
            <target name="jar" description="Compile serialized jar"
    depends="incserial,if_windows,if_linux">
                    <echo message="Using destination file ${jarfile}" />
                    <javac srcdir="src" destdir="bin"
    includeantruntime="false" *classpathref="compile-jars"* />
                    <jar destfile="${jarfile}" basedir="bin"
    filesetmanifest="mergewithoutmain">
                            <manifest>
                                    <attribute name="Manifest-Version"
    value="1.0"/>
                                    <attribute name="Created-By"
    value="ant 1.9.2 on CentOS 7" />
                                    <attribute name="Main-Class"
    value="KCBSEvents.KCBSEvents" />
                            </manifest>
                            *<!-- zipfilesets removed -->*
                    </jar>
            </target>
    </project>

Does this come back to my question about needing the zipfileset elements
for the Maven jars? I don't know how the pom.xml for Maven gets pulled
into this either.

On 2/17/2019 12:45 PM, Matt Bertolini wrote:
> Hi Dennis,
>
> I think you might be mixing up Eclipse concepts and Ant concepts and that
> might be causing some extra confusion. Based on your original email, the
> compiler is having issues finding your third-party dependencies. I believe
> Jaikiran is correct in saying that the <javac> task needs to be given some
> sort of classpath. The .classpath file is an Eclipse concept and unless
> there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
> file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
> <javac> task has a default value for the classpath attribute. If no
> classpath or classpathref is specified then the compiler is not passed any
> classpath information.
>
> I would start by locating the folder where your third-party dependencies
> are and create a <path> element containing them like this:
>
> <path id="compile-classpath">
>     <fileset dir="/the/path/to/your/third/party/jars"/>
> </path>
>
> Once you have a path defined you can pass the classpath to the <javac> task
> using a refid like this:
>
> <javac srcdir="src" destdir="bin" includeantruntime="false"
> classpathref="compile-classpath"/>
>
> Try that and see how it goes.
>
> Matt Bertolini
>
>


Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Matt,

Thanks for that information. Since this used to work I guess somewhere
along the line I must have deleted that classpath info. I will give this
a try. In the mean time does this mean I don't need the zipfileset
elements if I include those jars in the path element? Or do I still need
both because they are Maven dependencies?

On 2/17/2019 12:45 PM, Matt Bertolini wrote:
> Hi Dennis,
>
> I think you might be mixing up Eclipse concepts and Ant concepts and that
> might be causing some extra confusion. Based on your original email, the
> compiler is having issues finding your third-party dependencies. I believe
> Jaikiran is correct in saying that the <javac> task needs to be given some
> sort of classpath. The .classpath file is an Eclipse concept and unless
> there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
> file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
> <javac> task has a default value for the classpath attribute. If no
> classpath or classpathref is specified then the compiler is not passed any
> classpath information.
>
> I would start by locating the folder where your third-party dependencies
> are and create a <path> element containing them like this:
>
> <path id="compile-classpath">
>     <fileset dir="/the/path/to/your/third/party/jars"/>
> </path>
>
> Once you have a path defined you can pass the classpath to the <javac> task
> using a refid like this:
>
> <javac srcdir="src" destdir="bin" includeantruntime="false"
> classpathref="compile-classpath"/>
>
> Try that and see how it goes.
>
> Matt Bertolini
>
> On Sun, Feb 17, 2019 at 10:02 AM Dennis Putnam <da...@bellsouth.net> wrote:
>
>> I apologize for being a pest but this is a problem I cannot resolve on my
>> own. The more I read the more confusing it gets. It seems like there are
>> thousands of ways to accomplish what I want but none make any more sense
>> than what I have. Is there no one that can help me debug this problem or at
>> least point me in the right direction?
>>
>> On 2/14/2019 9:42 AM, Dennis Putnam wrote:
>>
>> Hi Jaikiran,
>>
>> Thanks for the reply. I thought the classpath parameter defaulted to
>> "basedir"/.classpath. In any case I made the following change:
>>
>> <javac srcdir="src" destdir="bin" includeantruntime="false" classpath=".classpath" />
>>
>>
>> Unfortunately that didn't help. The ant output is exactly the same. FWIW
>> here is .classpath:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <classpath>
>>         <classpathentry including="**/*.java" kind="src"
>> output="target/classes" path="src">
>>                 <attributes>
>>                         <attribute name="optional" value="true"/>
>>                         <attribute name="maven.pomderived" value="true"/>
>>                 </attributes>
>>         </classpathentry>
>>         <classpathentry kind="con"
>> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
>>                 <attributes>
>>                         <attribute name="maven.pomderived" value="true"/>
>>                 </attributes>
>>         </classpathentry>
>>         <classpathentry kind="lib"
>> path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
>>         <classpathentry kind="con"
>> path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
>>                 <attributes>
>>                         <attribute name="maven.pomderived" value="true"/>
>>                 </attributes>
>>         </classpathentry>
>>         <classpathentry kind="output" path="target/classes"/>
>>
>> The "lib" path is correct. I am guessing that the next tag essentially
>> points the pom.xml so here it is in case it matters:
>>
>> <project xmlns="http://maven.apache.org/POM/4.0.0"
>> <http://maven.apache.org/POM/4.0.0> xmlns:xsi=
>> "http://www.w3.org/2001/XMLSchema-instance"
>> <http://www.w3.org/2001/XMLSchema-instance> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
>> http://maven.apache.org/xsd/maven-4.0.0.xsd"
>> <http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd>
>>   <modelVersion>4.0.0</modelVersion>
>>   <groupId>KCBSEvents</groupId>
>>   <artifactId>KCBSEvents</artifactId>
>>   <version>0.0.1-SNAPSHOT</version>
>>   <build>
>>     <sourceDirectory>src</sourceDirectory>
>>     <resources>
>>       <resource>
>>         <directory>src</directory>
>>         <excludes>
>>           <exclude>**/*.java</exclude>
>>         </excludes>
>>       </resource>
>>     </resources>
>>     <plugins>
>>       <plugin>
>>         <artifactId>maven-compiler-plugin</artifactId>
>>         <version>3.7.0</version>
>>         <configuration>
>>           <source>1.7</source>
>>           <target>1.7</target>
>>         </configuration>
>>       </plugin>
>>     </plugins>
>>   </build>
>>    <dependencies>
>>         <dependency>
>>                 <groupId>org.apache.httpcomponents</groupId>
>>                 <artifactId>httpclient</artifactId>
>>                 <version>4.5.6</version>
>>         </dependency>
>>         <dependency>
>>                 <groupId>commons-io</groupId>
>>                 <artifactId>commons-io</artifactId>
>>                 <version>2.5</version>
>>         </dependency>
>>         <dependency>
>>                 <groupId>org.apache.httpcomponents</groupId>
>>                 <artifactId>httpcore</artifactId>
>>                 <version>4.4.10</version>
>>         </dependency>
>>         <dependency>
>>                 <groupId>commons-codec</groupId>
>>                 <artifactId>commons-codec</artifactId>
>>                 <version>1.10</version>
>>         </dependency>
>>         <dependency>
>>                 <groupId>commons-logging</groupId>
>>                 <artifactId>commons-logging</artifactId>
>>                 <version>1.2</version>
>>         </dependency>
>>    </dependencies>
>>
>> Presumably the maven libraries are found from the zipfilesets in the ant
>> script.
>>
>> On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
>>
>> Hi Dennis,
>>
>> On 13/02/19 11:56 PM, Dennis Putnam wrote:
>>
>> <javac srcdir="src" destdir="bin" includeantruntime="false" />
>>
>> I don't see any classpath being passed to the javac task in your build
>> script. You should be passing a classpath containing your jars that are
>> required to compile the source. There's more than one way to do that.
>> The javac task manual has more details about ithttps://ant.apache.org/manual/Tasks/javac.html
>>
>>
>> -Jaikiran
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>>



AW: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Yes.
Eclipse uses .project and .classpath.
Ant uses build.xml (and an often used file build.properties).

In contrast to Maven or Gradle Ant doesn't come with a built in dependency manager.
So just declaring "I need JUnit 4.12" doesn't work.
- place the jars by yourself in a directory (e.g. "/libs") and reference that (libs are stored in vcs)
- have a "download script" that places the jars inside that folder (libs are not stored in vcs, only the dependency declaration in the download script)
- use the maven tasks for downloading the files (see Ant's fetch.xml)
- use Ivy as dependency manager and use it to define the path's (see Ant's check.xml)


Jan


> -----Ursprüngliche Nachricht-----
> Von: Dennis Putnam [mailto:dap1@bellsouth.net]
> Gesendet: Montag, 18. Februar 2019 14:35
> An: user@ant.apache.org
> Betreff: Re: AW: Javac Run By Ant Script is Unable to Find External
> Jars
> 
> Hi Jan,
> 
> Thanks. Things are starting to come together in my head. If I
> understand, ant doesn't need the Eclipse .classpath at all and only the
> classpath suggested by Matt is used by ant, right?
> 
> On 2/18/2019 8:11 AM, Jan Matèrne (jhm) wrote:
> > Matt is correct: you are mixing Eclipse and Ant definitions.
> > So here some points by me:
> > * There is no default behaviour of <javac>. You have to specify the
> paths the compiler should use by yourself.
> > * <javac ... classpath=".classpath"/> means, that the file or
> directory ".classpath" should be used for classpath. But the
> .classpath-file is not a jar file, it is a xml file.
> > * I try to "translate" the .classpath:
> >
> > Eclipse: <classpathentry including="**/*.java" kind="src"
> output="target/classes" path="src">
> > Ant:     <javac src="src" dest="target/classes" includes=**/*.java"/>
> >
> > Eclipse: <classpathentry kind="con"
> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.
> debug.ui.launcher.StandardVMType/JavaSE-1.7">
> > Ant:     not used (include current Java runtime)
> >
> > Eclipse: <classpathentry kind="lib" path="/lib/java-ext/json-simple-
> 1.1.1/json-simple-1.1.1.jar"/>
> > Ant:     <javac><classpath><path entry="/lib/java-ext/json-simple-
> 1.1.1/json-simple-1.1.1.jar"/></classpath></javac>
> >   ore more generic
> >          <javac><classpath><fileset dir="lib"
> > includes="**.*.jar"/></classpath></javac>
> >
> > Eclipse: <classpathentry kind="output" path="target/classes"/>
> > Ant:     not used (I think this controlls the "export behaviour" for
> inter-project dependencies)
> >
> > So combined (and tuned):
> >   <property name="build.classes" value="target/classes"/>
> >   <mkdir dir="${build.classes}"/>
> >   <javac src="src" dest="${build.classes}">  <!-- includes not
> required -->
> >     <classpath>
> >       <fileset dir="lib" includes="**.*.jar"/>
> >     </classpath>
> >   </javac>
> >
> >
> >
> > Jan
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Matt Bertolini [mailto:viper2843@gmail.com]
> >> Gesendet: Sonntag, 17. Februar 2019 18:45
> >> An: Ant Users List
> >> Betreff: Re: Javac Run By Ant Script is Unable to Find External Jars
> >>
> >> Hi Dennis,
> >>
> >> I think you might be mixing up Eclipse concepts and Ant concepts and
> >> that might be causing some extra confusion. Based on your original
> >> email, the compiler is having issues finding your third-party
> >> dependencies. I believe Jaikiran is correct in saying that the
> >> <javac> task needs to be given some sort of classpath. The
> .classpath
> >> file is an Eclipse concept and unless there is some sort of
> >> Eclipse/Ant plugin I am not aware of, the .classpath file will have
> >> no effect on Ant’s, <javac> task. Also, I don’t believe the <javac>
> >> task has a default value for the classpath attribute. If no
> classpath
> >> or classpathref is specified then the compiler is not passed any
> classpath information.
> >>
> >> I would start by locating the folder where your third-party
> >> dependencies are and create a <path> element containing them like
> this:
> >>
> >> <path id="compile-classpath">
> >>     <fileset dir="/the/path/to/your/third/party/jars"/>
> >> </path>
> >>
> >> Once you have a path defined you can pass the classpath to the
> >> <javac> task using a refid like this:
> >>
> >> <javac srcdir="src" destdir="bin" includeantruntime="false"
> >> classpathref="compile-classpath"/>
> >>
> >> Try that and see how it goes.
> >>
> >> Matt Bertolini
> >>
> >> On Sun, Feb 17, 2019 at 10:02 AM Dennis Putnam <da...@bellsouth.net>
> >> wrote:
> >>
> >>> I apologize for being a pest but this is a problem I cannot resolve
> >> on
> >>> my own. The more I read the more confusing it gets. It seems like
> >>> there are thousands of ways to accomplish what I want but none make
> >>> any more sense than what I have. Is there no one that can help me
> >>> debug this problem or at least point me in the right direction?
> >>>
> >>> On 2/14/2019 9:42 AM, Dennis Putnam wrote:
> >>>
> >>> Hi Jaikiran,
> >>>
> >>> Thanks for the reply. I thought the classpath parameter defaulted
> to
> >>> "basedir"/.classpath. In any case I made the following change:
> >>>
> >>> <javac srcdir="src" destdir="bin" includeantruntime="false"
> >>> classpath=".classpath" />
> >>>
> >>>
> >>> Unfortunately that didn't help. The ant output is exactly the same.
> >>> FWIW here is .classpath:
> >>>
> >>> <?xml version="1.0" encoding="UTF-8"?> <classpath>
> >>>         <classpathentry including="**/*.java" kind="src"
> >>> output="target/classes" path="src">
> >>>                 <attributes>
> >>>                         <attribute name="optional" value="true"/>
> >>>                         <attribute name="maven.pomderived"
> >> value="true"/>
> >>>                 </attributes>
> >>>         </classpathentry>
> >>>         <classpathentry kind="con"
> >>>
> >>
> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.
> >> debug.ui.launcher.StandardVMType/JavaSE-1.7">
> >>>                 <attributes>
> >>>                         <attribute name="maven.pomderived"
> >> value="true"/>
> >>>                 </attributes>
> >>>         </classpathentry>
> >>>         <classpathentry kind="lib"
> >>> path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
> >>>         <classpathentry kind="con"
> >>> path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
> >>>                 <attributes>
> >>>                         <attribute name="maven.pomderived"
> >> value="true"/>
> >>>                 </attributes>
> >>>         </classpathentry>
> >>>         <classpathentry kind="output" path="target/classes"/>
> >>>
> >>> The "lib" path is correct. I am guessing that the next tag
> >> essentially
> >>> points the pom.xml so here it is in case it matters:
> >>>
> >>> <project xmlns="http://maven.apache.org/POM/4.0.0"
> >>> <http://maven.apache.org/POM/4.0.0> xmlns:xsi=
> >>> "http://www.w3.org/2001/XMLSchema-instance"
> >>> <http://www.w3.org/2001/XMLSchema-instance>
> >>> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> >>> http://maven.apache.org/xsd/maven-4.0.0.xsd"
> >>>
> <http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-
> >> 4.
> >>> 0.0.xsd>
> >>>   <modelVersion>4.0.0</modelVersion>
> >>>   <groupId>KCBSEvents</groupId>
> >>>   <artifactId>KCBSEvents</artifactId>
> >>>   <version>0.0.1-SNAPSHOT</version>
> >>>   <build>
> >>>     <sourceDirectory>src</sourceDirectory>
> >>>     <resources>
> >>>       <resource>
> >>>         <directory>src</directory>
> >>>         <excludes>
> >>>           <exclude>**/*.java</exclude>
> >>>         </excludes>
> >>>       </resource>
> >>>     </resources>
> >>>     <plugins>
> >>>       <plugin>
> >>>         <artifactId>maven-compiler-plugin</artifactId>
> >>>         <version>3.7.0</version>
> >>>         <configuration>
> >>>           <source>1.7</source>
> >>>           <target>1.7</target>
> >>>         </configuration>
> >>>       </plugin>
> >>>     </plugins>
> >>>   </build>
> >>>    <dependencies>
> >>>         <dependency>
> >>>                 <groupId>org.apache.httpcomponents</groupId>
> >>>                 <artifactId>httpclient</artifactId>
> >>>                 <version>4.5.6</version>
> >>>         </dependency>
> >>>         <dependency>
> >>>                 <groupId>commons-io</groupId>
> >>>                 <artifactId>commons-io</artifactId>
> >>>                 <version>2.5</version>
> >>>         </dependency>
> >>>         <dependency>
> >>>                 <groupId>org.apache.httpcomponents</groupId>
> >>>                 <artifactId>httpcore</artifactId>
> >>>                 <version>4.4.10</version>
> >>>         </dependency>
> >>>         <dependency>
> >>>                 <groupId>commons-codec</groupId>
> >>>                 <artifactId>commons-codec</artifactId>
> >>>                 <version>1.10</version>
> >>>         </dependency>
> >>>         <dependency>
> >>>                 <groupId>commons-logging</groupId>
> >>>                 <artifactId>commons-logging</artifactId>
> >>>                 <version>1.2</version>
> >>>         </dependency>
> >>>    </dependencies>
> >>>
> >>> Presumably the maven libraries are found from the zipfilesets in
> the
> >>> ant script.
> >>>
> >>> On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
> >>>
> >>> Hi Dennis,
> >>>
> >>> On 13/02/19 11:56 PM, Dennis Putnam wrote:
> >>>
> >>> <javac srcdir="src" destdir="bin" includeantruntime="false" />
> >>>
> >>> I don't see any classpath being passed to the javac task in your
> >> build
> >>> script. You should be passing a classpath containing your jars that
> >>> are required to compile the source. There's more than one way to do
> >> that.
> >>> The javac task manual has more details about
> >>> ithttps://ant.apache.org/manual/Tasks/javac.html
> >>>
> >>>
> >>> -Jaikiran
> >>>
> >>>
> >>> -------------------------------------------------------------------
> -
> >>> - 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
> >
> >
> 



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


Re: AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Jan,

Thanks. Things are starting to come together in my head. If I
understand, ant doesn't need the Eclipse .classpath at all and only the
classpath suggested by Matt is used by ant, right?

On 2/18/2019 8:11 AM, Jan Matèrne (jhm) wrote:
> Matt is correct: you are mixing Eclipse and Ant definitions.
> So here some points by me:
> * There is no default behaviour of <javac>. You have to specify the paths the compiler should use by yourself.
> * <javac ... classpath=".classpath"/> means, that the file or directory ".classpath" should be used for classpath. But the .classpath-file is not a jar file, it is a xml file.
> * I try to "translate" the .classpath:
>
> Eclipse: <classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
> Ant:     <javac src="src" dest="target/classes" includes=**/*.java"/>
>
> Eclipse: <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
> Ant:     not used (include current Java runtime)
>
> Eclipse: <classpathentry kind="lib" path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
> Ant:     <javac><classpath><path entry="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/></classpath></javac>
>   ore more generic
>          <javac><classpath><fileset dir="lib" includes="**.*.jar"/></classpath></javac>
>
> Eclipse: <classpathentry kind="output" path="target/classes"/>
> Ant:     not used (I think this controlls the "export behaviour" for inter-project dependencies)
>
> So combined (and tuned):
>   <property name="build.classes" value="target/classes"/>
>   <mkdir dir="${build.classes}"/>
>   <javac src="src" dest="${build.classes}">  <!-- includes not required -->
>     <classpath>
>       <fileset dir="lib" includes="**.*.jar"/>
>     </classpath>
>   </javac>
>
>
>
> Jan
>
>> -----Ursprüngliche Nachricht-----
>> Von: Matt Bertolini [mailto:viper2843@gmail.com]
>> Gesendet: Sonntag, 17. Februar 2019 18:45
>> An: Ant Users List
>> Betreff: Re: Javac Run By Ant Script is Unable to Find External Jars
>>
>> Hi Dennis,
>>
>> I think you might be mixing up Eclipse concepts and Ant concepts and
>> that might be causing some extra confusion. Based on your original
>> email, the compiler is having issues finding your third-party
>> dependencies. I believe Jaikiran is correct in saying that the <javac>
>> task needs to be given some sort of classpath. The .classpath file is
>> an Eclipse concept and unless there is some sort of Eclipse/Ant plugin
>> I am not aware of, the .classpath file will have no effect on Ant’s,
>> <javac> task. Also, I don’t believe the <javac> task has a default
>> value for the classpath attribute. If no classpath or classpathref is
>> specified then the compiler is not passed any classpath information.
>>
>> I would start by locating the folder where your third-party
>> dependencies are and create a <path> element containing them like this:
>>
>> <path id="compile-classpath">
>>     <fileset dir="/the/path/to/your/third/party/jars"/>
>> </path>
>>
>> Once you have a path defined you can pass the classpath to the <javac>
>> task using a refid like this:
>>
>> <javac srcdir="src" destdir="bin" includeantruntime="false"
>> classpathref="compile-classpath"/>
>>
>> Try that and see how it goes.
>>
>> Matt Bertolini
>>
>> On Sun, Feb 17, 2019 at 10:02 AM Dennis Putnam <da...@bellsouth.net>
>> wrote:
>>
>>> I apologize for being a pest but this is a problem I cannot resolve
>> on
>>> my own. The more I read the more confusing it gets. It seems like
>>> there are thousands of ways to accomplish what I want but none make
>>> any more sense than what I have. Is there no one that can help me
>>> debug this problem or at least point me in the right direction?
>>>
>>> On 2/14/2019 9:42 AM, Dennis Putnam wrote:
>>>
>>> Hi Jaikiran,
>>>
>>> Thanks for the reply. I thought the classpath parameter defaulted to
>>> "basedir"/.classpath. In any case I made the following change:
>>>
>>> <javac srcdir="src" destdir="bin" includeantruntime="false"
>>> classpath=".classpath" />
>>>
>>>
>>> Unfortunately that didn't help. The ant output is exactly the same.
>>> FWIW here is .classpath:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?> <classpath>
>>>         <classpathentry including="**/*.java" kind="src"
>>> output="target/classes" path="src">
>>>                 <attributes>
>>>                         <attribute name="optional" value="true"/>
>>>                         <attribute name="maven.pomderived"
>> value="true"/>
>>>                 </attributes>
>>>         </classpathentry>
>>>         <classpathentry kind="con"
>>>
>> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.
>> debug.ui.launcher.StandardVMType/JavaSE-1.7">
>>>                 <attributes>
>>>                         <attribute name="maven.pomderived"
>> value="true"/>
>>>                 </attributes>
>>>         </classpathentry>
>>>         <classpathentry kind="lib"
>>> path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
>>>         <classpathentry kind="con"
>>> path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
>>>                 <attributes>
>>>                         <attribute name="maven.pomderived"
>> value="true"/>
>>>                 </attributes>
>>>         </classpathentry>
>>>         <classpathentry kind="output" path="target/classes"/>
>>>
>>> The "lib" path is correct. I am guessing that the next tag
>> essentially
>>> points the pom.xml so here it is in case it matters:
>>>
>>> <project xmlns="http://maven.apache.org/POM/4.0.0"
>>> <http://maven.apache.org/POM/4.0.0> xmlns:xsi=
>>> "http://www.w3.org/2001/XMLSchema-instance"
>>> <http://www.w3.org/2001/XMLSchema-instance>
>>> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
>>> http://maven.apache.org/xsd/maven-4.0.0.xsd"
>>> <http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-
>> 4.
>>> 0.0.xsd>
>>>   <modelVersion>4.0.0</modelVersion>
>>>   <groupId>KCBSEvents</groupId>
>>>   <artifactId>KCBSEvents</artifactId>
>>>   <version>0.0.1-SNAPSHOT</version>
>>>   <build>
>>>     <sourceDirectory>src</sourceDirectory>
>>>     <resources>
>>>       <resource>
>>>         <directory>src</directory>
>>>         <excludes>
>>>           <exclude>**/*.java</exclude>
>>>         </excludes>
>>>       </resource>
>>>     </resources>
>>>     <plugins>
>>>       <plugin>
>>>         <artifactId>maven-compiler-plugin</artifactId>
>>>         <version>3.7.0</version>
>>>         <configuration>
>>>           <source>1.7</source>
>>>           <target>1.7</target>
>>>         </configuration>
>>>       </plugin>
>>>     </plugins>
>>>   </build>
>>>    <dependencies>
>>>         <dependency>
>>>                 <groupId>org.apache.httpcomponents</groupId>
>>>                 <artifactId>httpclient</artifactId>
>>>                 <version>4.5.6</version>
>>>         </dependency>
>>>         <dependency>
>>>                 <groupId>commons-io</groupId>
>>>                 <artifactId>commons-io</artifactId>
>>>                 <version>2.5</version>
>>>         </dependency>
>>>         <dependency>
>>>                 <groupId>org.apache.httpcomponents</groupId>
>>>                 <artifactId>httpcore</artifactId>
>>>                 <version>4.4.10</version>
>>>         </dependency>
>>>         <dependency>
>>>                 <groupId>commons-codec</groupId>
>>>                 <artifactId>commons-codec</artifactId>
>>>                 <version>1.10</version>
>>>         </dependency>
>>>         <dependency>
>>>                 <groupId>commons-logging</groupId>
>>>                 <artifactId>commons-logging</artifactId>
>>>                 <version>1.2</version>
>>>         </dependency>
>>>    </dependencies>
>>>
>>> Presumably the maven libraries are found from the zipfilesets in the
>>> ant script.
>>>
>>> On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
>>>
>>> Hi Dennis,
>>>
>>> On 13/02/19 11:56 PM, Dennis Putnam wrote:
>>>
>>> <javac srcdir="src" destdir="bin" includeantruntime="false" />
>>>
>>> I don't see any classpath being passed to the javac task in your
>> build
>>> script. You should be passing a classpath containing your jars that
>>> are required to compile the source. There's more than one way to do
>> that.
>>> The javac task manual has more details about
>>> ithttps://ant.apache.org/manual/Tasks/javac.html
>>>
>>>
>>> -Jaikiran
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>



AW: Javac Run By Ant Script is Unable to Find External Jars

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Matt is correct: you are mixing Eclipse and Ant definitions.
So here some points by me:
* There is no default behaviour of <javac>. You have to specify the paths the compiler should use by yourself.
* <javac ... classpath=".classpath"/> means, that the file or directory ".classpath" should be used for classpath. But the .classpath-file is not a jar file, it is a xml file.
* I try to "translate" the .classpath:

Eclipse: <classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
Ant:     <javac src="src" dest="target/classes" includes=**/*.java"/>

Eclipse: <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
Ant:     not used (include current Java runtime)

Eclipse: <classpathentry kind="lib" path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
Ant:     <javac><classpath><path entry="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/></classpath></javac>
  ore more generic
         <javac><classpath><fileset dir="lib" includes="**.*.jar"/></classpath></javac>

Eclipse: <classpathentry kind="output" path="target/classes"/>
Ant:     not used (I think this controlls the "export behaviour" for inter-project dependencies)

So combined (and tuned):
  <property name="build.classes" value="target/classes"/>
  <mkdir dir="${build.classes}"/>
  <javac src="src" dest="${build.classes}">  <!-- includes not required -->
    <classpath>
      <fileset dir="lib" includes="**.*.jar"/>
    </classpath>
  </javac>



Jan

> -----Ursprüngliche Nachricht-----
> Von: Matt Bertolini [mailto:viper2843@gmail.com]
> Gesendet: Sonntag, 17. Februar 2019 18:45
> An: Ant Users List
> Betreff: Re: Javac Run By Ant Script is Unable to Find External Jars
> 
> Hi Dennis,
> 
> I think you might be mixing up Eclipse concepts and Ant concepts and
> that might be causing some extra confusion. Based on your original
> email, the compiler is having issues finding your third-party
> dependencies. I believe Jaikiran is correct in saying that the <javac>
> task needs to be given some sort of classpath. The .classpath file is
> an Eclipse concept and unless there is some sort of Eclipse/Ant plugin
> I am not aware of, the .classpath file will have no effect on Ant’s,
> <javac> task. Also, I don’t believe the <javac> task has a default
> value for the classpath attribute. If no classpath or classpathref is
> specified then the compiler is not passed any classpath information.
> 
> I would start by locating the folder where your third-party
> dependencies are and create a <path> element containing them like this:
> 
> <path id="compile-classpath">
>     <fileset dir="/the/path/to/your/third/party/jars"/>
> </path>
> 
> Once you have a path defined you can pass the classpath to the <javac>
> task using a refid like this:
> 
> <javac srcdir="src" destdir="bin" includeantruntime="false"
> classpathref="compile-classpath"/>
> 
> Try that and see how it goes.
> 
> Matt Bertolini
> 
> On Sun, Feb 17, 2019 at 10:02 AM Dennis Putnam <da...@bellsouth.net>
> wrote:
> 
> > I apologize for being a pest but this is a problem I cannot resolve
> on
> > my own. The more I read the more confusing it gets. It seems like
> > there are thousands of ways to accomplish what I want but none make
> > any more sense than what I have. Is there no one that can help me
> > debug this problem or at least point me in the right direction?
> >
> > On 2/14/2019 9:42 AM, Dennis Putnam wrote:
> >
> > Hi Jaikiran,
> >
> > Thanks for the reply. I thought the classpath parameter defaulted to
> > "basedir"/.classpath. In any case I made the following change:
> >
> > <javac srcdir="src" destdir="bin" includeantruntime="false"
> > classpath=".classpath" />
> >
> >
> > Unfortunately that didn't help. The ant output is exactly the same.
> > FWIW here is .classpath:
> >
> > <?xml version="1.0" encoding="UTF-8"?> <classpath>
> >         <classpathentry including="**/*.java" kind="src"
> > output="target/classes" path="src">
> >                 <attributes>
> >                         <attribute name="optional" value="true"/>
> >                         <attribute name="maven.pomderived"
> value="true"/>
> >                 </attributes>
> >         </classpathentry>
> >         <classpathentry kind="con"
> >
> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.
> debug.ui.launcher.StandardVMType/JavaSE-1.7">
> >                 <attributes>
> >                         <attribute name="maven.pomderived"
> value="true"/>
> >                 </attributes>
> >         </classpathentry>
> >         <classpathentry kind="lib"
> > path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
> >         <classpathentry kind="con"
> > path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
> >                 <attributes>
> >                         <attribute name="maven.pomderived"
> value="true"/>
> >                 </attributes>
> >         </classpathentry>
> >         <classpathentry kind="output" path="target/classes"/>
> >
> > The "lib" path is correct. I am guessing that the next tag
> essentially
> > points the pom.xml so here it is in case it matters:
> >
> > <project xmlns="http://maven.apache.org/POM/4.0.0"
> > <http://maven.apache.org/POM/4.0.0> xmlns:xsi=
> > "http://www.w3.org/2001/XMLSchema-instance"
> > <http://www.w3.org/2001/XMLSchema-instance>
> > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> > http://maven.apache.org/xsd/maven-4.0.0.xsd"
> > <http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-
> 4.
> > 0.0.xsd>
> > >
> >   <modelVersion>4.0.0</modelVersion>
> >   <groupId>KCBSEvents</groupId>
> >   <artifactId>KCBSEvents</artifactId>
> >   <version>0.0.1-SNAPSHOT</version>
> >   <build>
> >     <sourceDirectory>src</sourceDirectory>
> >     <resources>
> >       <resource>
> >         <directory>src</directory>
> >         <excludes>
> >           <exclude>**/*.java</exclude>
> >         </excludes>
> >       </resource>
> >     </resources>
> >     <plugins>
> >       <plugin>
> >         <artifactId>maven-compiler-plugin</artifactId>
> >         <version>3.7.0</version>
> >         <configuration>
> >           <source>1.7</source>
> >           <target>1.7</target>
> >         </configuration>
> >       </plugin>
> >     </plugins>
> >   </build>
> >    <dependencies>
> >         <dependency>
> >                 <groupId>org.apache.httpcomponents</groupId>
> >                 <artifactId>httpclient</artifactId>
> >                 <version>4.5.6</version>
> >         </dependency>
> >         <dependency>
> >                 <groupId>commons-io</groupId>
> >                 <artifactId>commons-io</artifactId>
> >                 <version>2.5</version>
> >         </dependency>
> >         <dependency>
> >                 <groupId>org.apache.httpcomponents</groupId>
> >                 <artifactId>httpcore</artifactId>
> >                 <version>4.4.10</version>
> >         </dependency>
> >         <dependency>
> >                 <groupId>commons-codec</groupId>
> >                 <artifactId>commons-codec</artifactId>
> >                 <version>1.10</version>
> >         </dependency>
> >         <dependency>
> >                 <groupId>commons-logging</groupId>
> >                 <artifactId>commons-logging</artifactId>
> >                 <version>1.2</version>
> >         </dependency>
> >    </dependencies>
> >
> > Presumably the maven libraries are found from the zipfilesets in the
> > ant script.
> >
> > On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
> >
> > Hi Dennis,
> >
> > On 13/02/19 11:56 PM, Dennis Putnam wrote:
> >
> > <javac srcdir="src" destdir="bin" includeantruntime="false" />
> >
> > I don't see any classpath being passed to the javac task in your
> build
> > script. You should be passing a classpath containing your jars that
> > are required to compile the source. There's more than one way to do
> that.
> > The javac task manual has more details about
> > ithttps://ant.apache.org/manual/Tasks/javac.html
> >
> >
> > -Jaikiran
> >
> >
> > ---------------------------------------------------------------------
> > 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


Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Matt Bertolini <vi...@gmail.com>.
Hi Dennis,

I think you might be mixing up Eclipse concepts and Ant concepts and that
might be causing some extra confusion. Based on your original email, the
compiler is having issues finding your third-party dependencies. I believe
Jaikiran is correct in saying that the <javac> task needs to be given some
sort of classpath. The .classpath file is an Eclipse concept and unless
there is some sort of Eclipse/Ant plugin I am not aware of, the .classpath
file will have no effect on Ant’s, <javac> task. Also, I don’t believe the
<javac> task has a default value for the classpath attribute. If no
classpath or classpathref is specified then the compiler is not passed any
classpath information.

I would start by locating the folder where your third-party dependencies
are and create a <path> element containing them like this:

<path id="compile-classpath">
    <fileset dir="/the/path/to/your/third/party/jars"/>
</path>

Once you have a path defined you can pass the classpath to the <javac> task
using a refid like this:

<javac srcdir="src" destdir="bin" includeantruntime="false"
classpathref="compile-classpath"/>

Try that and see how it goes.

Matt Bertolini

On Sun, Feb 17, 2019 at 10:02 AM Dennis Putnam <da...@bellsouth.net> wrote:

> I apologize for being a pest but this is a problem I cannot resolve on my
> own. The more I read the more confusing it gets. It seems like there are
> thousands of ways to accomplish what I want but none make any more sense
> than what I have. Is there no one that can help me debug this problem or at
> least point me in the right direction?
>
> On 2/14/2019 9:42 AM, Dennis Putnam wrote:
>
> Hi Jaikiran,
>
> Thanks for the reply. I thought the classpath parameter defaulted to
> "basedir"/.classpath. In any case I made the following change:
>
> <javac srcdir="src" destdir="bin" includeantruntime="false" classpath=".classpath" />
>
>
> Unfortunately that didn't help. The ant output is exactly the same. FWIW
> here is .classpath:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <classpath>
>         <classpathentry including="**/*.java" kind="src"
> output="target/classes" path="src">
>                 <attributes>
>                         <attribute name="optional" value="true"/>
>                         <attribute name="maven.pomderived" value="true"/>
>                 </attributes>
>         </classpathentry>
>         <classpathentry kind="con"
> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
>                 <attributes>
>                         <attribute name="maven.pomderived" value="true"/>
>                 </attributes>
>         </classpathentry>
>         <classpathentry kind="lib"
> path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
>         <classpathentry kind="con"
> path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
>                 <attributes>
>                         <attribute name="maven.pomderived" value="true"/>
>                 </attributes>
>         </classpathentry>
>         <classpathentry kind="output" path="target/classes"/>
>
> The "lib" path is correct. I am guessing that the next tag essentially
> points the pom.xml so here it is in case it matters:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> <http://maven.apache.org/POM/4.0.0> xmlns:xsi=
> "http://www.w3.org/2001/XMLSchema-instance"
> <http://www.w3.org/2001/XMLSchema-instance> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd"
> <http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd>
> >
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>KCBSEvents</groupId>
>   <artifactId>KCBSEvents</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <build>
>     <sourceDirectory>src</sourceDirectory>
>     <resources>
>       <resource>
>         <directory>src</directory>
>         <excludes>
>           <exclude>**/*.java</exclude>
>         </excludes>
>       </resource>
>     </resources>
>     <plugins>
>       <plugin>
>         <artifactId>maven-compiler-plugin</artifactId>
>         <version>3.7.0</version>
>         <configuration>
>           <source>1.7</source>
>           <target>1.7</target>
>         </configuration>
>       </plugin>
>     </plugins>
>   </build>
>    <dependencies>
>         <dependency>
>                 <groupId>org.apache.httpcomponents</groupId>
>                 <artifactId>httpclient</artifactId>
>                 <version>4.5.6</version>
>         </dependency>
>         <dependency>
>                 <groupId>commons-io</groupId>
>                 <artifactId>commons-io</artifactId>
>                 <version>2.5</version>
>         </dependency>
>         <dependency>
>                 <groupId>org.apache.httpcomponents</groupId>
>                 <artifactId>httpcore</artifactId>
>                 <version>4.4.10</version>
>         </dependency>
>         <dependency>
>                 <groupId>commons-codec</groupId>
>                 <artifactId>commons-codec</artifactId>
>                 <version>1.10</version>
>         </dependency>
>         <dependency>
>                 <groupId>commons-logging</groupId>
>                 <artifactId>commons-logging</artifactId>
>                 <version>1.2</version>
>         </dependency>
>    </dependencies>
>
> Presumably the maven libraries are found from the zipfilesets in the ant
> script.
>
> On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
>
> Hi Dennis,
>
> On 13/02/19 11:56 PM, Dennis Putnam wrote:
>
> <javac srcdir="src" destdir="bin" includeantruntime="false" />
>
> I don't see any classpath being passed to the javac task in your build
> script. You should be passing a classpath containing your jars that are
> required to compile the source. There's more than one way to do that.
> The javac task manual has more details about ithttps://ant.apache.org/manual/Tasks/javac.html
>
>
> -Jaikiran
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>

Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
I apologize for being a pest but this is a problem I cannot resolve on
my own. The more I read the more confusing it gets. It seems like there
are thousands of ways to accomplish what I want but none make any more
sense than what I have. Is there no one that can help me debug this
problem or at least point me in the right direction?

On 2/14/2019 9:42 AM, Dennis Putnam wrote:
> Hi Jaikiran,
>
> Thanks for the reply. I thought the classpath parameter defaulted to
> "basedir"/.classpath. In any case I made the following change:
>
> <javac srcdir="src" destdir="bin" includeantruntime="false" classpath=".classpath" />
>
> Unfortunately that didn't help. The ant output is exactly the same.
> FWIW here is .classpath:
>
>     <?xml version="1.0" encoding="UTF-8"?>
>     <classpath>
>             <classpathentry including="**/*.java" kind="src"
>     output="target/classes" path="src">
>                     <attributes>
>                             <attribute name="optional" value="true"/>
>                             <attribute name="maven.pomderived"
>     value="true"/>
>                     </attributes>
>             </classpathentry>
>             <classpathentry kind="con"
>     path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
>                     <attributes>
>                             <attribute name="maven.pomderived"
>     value="true"/>
>                     </attributes>
>             </classpathentry>
>             <classpathentry kind="lib"
>     path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
>             <classpathentry kind="con"
>     path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
>                     <attributes>
>                             <attribute name="maven.pomderived"
>     value="true"/>
>                     </attributes>
>             </classpathentry>
>             <classpathentry kind="output" path="target/classes"/>
>
> The "lib" path is correct. I am guessing that the next tag essentially
> points the pom.xml so here it is in case it matters:
>
>     <project xmlns="http://maven.apache.org/POM/4.0.0"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
>     http://maven.apache.org/xsd/maven-4.0.0.xsd">
>       <modelVersion>4.0.0</modelVersion>
>       <groupId>KCBSEvents</groupId>
>       <artifactId>KCBSEvents</artifactId>
>       <version>0.0.1-SNAPSHOT</version>
>       <build>
>         <sourceDirectory>src</sourceDirectory>
>         <resources>
>           <resource>
>             <directory>src</directory>
>             <excludes>
>               <exclude>**/*.java</exclude>
>             </excludes>
>           </resource>
>         </resources>
>         <plugins>
>           <plugin>
>             <artifactId>maven-compiler-plugin</artifactId>
>             <version>3.7.0</version>
>             <configuration>
>               <source>1.7</source>
>               <target>1.7</target>
>             </configuration>
>           </plugin>
>         </plugins>
>       </build>
>        <dependencies>
>             <dependency>
>                     <groupId>org.apache.httpcomponents</groupId>
>                     <artifactId>httpclient</artifactId>
>                     <version>4.5.6</version>
>             </dependency>
>             <dependency>
>                     <groupId>commons-io</groupId>
>                     <artifactId>commons-io</artifactId>
>                     <version>2.5</version>
>             </dependency>
>             <dependency>
>                     <groupId>org.apache.httpcomponents</groupId>
>                     <artifactId>httpcore</artifactId>
>                     <version>4.4.10</version>
>             </dependency>
>             <dependency>
>                     <groupId>commons-codec</groupId>
>                     <artifactId>commons-codec</artifactId>
>                     <version>1.10</version>
>             </dependency>
>             <dependency>
>                     <groupId>commons-logging</groupId>
>                     <artifactId>commons-logging</artifactId>
>                     <version>1.2</version>
>             </dependency>
>        </dependencies>
>
> Presumably the maven libraries are found from the zipfilesets in the
> ant script.
>
> On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
>> Hi Dennis,
>>
>> On 13/02/19 11:56 PM, Dennis Putnam wrote:
>>> <javac srcdir="src" destdir="bin" includeantruntime="false" />
>> I don't see any classpath being passed to the javac task in your build
>> script. You should be passing a classpath containing your jars that are
>> required to compile the source. There's more than one way to do that.
>> The javac task manual has more details about it
>> https://ant.apache.org/manual/Tasks/javac.html
>>
>>
>> -Jaikiran
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>


Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Dennis Putnam <da...@bellsouth.net>.
Hi Jaikiran,

Thanks for the reply. I thought the classpath parameter defaulted to
"basedir"/.classpath. In any case I made the following change:

<javac srcdir="src" destdir="bin" includeantruntime="false" classpath=".classpath" />


Unfortunately that didn't help. The ant output is exactly the same. FWIW
here is .classpath:

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
            <classpathentry including="**/*.java" kind="src"
    output="target/classes" path="src">
                    <attributes>
                            <attribute name="optional" value="true"/>
                            <attribute name="maven.pomderived"
    value="true"/>
                    </attributes>
            </classpathentry>
            <classpathentry kind="con"
    path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
                    <attributes>
                            <attribute name="maven.pomderived"
    value="true"/>
                    </attributes>
            </classpathentry>
            <classpathentry kind="lib"
    path="/lib/java-ext/json-simple-1.1.1/json-simple-1.1.1.jar"/>
            <classpathentry kind="con"
    path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
                    <attributes>
                            <attribute name="maven.pomderived"
    value="true"/>
                    </attributes>
            </classpathentry>
            <classpathentry kind="output" path="target/classes"/>

The "lib" path is correct. I am guessing that the next tag essentially
points the pom.xml so here it is in case it matters:

    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>KCBSEvents</groupId>
      <artifactId>KCBSEvents</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
          <resource>
            <directory>src</directory>
            <excludes>
              <exclude>**/*.java</exclude>
            </excludes>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
       <dependencies>
            <dependency>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                    <version>4.5.6</version>
            </dependency>
            <dependency>
                    <groupId>commons-io</groupId>
                    <artifactId>commons-io</artifactId>
                    <version>2.5</version>
            </dependency>
            <dependency>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpcore</artifactId>
                    <version>4.4.10</version>
            </dependency>
            <dependency>
                    <groupId>commons-codec</groupId>
                    <artifactId>commons-codec</artifactId>
                    <version>1.10</version>
            </dependency>
            <dependency>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                    <version>1.2</version>
            </dependency>
       </dependencies>

Presumably the maven libraries are found from the zipfilesets in the ant
script.

On 2/14/2019 8:55 AM, Jaikiran Pai wrote:
> Hi Dennis,
>
> On 13/02/19 11:56 PM, Dennis Putnam wrote:
>> <javac srcdir="src" destdir="bin" includeantruntime="false" />
>
> I don't see any classpath being passed to the javac task in your build
> script. You should be passing a classpath containing your jars that are
> required to compile the source. There's more than one way to do that.
> The javac task manual has more details about it
> https://ant.apache.org/manual/Tasks/javac.html
>
>
> -Jaikiran
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


Re: Javac Run By Ant Script is Unable to Find External Jars

Posted by Jaikiran Pai <ja...@apache.org>.
Hi Dennis,

On 13/02/19 11:56 PM, Dennis Putnam wrote:
> <javac srcdir="src" destdir="bin" includeantruntime="false" />


I don't see any classpath being passed to the javac task in your build
script. You should be passing a classpath containing your jars that are
required to compile the source. There's more than one way to do that.
The javac task manual has more details about it
https://ant.apache.org/manual/Tasks/javac.html


-Jaikiran


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