Java/Packaging/Eclipse projects
From openSUSE
The Eclipse is one of the most popular IDE's over the world. Unfortunatelly don't use a standardize build system, but has it owns. For non-interactive build process (eg. build of rpm), there're some things, which are necessary to do.
Contents |
Requirements
For Java development, you need the Eclipse Java development tools (eclipse-jdt). For produce of standard build.xml you need the an Eclipse Plugin Development Environment (eclipse-pde) installed.
zypper install eclipse-pde
Eclipse project
Run eclipse and open/create a Java project. By default, eclipse creates similar files structure:
$ ls /home/mvyskocil/workspace/sample .classpath .project bin src
Move to the Package Explorer - a list of the packages in your project and shows the context menu ...
select PDE Tools/Converts projects to Plug-In Projects ...
... select the projects to convert ...
Now, we have a build.properties file. So for the generate of the build.xml ...
... select a PDE Tools/Create Ant Build File ...
... and voila, you've got an build.xml.
Create a jar
The default target doesn't creates a jar file. The jar was created in build.update.jar target, so type:
$ ant build.update.jar
Buildfile: build.xml
properties:
init:
build.update.jar:
[mkdir] Created dir: /home/mvyskocil/workspace/sample/temp.folder
properties:
init:
build.jars:
properties:
init:
@dot:
[mkdir] Created dir: /home/mvyskocil/workspace/sample/temp.folder/@dot.bin
[javac] Compiling 1 source file to /home/mvyskocil/workspace/sample/temp.folder/@dot.bin
[copy] Copying 1 file to /home/mvyskocil/workspace/sample/@dot
[delete] Deleting directory /home/mvyskocil/workspace/sample/temp.folder/@dot.bin
properties:
init:
gather.bin.parts:
[mkdir] Created dir: /home/mvyskocil/workspace/sample/temp.folder/sample_1.0.0
[copy] Copying 1 file to /home/mvyskocil/workspace/sample/temp.folder/sample_1.0.0
[copy] Copying 1 file to /home/mvyskocil/workspace/sample/temp.folder/sample_1.0.0
[jar] Building jar: /home/mvyskocil/workspace/sample/sample_1.0.0.jar
[jar] Building jar: /home/mvyskocil/workspace/sample/sample_1.0.0.jar
[delete] Deleting directory /home/mvyskocil/workspace/sample/temp.folder
BUILD SUCCESSFUL
Total time: 17 seconds
$ ls sample_1.0.0.jar
sample_1.0.0.jar
Tweaking the generated build.xml
You almost certainly want to set javacFailOnError to true, otherwise ant will report BUILD SUCCESSFUL even if nothing is build due to a missing class. Also, to make the build.xml more portable, it's a good idea to match the Eclipse jars in the classpath by wildcards instead of hardcoding the exact version number, e.g.
<path id="@dot.classpath"> <fileset dir="/usr/share/eclipse/plugins"> <include name="org.eclipse.ui_*.jar"/> <include name="org.eclipse.core.runtime_*.jar"/> <include name="org.eclipse.osgi_*.jar"/> <include name="org.eclipse.equinox.common_*.jar"/>
Have a look at the build.xml used in the Build Service plugin for eclipse for an example of such build file.






