Adding jars to ant classpath in gwt - gwt

I am newbie to gwt and ant. Earlier I was working with maven/spring playFramework/sbt.
I would like to add some external jars to my gwt project like:
gwt3bootstrap
hibernate
mysql connector etc.
I've added jars to my lib folder in project:
- gwtbootstrap3-0.9.1.jar
- gwtbootstrap3-extras-0.9.1.jar
But I am getting an error on console:
Runing CodeServer with parameters: [-noprecompile, -port, 42543, -sourceLevel, 1.7, -bindAddress, 127.0.0.1, -launcherDir, /home/danielo/eclipseGwt/StockWatcher/war, -logLevel, INFO, com.google.gwt.sample.stockwatcher.StockWatcher]
Super Dev Mode starting up
workDir: /tmp/gwt-codeserver-6966154251496651044.tmp
Loading inherited module 'com.google.gwt.sample.stockwatcher.StockWatcher'
Loading inherited module 'com.github.gwtbootstrap.Bootstrap'
[ERROR] Unable to find 'com/github/gwtbootstrap/Bootstrap.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Loading modules
com.google.gwt.sample.stockwatcher.StockWatcher
Loading inherited module 'com.google.gwt.sample.stockwatcher.StockWatcher'
Loading inherited module 'com.github.gwtbootstrap.Bootstrap'
[ERROR] Unable to find 'com/github/gwtbootstrap/Bootstrap.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] shell failed in doStartup method
MyProject.gwt.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6.2//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.2/distro-source/core/src/gwt-module.dtd">
<module rename-to='stockwatcher'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.google.gwt.sample.stockwatcher.client.StockWatcher' />
</module>
build.xml:
<?xml version="1.0" encoding="utf-8" ?>
<project name="StockWatcher" default="build" basedir=".">
<!-- Configure path to GWT SDK -->
<property name="gwt.sdk" location="/path/to/gwt.sdk" />
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes" />
<pathelement location="${gwt.sdk}/gwt-user.jar" />
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar" />
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib" includes="**/*.jar" />
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
<!-- Add any additional server libs that need to be copied -->
</target>
<target name="javac" depends="libs" description="Compile java source">
<mkdir dir="war/WEB-INF/classes" />
<javac srcdir="src" includes="**" encoding="utf-8" destdir="war/WEB-INF/classes" source="1.5" target="1.5" nowarn="true" debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path" />
</javac>
<copy todir="war/WEB-INF/classes">
<fileset dir="src" excludes="**/*.java" />
</copy>
</target>
<target name="gwtc" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src" />
<path refid="project.class.path" />
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M" />
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg value="com.google.gwt.sample.stockwatcher.StockWatcher" />
</java>
</target>
<target name="devmode" depends="javac" description="Run development mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
<classpath>
<pathelement location="src" />
<path refid="project.class.path" />
</classpath>
<jvmarg value="-Xmx256M" />
<arg value="-startupUrl" />
<arg value="StockWatcher.html" />
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg value="com.google.gwt.sample.stockwatcher.StockWatcher" />
</java>
</target>
<target name="javac.tests" depends="javac" description="Compiles test code">
<javac srcdir="test" includes="**" encoding="utf-8" source="1.5" target="1.5" nowarn="true" debug="true" debuglevel="lines,vars,source">
<classpath location="path_to_the_junit_jar" />
<classpath refid="project.class.path" />
</javac>
</target>
<target name="test.dev" depends="javac.tests" description="Run development mode tests">
<mkdir dir="reports/htmlunit.dev" />
<junit fork="yes" printsummary="yes" haltonfailure="yes">
<jvmarg line="-Xmx256m" />
<sysproperty key="gwt.args" value="-logLevel WARN" />
<sysproperty key="java.awt.headless" value="true" />
<classpath>
<pathelement location="src" />
<pathelement location="test" />
<path refid="project.class.path" />
<pathelement location="path_to_the_junit_jar" />
</classpath>
<batchtest todir="reports/htmlunit.dev">
<fileset dir="test">
<include name="**/*Test.java" />
</fileset>
</batchtest>
<formatter type="plain" />
<formatter type="xml" />
</junit>
</target>
<target name="test.prod" depends="javac.tests" description="Run production mode tests">
<mkdir dir="reports/htmlunit.prod" />
<junit fork="yes" printsummary="yes" haltonfailure="yes">
<jvmarg line="-Xmx256m" />
<sysproperty key="gwt.args" value="-prod -logLevel WARN -out www-test" />
<sysproperty key="java.awt.headless" value="true" />
<classpath>
<pathelement location="src" />
<pathelement location="test" />
<path refid="project.class.path" />
<pathelement location="path_to_the_junit_jar" />
</classpath>
<batchtest todir="reports/htmlunit.prod">
<fileset dir="test">
<include name="**/*Test.java" />
</fileset>
</batchtest>
<formatter type="plain" />
<formatter type="xml" />
</junit>
</target>
<target name="test" description="Run development and production mode tests">
<antcall target="test.dev" />
<antcall target="test.prod" />
</target>
<target name="hosted" depends="devmode" description="Run development mode (NOTE: the 'hosted' target is deprecated)" />
<target name="build" depends="gwtc" description="Build this project" />
<target name="war" depends="build" description="Create a war file">
<zip destfile="StockWatcher.war" basedir="war" />
</target>
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/stockwatcher" failonerror="false" />
</target>
</project>
I've also tried to add this jars using in eclipse RMB on project -> Properties -> Java Build Path -> Libraries tab -> Add External JARs
But it dosn't helped me.
Please give me some help.
I have search many forum posts with the same issue, but couldn't resolve it on my own.

