i am facing an issue in an ant build xml during compile process. My Ant command is pretty simple:
<target name="compile" description="Compilation target">
<javac srcdir="src" destdir="JARbuild">
<compilerarg value="-Xlint:deprecation"/>
</javac>
</target>
However i always get the following error
error: cannot find symbol
private final static JSObject jso = JSObject.getWindow(JMain.getInstance());
I am able to compile my project with netbeans ide, without running into an error, since the corresponding jar file (plugin.jar) is recognized as a library. I tried to add the library to classPath by setting sth. similar to:
<classpath>
<path>
<pathelement location="C:\Program Files\Java\jre7\lib\plugin.jar" />
</path>
</classpath>
However error still occurs. Somebody got a solution?
Thanks.
Have you tried using escaped-backlashes, or unix-style seprators in your Windows path?
E.g.
<pathelement location="C:\\Program Files\\Java\\jre7\\lib\\plugin.jar"
or
<pathelement location="C:/Program Files/Java/jre7/lib/plugin.jar"
Related
Below is the code for setting class path in ant.
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="compile" depends="clean">
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
</target>
Why do we need to set classpath in ant ?
Think of ant as a framework to run your build tasks - compiling the code, running the (unit) tests, etc. In order to properly compile and execute your (test) code, java will need access to the third party libraries you may be using (e.g., JUnit for running unit tests). The classpath tells java where these JARs are located, so it can use them.
I need to add some external .jar files to my android project BUT
1) without using Eclipse or any other IDE (so no .classpath)
2) without copying them to /libs folder, i need them to stay where they are
How can i accomplish that? I know that ant should have this functionality but and cant find it. It would be great if there is something like adding "android.library.reference" to project.properties but for .jar instead of library project.
i am not sure that it will work for you but you can use this
<path id="class.path">
<fileset dir="jar_folder">
<include name="**/*.jar" />
</fileset>
</path>
and you can use it in javac command as
<javac executable="${env.JAVA_HOME}/bin/javac" encoding="utf-8" srcdir="src/" destdir="temp/" debug="on" debuglevel="lines,source,var" fork="true" memoryInitialSize="256m" memoryMaximumSize="1024m">
<classpath refid="class.path" />
</javac>
I'm trying to call Findbugs via Ant, but receiving this error:
Cannot run program "C:\Program Files (x86)\Java\jre6\bin\javaw.exe" (in
directory "H:\Users\MyName\workspace\MyProject"):
CreateProcess error=206, The filename or extension is too long
How can I fix this? o.O
I had the same problem.
I used
<fileset dir="${basedir}/build">
<include name="**/*.class"/>
</fileset>
inside findbugs target and it seems that there is too much .class files to be passed to findbug (?via command line?) because when I used
<fileset dir="${basedir}/build/com/domain/package">
<include name="**/*.class"/>
</fileset>
that had low number of classes, the error was gone.
So, I solved the problem by making one jar file and feeding it to findbugs target with
<findbugs home="${findbugs.home}">
...
<class location="${basedir}/targets/classes-to-analyze.jar"/>
</findbugs>
I think one of the effective file paths are really long when java tries to compile clases.
One worth try is to put codebase in a directory such as C:\MyProject instead of something like C:\Users\MyName\workspace\MyProject
To solve this issue you need to generate a manifestclasspath and a pathing jar.
First Generate your classpath.
<path id="javac.path">
<fileset dir="lib/" includes="**/*.jar"/>
</path>
Next Generate your manifestclasspath
<target name="generate-manifest-classpath">
<manifestclasspath property="manifest.classpath" jarfile="pathing.jar">
<classpath refid="javac.path"/>
</manifestclasspath>
<jar destfile="pathing.jar" basedir="${the location of your build classes}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
<path id="javac.classpath">
<pathelement path="pathing.jar"/>
</path>
</target>
Next Implement your Manifestclasspath
<javac srcdir="${foo.dir}" destdir="${bar.dir}"
<classpath refid="javac.classpath"/>
</javac>
This will solve the 206 error message if implemented correctly.
I had the same error on IntelliJ while starting debug mode only. To fix is I've changed:
Run > Edit Configurations > "Configuration" tab > Shorten command line
to "JAR-manifest"
I am having trouble just creating something simple, and it does not seem that any website is clear on how to do this, and honestly I think it should be simple.
I have a bunch of java files for a project. I want to compile all of them, and then run each file with specific arguments.
Basically I want the order of operations to be something like this
javac prob1.java
javac prob2.java
java prob1 parameter
java prob2 parameter
But I want that in ant (build.xml).
I can do the compile part just fine with
<project default="compile">
<target name="compile">
<javac srcdir="." />
</target>
</project>
I just can not get it to run say prob1 with an argument. I imagine this is extremely easy, but every solution I have found, does not seem to work. Also note prob1.class and prob2.class are in the same directory.
This should work:
<target name="run">
<java classname="prob1">
<classpath>
<pathelement location="."/>
</classpath>
<arg value="parameter" />
</java>
<java classname="prob2">
<classpath>
<pathelement location="."/>
</classpath>
<arg value="parameter" />
</java>
</target>
How can I get the CLASSPATH from the environment in a build.xml?
I've tried
<property environment="env"/>
<path id="classpath">
<pathelement location="${env.CLASSPATH}"/>
</path>
<target name="compile">
<javac includeantruntime="false">
<src path="${src}"/>
<classpath refid="classpath"/>
</javac>
</target>
I have a feeling this is failing because ${env.CLASSPATH} is a colon-separated list.
How then, can I get my classpath? I was surprised when ant didn't use my environment's CLASSPATH.
EDIT:
I've found a quick solution, but the preferred method is to use a separate properties file like the example here http://www.java2s.com/Code/Java/Ant/Useseparatepropertyfile.htm
Solution is, add
<property name="build.sysclasspath" value="first"/>
to the top of the build.xml
Yes, it's failing because it's a colon-separated list. In general, it's considered a bad idea to specify the class-path externally and use it within Ant. This is because running the same Ant script on different machines may yield different results. Instead, you're better of specifying the class-path from within Ant.