ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Matèrne (jhm) <apa...@materne.de>
Subject AW: Javac Run By Ant Script is Unable to Find External Jars
Date Mon, 18 Feb 2019 13:11:43 GMT
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 <dap1@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


Mime
View raw message