just use gwtBootstrap3 and you have to download the jar for it! here the link
than you have to declare the pathelement in your build.xml
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes" />
<pathelement location="${gwt.sdk}/gwt-user.jar" />
<pathelement location="yourpathtojar/gwtbootstrap3-0.9.1.jar" />
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar" />
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib" includes="**/*.jar" />
</path>
if you use a maven project instead you can follow this example

Related

Ant + GWT compiling two related projects

I have a problem with using Ant to compile a GWT project which is split into two parts. First project which is GWT project- client side of a web app and the second project included in build path which is a data model for hibernate. When I'm runing a build.xml I'm geting errors that I forget to inherit some modules. Where should I include my second project? in javac? project.classpath? libs?
I'm using standard build.xml example from GWT showcase:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Showcase" default="build" basedir=".">
<!-- Arguments to gwtc and devmode targets -->
<property name="gwt.args" value="" />
<!-- Configure path to GWT SDK -->
<property name="gwt.sdk" location="../.." />
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
<!-- Add any additional non-server libs (such as JUnit) -->
<fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet-deps.jar" />
<!-- Add any additional server libs that need to be copied -->
</target>
<target name="javac" depends="libs" description="Compile java source to bytecode">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.5" target="1.5" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
<copy todir="war/WEB-INF/classes">
<fileset dir="src" excludes="**/*.java"/>
</copy>
</target>
<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
</java>
</target>
<target name="devmode" depends="javac" description="Run development mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="../../validation-api-1.0.0.GA.jar" />
<pathelement location="../../validation-api-1.0.0.GA-sources.jar" />
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="-startupUrl"/>
<arg value="Showcase.html"/>
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="com.google.gwt.sample.showcase.Showcase"/>
</java>
</target>
<target name="superdevmode" depends="javac" description="Run Super Dev Mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.codeserver.CodeServer">
<classpath>
<pathelement location="src"/>
<pathelement location="../../gwt-codeserver.jar" />
<path refid="project.class.path"/>
<pathelement location="../../validation-api-1.0.0.GA.jar" />
<pathelement location="../../validation-api-1.0.0.GA-sources.jar" />
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="com.google.gwt.sample.showcase.Showcase"/>
</java>
</target>
<target name="eclipse.generate" depends="libs" description="Generate eclipse project">
<java failonerror="true" fork="true" classname="com.google.gwt.user.tools.WebAppCreator">
<classpath>
<path refid="project.class.path"/>
</classpath>
<arg value="-XonlyEclipse"/>
<arg value="-ignore"/>
<arg value="com.google.gwt.sample.showcase.Showcase"/>
</java>
</target>
<target name="hosted" depends="devmode" description="Run development mode (NOTE: the 'hosted' target is deprecated)" />
<target name="build" depends="gwtc" description="Build this project" />
<target name="war" depends="build" description="Create a war file">
<zip destfile="Showcase.war" basedir="war"/>
</target>
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/showcase" failonerror="false" />
</target>
</project>

