eclipse.buildScript Complete Example Script for headless build - eclipse

I am trying to generate a build script for a plugin outside the IDE
Below is mybuild.xml
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
<target name="build.plugin">
<antcall target="generateBuildScript" />
<ant dir="${workspace.dir}/${project.name}"
antfile="build.xml"
target="build.update.jar" />
<copy todir="${eclipse.dir}/plugins">
<fileset dir="${workspace.dir}/${project.name}">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="generateBuildScript">
<eclipse.buildScript elements="plugin#${project.name}"
buildDirectory="${workspace.dir}"
baseLocation="${eclipse.dir}"
configInfo="linux,gtk,win32,win32,x86"/>
</target>
</project>
Expecting build.xml to be generated Please Guide me
When I run above script
$java -jar {$Eclipse.Dir}/plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -application org.eclipse.ant.core.antRunner -buildfile <Project_path>\mybuild.xml
I nothing is happening on build success.

Here i have found the answer may help some new bees like me..
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
...
</project>
As there is no default set, it is not generating the required jar file so
modified only the first line as
<project name="com.foo.poo" default="build.plugin" xmlns='antlib:org.apache.tools.ant'>
...
</project>
now the required jar is generated under plugin folder and even copied to plugin folder of eclipse.
baseLocation : Target Plugins Directory absolute path.
buildDirectory: Absolute path to the plugin folder in which the Plugin Project is present.

Related

Ant can't seem to link to groovy properly in NetBeans 8.2

In netBeans 8.2, I'm having an issue reading groovy inside a build.xml file.
I have a project in which I run my script via a build.xml using the build-in Ant 1.9.7.
In it, for my groovy task, I set the following:
<property environment="env" />
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable" />
</path>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath" />
For environment variable {env.GROOVY_HOME}, I have set the following in windows environment variable:
GROOVY_HOME with the value C:\Program Files (x86)\Groovy\Groovy-2.4.10
Yet I'm still having an error ""Script failed" when reaching the step with Groovy at the following stage in the build.xml file:
<groovy>
def corePlatformList = []
[Groovy code here...]
</groovy>
I know the script is working fine as it does run perfectly in Eclipse and IntelliJ.
It would seem ant can't link with Groovy 2.4.10 for some reason.
I believe that you have some trivial error.
You need to include the library file.
Change from:
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable" />
</path>
To:
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable">
<include name="**/groovy-all-*.jar"/>
</fileset>
</path>
EDIT: based on OP comments
Here is the complete build.xml and I can see it working.
<project name="MyProject" default="runscript" basedir=".">
<path id="groovy.classpath">
<fileset dir="d:/softwares/groovy-2.4.5/embeddable">
<include name="**/groovy-all-*.jar"/>
</fileset>
</path>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath" />
<target name="runscript"
description="compile the source">
<groovy>
def corePlatformList = [1,2,3,4]
println corePlatformList
</groovy>
</target>
</project>

Setup Netbeans project on Jenkins

I have a Netbeans Project that I'm trying to build from Jenkins, using ant, in a linux environment.
I have copied the CopyLibStack.jar to /var/lib/Jenkins/nblibs/ and setup in the ant task with the following properties:
-Dj2ee.server.home="/var/lib/jenkins/tomcat/"
-Dlibs.CopyLibs.classpath=/var/lib/jenkins/nblibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
But it doesn’t work; it fails on a <copyfiles> task
If I install Jenkins on windows and set the properties to:
-Dj2ee.server.home="C:\Archivos de programa\Apache Software Foundation\Tomcat 6.0"
-Dlibs.CopyLibs.classpath=C:\\.jenkins\\nblibs\\org-netbeans-modules-java-j2seproject-copylibstask.jar
The project build without problems
If I run the ant task from the terminal with:
ant -file build.xml do-dist test -Dlibs.CopyLibs.classpath="/var/lib/jenkins/nblibs/copylibstask.jar" -Dj2ee.server.home="/var/lib/jenkins/tomcat/"
it builds fine too
I think that the problem is in the user jenkins, but I don't know how to fix it.
What can I do?
I had the same problem, which I have fixed :) (I'm using ubuntu 12.04). Find build.properties in ".netbeans/7.0" and look for the lib that you are missing... copy it to project.properties
Ex:
libs.CopyLibs.classpath=/opt/netbeans-7.0.1/java/ant/extra/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.javaee-api-6.0.classpath=/opt/netbeans-7.0.1/enterprise/modules/ext/javaee-api-6.0.jar
I found a recipe in this link basically you have to have Netbeans installed on your server so you can reuse the build.xml generated by Netbeans.
Create a file jenkins-build.xml at the same level as your build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="BioGatewayWS Stub" default="build" basedir=".">
<!-- create private folders -->
<mkdir dir="nbproject/private"/>
<!--- set variables needed by Ant when outside of Netbeans -->
<propertyfile file="nbproject/private/private.properties">
<!--<entry key="user.properties.file" value="/opt/NetBeans8/build.properties"/>-->
<entry key="user.properties.file" value="C:\Users\jm\AppData\Roaming\NetBeans\8.2\build.properties"/>
</propertyfile>
<!-- Build targets - these just chain a call to the original build file-->
<target name="build">
<!-- <ant dir="${basedir}" target="build"/>-->
<ant dir="${basedir}" target="default"/>
</target>
<target name="clean">
<ant dir="${basedir}" target="clean"/>
</target>
</project>
and run Ant:
ant -file jenkins-build.xml clean
ant -file jenkins-build.xml build
Thanks to the original author matt

Getting an error "Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found."

I am getting an error Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found. when I am trying to ant build on eclipse. So I downloaded ant-contrib-0.6.jar and kept it in my /lib location of apache ant, but it still does not resolve my issue. I have also tried by specifying the /lib location in my CLASSPATH system variable. How can I get around this error?
You can provide full path to the ant-contrib JAR explicitly using "classpath" element:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${path-to-ant-contrib}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
EDIT: Link contributed by Djacomo:
http://ant-contrib.sourceforge.net/
One important thing missing from this StackOverflow page is that setting the correct ANT_HOME env var is absolutely vital and important, without this setting ant keeps telling the same error, regardless of where you copy the ant-contrib-1.0b3.jar on your file systems. This missing thing has costed me a few hours. =)
However I receive this error without eclipse, in the pure ant.
I fixed that this way:
Add the JAR to the Ant runtime classpath entries.
Window>Preferences>Ant>Runtime>Classpath
Add the JAR to either Ant Home Entries or Global Entries.
It would appear that you haven't installed the ant contrib jar into the correct lib directory. This can be difficult to do if you have several installations of ANT.
My suggestion is to install your ANT plugins into the "$HOME/.ant/lib" directory. You could go one step further and automate the process as follows:
<project name="ant-contrib-tasks" default="all">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
</target>
<target name="all">
<for param="file">
<fileset dir="." includes="*.txt"/>
<sequential>
<echo message="Found file #{file}"/>
</sequential>
</for>
</target>
</project>
Use the below mentioned code in your build xml:
<path id="ant.classpath">
<pathelement location="${ant.jarPath}/ant.jar" />
<pathelement location="${ant.jarPath}/ant-contrib-0.3.jar" />
</path>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath refid="ant.classpath" />
</taskdef>
And in your build property file:
ant.jarPath=D:/antjars
And place ant.jar and ant-contrib-0.3.jar in directory:D:/antjars
Check you have read permissions for the ant-contrib jar file.
In our case after copying the file with another user it did not, giving the same error message.

