I am having some trouble (annoyance really) with ANT editor in Eclipse where it is displaying me a warning "Reference build.classpath not found." on the following block:
<target name="generate" depends="..., mvn-depends">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="build.classpath" />
</taskdef>
...
</target>
With mvn-depends target looking like this:
<target name="mvn-depends">
<artifact:dependencies pathId="build.classpath">
<pom refid="my.pom" />
</artifact:dependencies>
</target>
The rest of the references to build.classpath in the build file are not throwing any warnings and the and build runs just fine without any errors, so it does not seem to be amounting to much.
Still, ignoring a warning makes me feel sort of dirty every time I have to edit that file. Specifically, not knowing if this is a bug in Eclipse ant build file validation code or a potential problem in the way the build file has been structured, that Eclipse has identified.
If anyone has any ideas on why this warning is being shown and whether it is safe to ignore or maybe even disable from preferences and would care to share that knowledge, I would definitely be grateful for the knowledge.
Edit:
As requested, here is an example of a reference to build.classpath that does not cause any warnings:
<javac deprecation="off" debug="on" source="1.7" target="1.7" encoding="UTF-8"
includeantruntime="false" memoryMaximumSize="512M" fork="true">
<classpath refid="build.classpath" />
</javac>
As the editor could recognize refids and other elements that Ant specifies, I guess that the editor does something similar to Ant's build file parsing process.
That is, parse this ant build file into a Project object, and references in <taskdef> may be checked, while <javac> may not.
Since the build.classpath is set during runtime and it is set by something other than things like <classpath>, Eclipse may not find it.
I don't have strong prove about this. But something can be done to make us know more.
First, copy the <javac> to the same target where the warned
<taskdef> exists, to see if the <javac> gets a warning;
Then, copy the <taskdef> to the same target where the presetdefed
<javac> exists, to see if the <taskdef> still gets a warning;
Third, in target "generate", comment out the <taskdef> part, and
check if the <xjc ... /> call gets a warning.
For the first one, I expect "NO", while for the other two, I expect "YES". Otherwise, my guess is wrong.
And it makes sense that it is just a warning -- things Eclipse can't find in editing time could exist during runtime.
Make sure you have given the path element location correctly as bellow.
<property name="dependencyfinder.home" value="C:/DependencyFinder"/>
<path id="dependencyfinder">
<pathelement location="${dependencyfinder.home}/lib/aaa.jar"/>
</path>
<taskdef classname="com.sun.tools.xjc.XJCTask">
<classpath refid="dependencyfinder"/>
</taskdef>
Note: DependencyFinder has a folder lib and lib has aaa.jar
Please check the bellow link for more information
Click here
Related
I am running find bugs in ant and am trying to set everything (attributes, options, etc) in my ant build.xml to the most sensitive settings for finding bugs. From reading the documentation and looking at example here is what I concluded will be the most sensitive settings for if a bug is ran into. If it is not please let me know any attribute, options, etc that needed to be added or changed to find all the bugs that may be in my code.
<target name="findbugs" depends="jar">
<findbugs home="/home/me/Desktop/findbugs"
output="html"
outputFile="bc.html"
effort="max"
reportLevel="low"
workHard="true"
debug="true">
<auxClasspath path="../foo/bin"/>
<auxClasspath path="../bar/bin"/>
<sourcePath path="../foo2/src" />
<class location="bin/"/>
</findbugs>
</target>
No need for workHard="true" since you already have effort='max'. They're just synonyms of each other. Otherwise, it looks like you have it.
There are includeFilter and excludeFilter, but if you don't list either of those, you get all bugs.
I am hoping someone has experienced this issue and can maybe shed some light.
I have an xml schema and an ant build file. The output .java files differ when I run ant on Windows versus Mac, even if I am using the same jaxb-xjc.jar to do the xml-compiling. The Windows side is naming the "getter" methods for attributes as "getX". The Mac side wants to name them "isX". Anyone experience anything like this before and/or have a solution? This is consistent between Windows Vista & 7 doing this the one way and Mac OSX 10.6 & 10.7 (untested on Mac OSX 10.8) doing it the other.
----edit----
I'll attach some of the code from the ant build.xml file.
Telling it what the xjc is.
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="classpath"/>
</taskdef>
Here is the 'actual' compiling:
Compiling the automaton schema
<echo>Compiling old automaton schema</echo>
<xjc schema="${oldxml-schema}" destdir="${src.dir}" package="${oldxml.package}">
<produces dir="${oldxml-gen.dir}" includes="**/*.java"/>
</xjc>
<echo>Compiling the plugin schema</echo>
<mkdir dir="${plugin-gen.dir}" />
<xjc schema="${plugin-schema}" destdir="${src.dir}" package="${plugin.package}">
<produces dir="${plugin-gen.dir}" includes="**/*.java"/>
</xjc>
<echo>Compiling the pluginDesumaSide schema</echo>
<mkdir dir="${pluginDesumaSide-gen.dir}" />
<xjc schema="${pluginDesumaSide-schema}" destdir="${src.dir}" package="${pluginDesumaSide.package}">
<produces dir="${pluginDesumaSide-gen.dir}" includes="**/*.java"/>
</xjc>
</target>
All targets (by that I mean anything mentioned like ${}) are defined and every links and compiles right except for Mac naming the 'getter' methods as 'is' methods for variables. They are boolean attributes that do have defaults if non-specified.
From the responses I got I was able to google for a solution. Apparently this naming inconsistency and another (a getter returning a primitive but the setter only accepting objects) was apparent by chance for older xml-compilers due to some inconsistency in the specification.
This was fixed by going to http://jaxb.java.net/ and getting a new jaxb-impl.jar & jaxb-xjc.jar. I downloaded and ran the jaxb.jar file download and it created the needed jars.
I'm writing an ANT task that is behaving very oddly. I've tried a variety of google searches with no clear answer.
I have a compile target in ANT that calls the javac command:
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}:${unittest.src.dir}" destdir="${classes.dir}">
<classpath refid="classpath" />
<exclude name="**/plugins/**" />
<exclude name="**/outbound/**" />
</javac>
</target>
That generates no errors, but when I run ant with the -verbose and -debug tags I get the following in my logs:
[javac] package/MyClass.java added as package/MyClass.class doesn't exist
So it's not erroring out, but it is giving me this odd result (with the "doesn't exist" appended at the end). Obviously this causes later targets to fail when it tries to run the classes (in this case, my junit target).
Web searches seem to indicate that I'm either missing a java_home env variable or that there is a versioning issue somewhere along the line (this error tended to occur when the source attribute on javac was set, but I removed that and am still getting the odd result). I believe we've got those possibilities covered.
Any thoughts or advice on this would be wonderful. Thanks.
I don't know too much about ant, but I would almost guess this error message is a red herring. I think it's just reporting that MyClass.java was added to the list of files to compile, because the compiled version of the class was not found on the class path. This seems to be supported by the fact that the task does not fail.
What are the later errors you are getting?
I have a ant file that runs JUnits tests. These tests rely on a relative path to certain configuration files. I've tried to set the working directory for the batch test, but fail.
I want the working directory to be ${plugins.dir}/${name}
The JUnit part of the ant script:
<junit haltonfailure="no" printsummary="on" fork="true" showoutput="true" dir="${plugins.dir}/${name}">
<jvmarg value="-Duser.dir=${plugins.dir}/${name}"/>
<classpath>
<path refid="project.classpath"/>
<pathelement location="${plugins.dir}/${dependency}/#dot/"/>
<pathelement location="${plugins.dir}/${name}/" />
</classpath>
<formatter type="xml" />
<sysproperty key="basedir" value="${plugins.dir}/${name}"/>
<sysproperty key="dir" value="${plugins.dir}/${name}"/>
<batchtest todir="${junit.output}">
<fileset dir="${dir}">
<include name="**\*AllTests.class" />
</fileset>
</batchtest>
</junit>
I've googled and searched but the workarounds I've found have been to set the "dir", "sysproperty" or "jvmarg". As you can see I've tried them all :)
Is there a way to print the current dir in the tag? It doesnt support . That would allow me to verify if the dir is actually changed and to what.
One wildcard in this equation is that this is being run in Hudson that starts upp an eclipse process that starts antrunner. This is so we can run both junit and eclipse plugin junit tests. Shouldn't have anything to do with the problem I think.
I think you are right with setting the basedir property (see projects attributes). However, since it is a property of ANT (and not of the JVM) it is READ ONLY!
Does it effect other target if you set the basedir when calling your ant task? See Command Line reference.
ant -Dbasedir=somedir
Alternatively, span a new ant process to call your junit target. See the AntCall task or Ant task. Following examples assumes that the junit target contains your junit task. I used this task for other properties (never needed the basedir property so far.
<antcall target="junit">
<param name="basedir" value="${plugins.dir}/${name}"/>
</antcall>
<ant dir="${plugins.dir}/${name}" target="junit" />
I had the same scenario and in my case I saw that dir="...." is ignored if run in same jvm so I simply added fork='true' and it worked.
Quote from Apache's documentation site "dir - The directory in which to invoke the VM. Ignored if fork is disabled.". More here.
I'm using NetBeans. When I add to Ant properties (from Tools, Options, Java, Ant) work.dir=C:/MyWorkingDir/ it executes ant with the following command and changes the working dir to C:\MyWorkingDir:
ant -f D:\\workspace\\lib\\project -Dfork=true -Djavac.includes=com/myapp/MyTest.java -Dtest.includes=com/myapp/MyTest.java "-Dwork.dir=C:/MyWorkingDir/" test-single
I'm trying to get a target to build that has quite a long list of <pathelement location="${xxx}"/> and <path refid="foo.class.path"/> elements in its <path id="bar.class.path"> element (in the build.xml file). I keep getting "package com.somecompany.somepackage does not exist" errors, and I'm having a hard time chasing down these packages and making sure I've synced them from our repository.
I'm new to this team so I'm unfamiliar with the build, but I would prefer to figure this out myself if possible (so I don't bother the other very busy team members). I have very limited experience with Ant.
I think it would save me quite a bit of time if I could have Ant print out the classpath for the target I'm trying to build.
Use the pathconvert task to convert a path to a property
<path id="classpath">
....
</path>
<pathconvert property="classpathProp" refid="classpath"/>
<echo>Classpath is ${classpathProp}</echo>
Docs for pathconvert.
This is even easier with versions of Ant > 1.6
<echo>${toString:classpath}</echo>
See http://ant.apache.org/manual/using.html#pathshortcut for more information