Eclipse with Java EE (EJB), ANT and Jenkins / Hudson

My Goal is to get a Enterprise Java Application to be built on Jenkins. The Application consists of 4 Projects (Client-Interfaces, Webapplcation (incl. Faces), EJB Application (incl. JPA), EAR-Container-Project).
When Eclipse deploys this projects to a glassfish server, it assembles the Webapplication (war-file), the Client-Interfaces (jar-file) and the EJB-Interfaces (jar-file) into one ear-File.
Now, if I want to use continous integration I need to achieve the same on the CI-Server jenkins.
My first idea was to solve this with ant, so I used the Export-Function of Eclipse and generated build-Files for the projects.
The Problem is that the generated Build-Files refer to the Java EE Libraries (such as Glassfish-Runtime, JPA-Library, etc) which are outside of the project directory. There are about 30 libraries.
This implies that I cannot use the file on jenkins, because this libraries are missing. Of course I can copy these, but I don't think this is how it should be done.
So, what is the best way to get the Java EE Enterprise Application to be built on the CI Server? Do I have to write the ANT-Script all by myself and copy the libraries into the project? Or am I Missing something obvious?
Since I did not found anything that suited for me, I wrote an ant script that covered my needs on my own.
Here is my solution if this helps anyone in the future:
`
<project basedir="." default="build" name="Project">
<available property="glassfishdir" value="/opt/glassfish3/glassfish/modules"
file="/opt/glassfish3/glassfish/modules" type="dir" />
<!-- ########### Property Declarations ################################################################################################################### -->
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="builddir" value="build" />
<property name="outputartifacts" value="out" />
<property name="web.name" value="ProjectWeb" />
<property name="web.projectpath" value="ProjectWeb"/>
<property name="web.src" value="${web.projectpath}/src" />
<property name="web.builddir" value="${builddir}/web" />
<property name="web.builddir.classes" value="${web.builddir}/WEB-INF/classes"/>
<property name="ejb.name" value="ProjectEJB" />
<property name="ejb.projectpath" value="ProjectEJB"/>
<property name="ejb.src" value="${ejb.projectpath}/src"/>
<property name="ejb.builddir" value="${builddir}/ejb" />
<property name="ejb.builddir.classes" value="${ejb.builddir}/classes" />
<property name="ejbclient.name" value="ProjectEJBClient" />
<property name="ejbclient.projectpath" value="ProjectEJBClient"/>
<property name="ejbclient.src" value="${ejbclient.projectpath}/src"/>
<property name="ejbclient.builddir" value="${builddir}/ejbclient" />
<property name="ejbclient.builddir.classes" value="${ejbclient.builddir}/classes"/>
<property name="ear.name" value="ProjectApplication" />
<property name="ear.dir" value="ProjectEAR" />
<!-- ########### Main Targets ################################################################################################################### -->
<target name="build" depends="create-ear">
</target>
<target name="clean-build">
<antcall target="clean" />
<antcall target="build" />
</target>
<target name="clean">
<delete dir="${builddir}"/>
<delete dir="${outputartifacts}"/>
</target>
<target name="init">
<mkdir dir="${outputartifacts}" />
</target>
<!-- ########### EJB App ################################################################################################################### -->
<target name="init-ejb" depends="init">
<mkdir dir="${ejb.builddir}" />
<copy includeemptydirs="false" todir="${ejb.builddir.classes}">
<fileset dir="${ejb.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="build-ejb" depends="init-ejb">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejb.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejb.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${outputartifacts}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ########### WEB ################################################################################################################### -->
<target name="init-web" depends="init">
<mkdir dir="${web.builddir.classes}"/>
<copy includeemptydirs="false" todir="${web.builddir}">
<fileset dir="${web.projectpath}/WebContent">
</fileset>
</copy>
<copy includeemptydirs="false" todir="${web.builddir.classes}">
<fileset dir="${web.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-web,create-ejb-client" name="build-web">
<javac debug="true" debuglevel="${debuglevel}" destdir="${web.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${web.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="out/">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############## EJB CLIENT ################################################################################################################ -->
<target name="init-ejb-client" depends="init">
<mkdir dir="${ejbclient.builddir}"/>
<copy includeemptydirs="false" todir="${ejbclient.builddir.classes}">
<fileset dir="${ejbclient.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-ejb-client" name="build-ejb-client">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejbclient.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejbclient.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############ CREATE ARCHIVES################################################################################################################## -->
<target name="create-web" depends="build-web">
<war destfile="${outputartifacts}/${web.name}.war" basedir="${web.builddir}" webxml="${web.projectpath}/WebContent/WEB-INF/web.xml"/>
</target>
<target name="create-ejb-client" depends="build-ejb-client">
<jar destfile="${outputartifacts}/${ejbclient.name}.jar" basedir="${ejbclient.builddir.classes}" includes="**/*"/>
</target>
<target name="create-ejb" depends="build-ejb">
<jar destfile="${outputartifacts}/${ejb.name}.jar" basedir="${ejb.builddir.classes}" includes="**/*">
<manifest>
<attribute name="Class-Path" value="${ejbclient.name}.jar"/>
</manifest>
</jar>
</target>
<target name="create-ear" depends="create-ejb-client,create-web,create-ejb">
<ear destfile="${outputartifacts}/${ear.name}.ear" appxml="${ear.dir}/EarContent/META-INF/application.xml">
<fileset dir="${outputartifacts}" includes="*.jar,*.war"/>
</ear>
</target>
</project>
`
Use Maven.
Maven allow to define all dependencies in a single xml file (pom), dependencies which will be automatically downloaded from internet at compilation phase.
Maven come with a set of plugin to facilitate continuous integration like being able to start a container, run the test and close it automatically.
Maven integrate natively with jenkins.
Maven defines a complex lifecycle designed for this kind of problematic and allowing to compile, run unit test, package, run integration test and deploy with a single command triggered from jenkins;
Maven is definitively THE solution here.
You can also auto-create the build.xml in Eclipse using "Export... > General\Ant Buildfile" from the project context menu. This way the correct classpath is generated to your JAR's already available in the project.
Chances are that if there are dependencies between the projects, you only need to configure one build file to be run on Jenkins, as it will automatically call the build files from the other projects.

