I am trying to build my Android project with Ant. I have some reference libs which I defined in build.xml like below mentioned in this question:
<target name="-pre-compile">
<!-- HACK to add the android-support-v4.jar to the classpath directly from the SDK -->
<echo>ORIGINAL jars.path : ${toString:project.all.jars.path}</echo>
<path id="project.all.jars.path.hacked">
<path path="${toString:project.all.jars.path}"/>
<path path="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
</path>
<path id="project.all.jars.path">
<path path="${toString:project.all.jars.path.hacked}"/>
</path>
<echo>HACKED jars.path : ${toString:project.all.jars.path}</echo>
</target>
I have no problem while compiling with my external jars and it builds apk properly.
My problem starts when I use an external lib having exact package similar to system package.
For example, I have some customized frameworks.jar and I have linked it to my project in the same fashion mentioned above. But ANT considers system frameworks and ignores my frameworks.jar.
This works fine in Eclipse when I order it and keep my custom frameworks.jar above system Android libs (Eclipse > Project > Right Click > Build Path > Configure Build Path > Order and Export)
Is there any way how we can define order of libraries to be consider while compiling by ANT. Like how we do it in Eclipse?
Just replace javac bootclasspath param to solve this problem.
The original bootclasspath is platform/android-xx/android.jar, and this class path has the the highest priority.
So we have to replace it with your own external jar, and replace it back after compile is finished to prevent proguard from adding platform/android-xx/android.jar to obfuscated.jar.
Code as follows:
<path id="project.org.path" >
</path>
<path id="project.org.android.jar" >
</path>
<target name="-pre-compile" >
<path id="project.org.path" >
<path path="${toString:project.all.jars.path}" />
</path>
<path id="project.org.android.jar" >
<path path="${toString:project.target.class.path}" />
</path>
<path id="project.all.jars.path.hacked" >
<path path="${toString:project.target.class.path}" />
<path path="${toString:project.all.jars.path}" />
</path>
<path id="project.all.jars.path" >
<path path="${toString:project.all.jars.path.hacked}" />
</path>
<path id="project.target.class.path" >
<path path="./framework.jar" />
</path>
</target>
<target name="-post-compile">
<path id="project.all.jars.path" >
<path path="${toString:project.org.path}" />
</path>
<path id="project.target.class.path" >
<path path="${toString:project.org.android.jar}" />
</path>
</target>
Related
I have a build.xml and I have a path for the classpath that I set to classpathref="compile.classpath" during compile:
<path id="compile.classpath">
<fileset dir="./lib">
<include name="*" />
</fileset>
</path>
The lib folder contains weblogic.jar but when i try to compile the project, i got many errors because of missing the weblogic.jar
If I modify my path to this:
<path id="compile.classpath">
<fileset dir="./lib">
<include name="*" />
</fileset>
<fileset dir="${env.WL_HOME}/wlserver/server/lib">
<include name="weblogic.jar" />
</fileset>
</path>
So I add the weblogic.jar from my local installed weblogic directory, there are no errors, and it's compiled.
I copied the weblogic.jar to my project lib folder from the local installed weblogic folder, so it must be the same weblogic.jar
What should I try? Thank you!
I would do something like this in your build.xml (probably just before you do the compilation will work).
<property name="echo.classpath" refid="compile.classpath"/>
<echo message="compileClasspath - ${echo.classpath}"/>
What you probably need to do is to be quite explicit about where your lib directory is, relative paths are tricky if you have multiple build.xml files, and nested directories and stuff.
What I have done before is to make sure that you explicitly define a property in the right place for your lib directory, and just use that rather than ./
<project basedir=".">
<target name="init">
<property name="local.lib.dir" value="${basedir}/lib">
</target>
<target name="compile" depends="init">
<path id="compile.classpath">
<fileset dir="${local.lib.dir}">
<include name="*" />
</fileset>
</path>
....
</target>
</project>
I have my jar files in Assignment2\lib folder and my build file is in Assignment2. The name of the jar file is Assignment1.jar The following is how I tried to compile my Assignment2 from build file through ant.
<project name="Assignment1" default="run" basedir=".">
<property name="classes" value="classes" />
<path id="project.class.path">
<pathelement location="src"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</path>
<path id="lib.jars">
<fileset dir="lib" includes="**/*.jar" />
</path>
......
<target name="compile" description="compaling java files with Assignment2">
<mkdir dir="build"/>
<javac srcdir="src" destdir="build" debug="on" failonerror="true">
<classpath refid="project.class.path"/>
<classpath refid="lib.jars"/>
</javac>
</target>
<Project/>
I am getting compile errors. I'm using windows. Is that the problem? Is there any way to compile?
Well,Everything looks good to me but, you can try the following to validate the same,
Check if the lib folder has all the necessary library jars required to compile you application
You can try assigning the relative path of the lib folder to a property and refer it in the classpath eg: Property lib value=".\Lib"
Try the following before you call the compile target to see the list of jars being included in the classpath
<pathconvert property="libjars" refid="lib.jars"/>
<echo>libjars is ${classpathProp}</echo>
hey guys thanx for the answers actually i found probelm. i was trying to use a jar file created by netbeans files. Apparently netbeans jar files can be used only by netbeans. at the end i made a new jar file of Assingment1 and used it. now everything is fine. Thanx again for the answers.
This is my build.xml using ant.
<?xml version="1.0" encoding="UTF-8"?>
<project name="compile" default="css.concatenate" basedir=".">
<property name="charset" value="utf-8"/>
<!-- compile LESS -->
<target name="css.concatenate">
<concat destfile="${basedir}/src/main/webapp/cons/cons.less">
<fileset dir="${basedir}/src/main/webapp/less">
<include name="*.less"/>
</fileset>
</concat>
<echo>cons is done!</echo>
</target>
<target name="lessc" depends="css.concatenate">
<echo>now in compression</echo>
<java classname="CpLess" fork="true">
<arg value="${basedir}/src/main/webapp/cons"/><!-- input folder that contains less file -->
<arg value="${basedir}/src/main/webapp/css"/><!-- output folder -->
<classpath>
<pathelement location="${basedir}/lib/commons-logging.jar"/>
<pathelement location="${basedir}/lib/js.jar"/>
<pathelement location="${basedir}/lib/lesscss-engine.jar"/>
<pathelement location="${basedir}/lib/yuicompressor.jar"/>
<pathelement location="${basedir}/lib/zkjszips.jar"/>
<pathelement location="${basedir}/lib/zkless.jar"/>
<pathelement location="${basedir}/lib/zul.jar"/> <!-- only needed if using _zkmixins.less -->
</classpath>
</java>
</target>
<target name="rename" depends="lessc">
<echo>renaming...</echo>
<rename src="${basedir}/src/main/webapp/css/cons.css.dsp" dest="${basedir}/src/main/webapp/css/core.css"/>
<delete file="${basedir}/src/main/webapp/css/cons.css.dsp.src"/>
<echo>rename done</echo>
</target>
<target name="trasition" >
<echo> in trasition </echo>
</target>
</project>
When I run this, it comes into the error like this:
Buildfile: C:\Users\di_yu\workspace\lessCompiler\build.xml
css.concatenate:
[echo] cons is done!
lessc:
[echo] now in compression
[java] Compiling... C:\Users\di_yu\workspace\lessCompiler\src\main\webapp\cons\cons.less
css.concatenate:
[echo] cons is done!
css.concatenate:
[echo] cons is done!
lessc:
[echo] now in compression
[java] Compiling... C:\Users\di_yu\workspace\lessCompiler\src\main\webapp\cons\cons.less
rename:
[echo] renaming...
[rename] DEPRECATED - The rename task is deprecated. Use move instead.
[delete] Deleting: C:\Users\di_yu\workspace\lessCompiler\src\main\webapp\css\cons.css.dsp.src
[echo] rename done
trasition:
[echo] in trasition
BUILD FAILED
Target "precompile-templates" does not exist in the project "compile".
Total time: 4 seconds
As you can see, it says "precompile-templates" target is not exist. However, I didn't call this task at all. I just delete it from my build.xml and there are no other targets related to it. How does the error come? PS: I use eclipse's run as ANT to run this build.xml.
Did you change the target you want to run after you deleted the unnecessary targets from the file? It looks to me like the run configuration is still using the old target. Use
The problem is that you created a target "precompile-templates", you subsequently deleted it ... and Eclipse is "remembering" the now-obsolete target.
SUGGESTION:
1) "File > Save all", 2) "Project > Clean project" 3) "Run As, Ant build"
See if that works!
Actually, I found out the problem. I still use the old configuration to run the build.xml. The solution is like this:
right click on the build.xml
click 'run as...' then click the external configuration tool
delete the selected launch configurations.
Para aquel que le interese
buil.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="less.compile" default="css.concatenate" basedir=".">
<!-- compile LESS -->
<target name="css.concatenate">
<concat destfile="${basedir}/WebContent/cons/index.less">
<fileset dir="${basedir}/WebContent/less/import">
<include name="*.less"/>
</fileset>
</concat>
<echo>cons is done!</echo>
</target>
<target name="css.lessc">
<java classname="CpLess" fork="true">
<arg value="${basedir}/WebContent/cons"/><!-- output folder -->
<arg value="${basedir}/WebContent/less"/><!-- output folder -->
<classpath>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/commons- logging.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/js.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/lesscss-engine-1.3.3.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/yuicompressor-2.4.7.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/zkjszips.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/zkless.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/zul.jar"/><!-- only needed if using _zkmixins.less -->
</classpath>
</java>
</target>
<target name="lessc">
<java classname="CpLess" fork="true">
<arg value="C:/WKSLuna000/PruebasZul/WebContent/lesssrc"/><!-- output folder -->
<arg value="C:/WKSLuna000/PruebasZul/WebContent/lessbuild"/><!-- output folder -->
<classpath>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/commons-logging.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/js.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/lesscss-engine-1.3.3.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/yuicompressor-2.4.7.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/zkjszips.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/zkless.jar"/>
<pathelement location="${basedir}/WebContent/WEB-INF/lib/zul.jar"/><!-- only needed if using _zkmixins.less -->
</classpath>
</java>
</target>
</project>
En la carpeta cons/
/zk/
_header.less
_zkminis.less
_skvariables.less
En la carpeta less/
/import/
0index.less
button.less
....
/zk/
_header.less
_zkminis.less
_skvariables.less
Archivo 0index.less:
#import "../bootstrap/less/variables.less";
#import "../bootstrap/less/mixins.less";
#import "zk/_header.less";
Tagging- Selenium as well just in case someone faced similar issue while creating selenium tests using Ant.
I have seen lot of questions/answers on this topic, tried all the options suggested on various forums but still my issue is not getting resolved. Basically i compile code(includes the test scripts), create JAR and run the same JAR. For some reason it does not seem to identify the libraries during run time. Same code(With tests) works fine when main() method is run from Eclipse. Here is the build.xml,
<project default="run">
<target name="clean">
<delete dir="build" />
</target>
<target name="init-classpath">
<path id="lib.classpath">
<fileset dir="./lib/">
<include name="**.jar" />
</fileset>
</path>
<pathconvert property="mf.classpath" pathsep=" ">
<path refid="lib.classpath" />
<flattenmapper />
</pathconvert>
</target>
<target name="jar" depends="clean, init-classpath">
<javac classpathref="lib.classpath" destdir="./compiled" failonerror="true" srcdir="./src" />
<mkdir dir="build/jar" />
<jar destfile="build/jar/BANC.jar" basedir="compiled">
<manifest>
<attribute name="Main-Class" value="com.portico.driver.TestDriver" />
<attribute name="Class-Path" value="${mf.classpath}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="build/jar/BANC.jar" fork="true">
</java>
</target>
</project>
Error:-Exception in thread "main" java.lang.NoClassDefFoundError: jxl/Workbook
Manifest content
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_41-b02 (Sun Microsystems Inc.)
Main-Class: com.portico.driver.TestDriver
Class-Path: activation.jar commons-lang-2.4.jar jna-3.4.0.jar jxl.jar
logging-selenium-1.2.jar mail.jar ojdbc14.jar poi-3.0.2-FINAL.jar rep
ortng-1.1.1.jar saxon-8.7.jar selenium-grid-demo-1.0.7.jar selenium-g
rid-demo-standalone-1.0.7.jar selenium-grid-hub-1.0.7.jar selenium-gr
id-hub-standalone-1.0.7.jar selenium-grid-remote-control-1.0.7.jar se
lenium-grid-remote-control-standalone-1.0.7.jar selenium-grid-tools-1
.0.7.jar selenium-grid-tools-standalone-1.0.7.jar selenium-server-1.0
.3-standalone.jar selenium-server-standalone-2.33.0.jar sikuli-script
.jar testng-6.8.jar velocity-1.7.jar
The first thing to check is, whether the problem is connected with the manifest or something else. If you can run your application with java -cp <allthejarfiles> <main-class> the problem is connected with the manifest. Keep in mind that the jar files specified in the manifest are relative to the jar file’s location. Trying to run the application with the -verbose:class option gives hint about which jar are really loaded.
Your manifest assumes the jars in the current working directory. So it would require dir attribute set to the folder where the jar exists.
Java task supports providing classpath in the arguments. Try giving the classpath in arguments.
<target name="run" depends="jar">
<java jar="build/jar/BANC.jar" fork="true" dir="build/jar" >
<classpath>
<pathelement path="${lib.classpath}"/>
</classpath>
</java>
</target>
I have faced the same issue in my project. I suggest that you should create a separate directory specially for the jar files, put all of your jars in that directory, and then point the lib address to that directory.
for example in your case say I have created a directory D:/jar_collection, where I have put all my jars physically.
<property name="lib.dir" value="D:/jar_collection"/>
<target name="setClassPath">
<path id="classpath_jars">
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
and it works fine. Please try it once.
We use Ant to build a Java web application. The application will compile and run on both Tomcat 6 and Tomcat 5.5. However, the build process is slightly different depending on which version of Tomcat you have installed: 5.5 keeps jar files that the build needs in $CATALINA_HOME/common/lib and $CATALINA_HOME/server/lib, while 6.0 keeps them all in $CATALINA_HOME/lib.
How can I set up Ant to choose the correct classpath(s) depending on a setting in build.properties? I'd be ok with even having to list the directories to be included in the classpath in a setting in build.properties, but I haven't been able to make this work.
Any suggestions?
Create 2 different path items:
<path id="path.tomcat55">
<fileset ... (tomcat5.5 files) />
</path>
<path id="path.tomcat6">
<fileset ... (tomcat6 files) />
</path>
Then create separate targets for building for 55, using the tomcat55 path and another for building 6 using tomcat6.
<target name="compile.tomcat55" depends="build">
<echo message="Compiling for Tomcat 5.5" />
<javac srcdir="${project.basedir}/src/test" destdir="${build.dir}" fork="true" source="1.5" classpathref="path.tomcat55" />
</target>
<target name="compile.tomcat6" depends="build">
<echo message="Compiling for Tomcat 6" />
<javac srcdir="${project.basedir}/src/test" destdir="${build.dir}" fork="true" source="1.5" classpathref="path.tomcat6" />
</target>
Then, just call the appropriate target.
Because the directory structure is mutually exclusive for Tomcat 5.5 and Tomcat 6.0, you may be able to specify all 3 of them and then ant will pick up only what's available:
<classpath>
<fileset dir="${catalina.home}/lib"
erroronmissingdir="false"
>
<include name="**/*.jar"/>
</fileset>
<fileset dir="${catalina.home}/common/lib"
erroronmissingdir="false"
>
<include name="**/*.jar"/>
</fileset>
<fileset dir="${catalina.home}/server/lib"
erroronmissingdir="false"
>
<include name="**/*.jar"/>
</fileset>
</classpath>
Specify erroronmissingdir="false", so ant does not complain about missing directories.
I would go the a simpler solution. Just add the 3 directories in the build path. Ant/javac should ignore if a classpath element is not found.