ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dennis Putnam <d...@bellsouth.net>
Subject Re: AW: Javac Run By Ant Script is Unable to Find External Jars
Date Thu, 28 Feb 2019 17:00:01 GMT
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
>  
>  
>  
>
>  
>
>  
>
>



Mime
View raw message