Trying create db using ant

My build.xml
<?xml version='1.0'?>
<project xmlns:ivy="antlib:org.apache.ivy.ant" name='myTest' basedir='.' default='usage'>
<property file='build.properties' />
<property name='src.dir' value='src' />
<property name='web.dir' value='war' />
<property name='build.dir' value='${web.dir}/WEB-INF/classes' />
<property name='name' value='myTest' />
<property name="sql.driver" value="org.postgresql.Driver"/>
<property name="sql.url" value="jdbc:postgresql://localhost:5432/tbook"/>
<property name="sql.user" value="postgres"/>
<property name="sql.pass" value="admin"/>
<path id='master-classpath'>
<fileset dir='${web.dir}/WEB-INF/lib'>
<include name='*.jar' />
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir='${appserver.lib}'>
<include name='servlet*.jar' />
</fileset>
<pathelement path='${build.dir}' />
</path>
<target name='usage'>
<echo message='' />
<echo message='${name} build file' />
<echo message='-----------------------------------' />
<echo message='' />
<echo message='Available targets are:' />
<echo message='' />
<echo message='build --> Build the application' />
<echo message='deploy --> Deploy application as directory' />
<echo message='deploywar --> Deploy application as a WAR file' />
<echo message='resolve --> retrieve dependencies with ivy' />
<echo message='' />
</target>
<target name="createDB_PostgreSQl">
<sql driver="${sql.driver}"
url="${sql.url}"
userid="${sql.user}"
password="${sql.pass}"
src="db.sql">
<classpath refid="master-classpath"/>
</sql>
</target>
<target name="dropDB_PostgreSQl">
<input message="Do you really want to delete this table (y/n)?" validargs="y,n" addproperty="do.delete" />
<condition property="do.abort">
<equals arg1="n" arg2="${do.delete}"/>
</condition>
<fail if="do.abort">Build aborted by user.</fail>
<sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
<classpath>
<pathelement location="postgresql-9.0-802.jdbc4.jar"/>
</classpath>
drop database sample_project;
</sql>
</target>
<target name="createTables_PostgreSQL">
<sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
<classpath refid="master-classpath"/>
<transaction src="user.sql"/>
</sql>
</target>
<target name='build' description='Compile main source tree java files'>
<mkdir dir='${build.dir}' />
<javac destdir='${build.dir}' source='1.5' target='1.5' debug='true'
deprecation='false' optimize='false' failonerror='true'>
<src path='${src.dir}' />
<classpath refid='master-classpath' />
</javac>
</target>
<target name="clean">
<delete includeemptydirs="false">
<fileset dir="build/" includes="**/**"/>
</delete>
</target>
<target name='deploy' depends='build' description='Deploy application'>
<copy todir='${deploy.path}/${name}' preservelastmodified='true'>
<fileset dir='${web.dir}'>
<include name='**/*.*' />
</fileset>
</copy>
</target>
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:retrieve />
</target>
<target name='deploywar' depends='build'
description='Deploy application as a WAR file'>
<war destfile='${name}.war' webxml='${web.dir}/WEB-INF/web.xml'>
<fileset dir='${web.dir}'>
<include name='**/*.*' />
</fileset>
</war>
<copy todir='${deploy.path}' preservelastmodified='true'>
<fileset dir='.'>
<include name='*.war' />
</fileset>
</copy>
</target>
</project>
Exception is:
org.postgresql.util.PSQLException:ERROR: CREATE DATABASE can not be executed inside a transaction block
Take a look at this thread from the past. http://archives.postgresql.org/pgsql-jdbc/2005-11/msg00132.php
Basically for the create db task add this autocommit="true"

