Headless Build for Beginners - Part I
Join the DZone community and get the full member experience.
Join For FreeThe easiest way to generate the plug-in jars is through Export Wizard. Assuming we already know this, lets try to play with headless build.
Headless Build
Here the workbench (IDE or UI) is referred to as 'head'. Headless build essentially means running the builds from command line in non-UI mode. This can be achieved by various means, however, we will start with java command line and org.eclipse.equinox.launcher jar.
Java -jar
This is standard Java part. Java executable has many command line options and -jar is one of them. The curious souls can learn more about packaging and executing jars.
org.eclipse.equinox.launcher
Eclipse has its own OSGi implementation which is known as Equinox. 'org.eclipse.equinox.launcher' is a plug-in as well as executable jar that launches the OSGi Runtime. It is located under plug-ins folder as org.eclipse.equinox.launcher_<version><qualifier.jar> ( for example org.eclipse.equinox.launcher_1.1.0.v20100507.jar).
-application
This '-application' option tells 'org.eclipse.equinox.launcher' that which application has to be launched. The application is identified by its id. The application is discovered using the Application Admin service. The Runtime Application Model explains how it works.
org.eclipse.ant.core.antRunner
Its the application id for the AntRunner application. It is contributed by org.eclipse.ant.core plug-in and its purpose it to run Ant build files.
build.xml
Its the Ant script to build the plug-in. Good news is the we need not be expert in Ant (however it good to have some knowledge about it). The PDE Build can generate this help for us. Right click on the build.properties and select PDE Tools -> Create Ant Build File. This will generate build.xml and javaCompiler...args files. There may be more and specially name of the later may vary depending on the output. entry in the build.properties file.
Putting the pieces together
Assuming that the name of the plugins project is 'com.example.helloworld' the command to build it headlessly will be
java -jar <eclipse-installation-path>\plugins\org.eclipse.equinox.launcher_<version><qualifier>.jar -application org.eclipse.ant.core.antRunner -buildfile <eclipse-workspace-path>\<project-name>\<build-xml-path>
Example:
java -jar C:\eclipse\plugins\org.eclipse.equinox.launcher_1.1.0.v20100507.jar
-application org.eclipse.ant.core.antRunner -buildfile C:\workspace\com.example.helloworld\build.xml
Result
This will build the plug-in project according to build.xml script. Since it was generated for us from build.propertied, it is essentially this file that governs the build. Note that build.xml is not generated automatically not kept in sync with build.properties. For any modifications to be reflected, the build.xml file has to be regenerated.
Assuming our plug-in does not have the Bundle-Classpath entry in the Manifest.MF file and source.. and output.. are the only source and output entries in our build.properties. The resultant build of such a plug-in will be in a folder '@Dot' in the project along with the log-file @dot.log .
This is not quite we expected. We were hoping to see a com.example.helloworld_1.0.0.v201006141121.jar kind of file. This happened because the default target (task) will just compile the classes. To make it generate the jar, edit build.xml and make the default target 'build.update.jar' (mentioned in the very first line).
<project name="com.example.helloworld" default="build.update.jar" basedir=".">
This shall generate the com.example.helloworld_<version><qualifier>.jar in the project folder. The build.xml can be modified to have it created in a desired location instead. Also note that the timestamp that replaces 'qualifier' is not the build time but the time when the build.xml was generated.
From http://blog.ankursharma.org/2010/06/headless-build-for-beginners-part-i.html
Opinions expressed by DZone contributors are their own.
Comments