.war file won't be updated

I have an old project, built using Google Web Toolkit in Eclipse. When I created it, I did the following steps, in order to get the .war file
GWT Compile Project
Run the following Ant script
<project name="The" basedir="." default="default">
<target name="default" depends="buildwar,deploy"></target>
<target name="buildwar">
<war basedir="war" destfile="The.war" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="The.war" todir="." />
</target>
</project>
Get the .war file
Now, I had to change a port in my project, so I changed it in my code and did the same steps in order to get the .war
However, when I deploy my updated project in Tomcat, it still makes requests to the old port number (I found this reading catalina.out)
So, What can I do in order to get a new, fresh .war ???
You don't mention it, but did you change the ports in tomcat? I assume you did, but I just want to cover all possibilities.

How can I automate (script) creating a war file in eclipse?

It's 5 button clicks to get eclipse to create a deployable war file for my eclipse project, I figure there's probably some eclipse command line option to do the same thing, so I can just write it into a script, but I'm not seeing it.
Use the Ant war task, set up a relevant build file and you can just hit the "external tools" button to execute it.
You could also setup a Maven build for your web project. Typing mvn package from the command line would then build the project for you.
For integration between Maven and Eclipse, see m2Eclipse and Maven Eclipse Plugin.
I cannot say anything about the WAR packaging itself, sorry.
But as I wrote in
How do I automatically export a WAR after Java build in Eclipse? : If you can describe the WAR packaging with an Ant script, you can have that Ant script being executed automatically after each change to your project. Use Project->Properties->Builders->Add->Ant Builder. Give that builder you custom Ant script and it will automatically be executed after the "normal" builders of your project.
You can even specify in the settings of the builder, if it shall only react on changes to specific files and so on.
The Ant builder is kind of a Swiss army knife for anything you want to automate in the project build without having to use the big tools like maven.
This Ant script should work for standard Dynamic Web Project structure of project:
Create Ant build.xml with replacing of two properties at begining:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Deploy From Eclipse to JBoss" basedir="." default="deploy">
<!-- This replace with yours project name and JBoss location: -->
<property name="warfile" value="MyProject"/>
<property name="deploy" value="/home/honza/jboss-as-7.1.1.Final/standalone/deployments"/>
<target name="create">
<war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
<classes dir="build\classes"/>
<fileset dir="WebContent">
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="copy">
<copy todir="${deploy}" overwrite="true">
<fileset dir=".">
<include name="${warfile}.war"/>
</fileset>
</copy>
</target>
<target name="clear">
<delete includeemptydirs="true">
<fileset dir="${deploy}" defaultexcludes="false">
<include name="${warfile}.*/**" />
</fileset>
</delete>
</target>
<target name="deploy">
<antcall target="create"/>
<antcall target="clear"/>
<antcall target="copy"/>
</target>
</project>
Now should command "ant" do WAR creation and copy them to the JBoss. JBoss automatically deploys wars which finds in deployment directory.
For automatic run after build (Project - Build) add this Buildfile here:
MyProject - Properties - New - Ant builder