Errors while applying transformations - Use of the extension element 'redirect' is not allowed when the secure processing feature is set to true

Please help me to fix this error and warnings:
41: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
79: Errors while applying transformations: javax.xml.transform.TransformerException: java.lang.RuntimeException: Use of the extension element 'redirect' is not allowed when the secure processing feature is set to true.
Total time: 31 seconds
This is my build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="Login">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../opt/eclipse"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="Login.classpath">
<pathelement location="bin"/>
<pathelement location="../../Downloads/JAR/junit-4.10.jar"/>
<pathelement location="../../Downloads/JAR/poi-3.2-FINAL.jar"/>
<pathelement location="../../Downloads/JAR/selenium-java-2.21.0.jar"/>
<pathelement location="../../Downloads/JAR/selenium-java-2.21.0.zip"/>
<pathelement location="../../Downloads/JAR/selenium-java-2.21.0-srcs.jar"/>
<pathelement location="../../Downloads/JAR/selenium-server-standalone-2.21.0.jar"/>
<pathelement location="../../Downloads/JAR/testng-6.5.1.zip"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="Login.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="login.testLogin">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="login" todir="${junit.output.dir}"/>
<classpath refid="Login.classpath"/>
</junit>
</target>
<target name="login">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="login" todir="${junit.output.dir}"/>
<classpath refid="Login.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
<classpath>
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
<path id="junit" location="${lib.dir}/junit-4.9b2.jar"/>
</classpath>
</javac>
</target>
</project>
For the warning, please add includeantruntime to javac target.
Please follow below link for more information.
ant warning: "'includeantruntime' was not set"
What is your version of Ant?
This links talk about a fix in 1.8.3

Eclipse unable to compile ant script programmatically

I have an Ant script that I would like to execute using a button that I made. The problem now is that I would get an error saying:
BUILD FAILED
X:\eclipseMT\runtime-workspace\testTest\diagram1_Sc2_TestScript.xml:68:
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the
classpath. Perhaps JAVA_HOME does not
point to the JDK. It is currently set
to "C:\Program
Files\Java\jdk1.6.0_12\jre"
I'm pretty sure that my classpath is correct and I can execute the same script using Eclipse internal Ant executor.
This is my ant script:
<property name="src.dir" value="src" />
<property name="test.dir" value="test" />
<property name="test.wstest.dir" value="${test.dir}/wstest" />
<property name="junit.dir" location="X:\eclipseMT\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100"/>
<property name="build.dir" value="build" />
<property name="build.classes.dir" value="${build.dir}/classes" />
<property name="build.test.dir" value="${build.dir}/test"/>
<property name="build.test.classes.dir" value="${build.test.dir}/classes" />
<property name="build.test.data.dir" value="${build.test.dir}/data" />
<property name="build.test.reports.dir" value="${build.test.dir}/reports" />
<property name="dist.dir" value="dist" />
<property name="lib.dir" value="lib" />
<property name="build.debug" value="true" />
<path id="compile.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<path id="test.compile.classpath">
<path refid="compile.classpath" />
<pathelement location="${build.classes.dir}"/>
</path>
<path id="test.classpath">
<path refid="test.compile.classpath" />
<pathelement location="${build.test.classes.dir}"/>
</path>
<target name="init" description="create dir desc">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${lib.dir}" />
<copy todir="${lib.dir}">
<fileset dir="${junit.dir}"/>
</copy>
<echo>make init dir done</echo>
</target>
<target name="test-init" depends="init" description="create test dir">
<mkdir dir="${build.test.dir}" />
<mkdir dir="${build.test.classes.dir}" />
<mkdir dir="${build.test.data.dir}"/>
<mkdir dir="${build.test.reports.dir}"/>
<echo>make test init dir done</echo>
</target>
<target name="clean" depends="init, test-init" description="remove previous build">
<delete verbose="true">
<fileset dir="${build.classes.dir}" />
<fileset dir="${build.test.classes.dir}" />
<fileset dir="${build.test.data.dir}" />
<fileset dir="${build.test.reports.dir}" />
<fileset dir="${dist.dir}" />
</delete>
<echo>clean build dir done</echo>
</target>
<target name="compile" depends="clean" description="compile java source">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" classpath="${build.classes.dir}" debug="on" fork="no" includeAntRuntime="false" />
<echo>compile source done</echo>
</target>
<target name="test-compile" depends="compile, test-init" description="compile test source">
<javac srcdir="${test.wstest.dir}" destdir="${build.test.classes.dir}" debug="true" includeAntRuntime="true">
<classpath refid="test.compile.classpath" />
</javac>
<echo>compile test src done</echo>
</target>
<target name="test-reporting" depends="test-compile" description="report even if fail">
<junit printsummary="false" errorproperty="test.failed" failureproperty="test.failed">
<classpath>
<path refid="test.classpath" />
</classpath>
<formatter type="brief" usefile="false" />
<formatter type="xml" />
<batchtest todir="${build.test.data.dir}" unless="testcase">
<fileset dir="${build.test.classes.dir}" />
<!--fileset dir="${build.test.classes.dir}" includes="Sc2TestClient*.class" /-->
</batchtest>
</junit>
<junitreport todir="${build.test.data.dir}">
<fileset dir="${build.test.data.dir}">
<include name="WSTEST-*.xml" />
</fileset>
<report format="frames" todir="${build.test.reports.dir}" />
</junitreport>
<fail if="test.failed">
Test failed. Check ${build.test.reports.dir}
</fail>
</target>
<target name="default" depends="test-reporting" description="test the whole suite">
<echo>all test done</echo>
<tstamp>
<format property="buildTime" pattern="yyyy-MM-dd' 'HH:mm:ss" />
</tstamp>
<echo>build time = ${buildTime}</echo>
</target>
This is my button code:
Project p = new Project();
try {
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
} catch (Throwable t) {
t.printStackTrace();
p.fireBuildFinished(t);
return false;
}
It's complaining about javac, unable to find javac.. your JAVA_HOME(C:\Program Files\Java\jdk1.6.0_12\jre) is pointing to only "jre" not to java compiler(javac). Set you JAVA_HOME to "C:\Program Files\Java\jdk1.6.0_12\bin"(which has both javac and jre) and it should work. :-)
--Nagesh Palathya
A friend give me a reference to this earlier question: Setting JAVA_HOME when running Ant from Java
The problem basicly is with ant because it has point java.home to 'jre' instead of 'jdk'. It got overwritten everytime ant was call to execute.
The solution is to add:
fork="yes"
to each compilation script and add:
p.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.6.0_26");
to the java execution code.
Hope this help others :D