This shows you the differences between two versions of the page.
|
blog:using_ant_and_javac_without_installation [2009/11/30 01:12] jankotek created |
blog:using_ant_and_javac_without_installation [2009/11/30 01:14] (current) jankotek |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Using Ant and Javac without installation ====== | ====== Using Ant and Javac without installation ====== | ||
| - | Installing Ant and JDK can be pain. This post shows howto make Ant Java compiler part of your project. So it does not require installation. Only one external dependency needed to make build will be JRE. This setup makes it also much easier for new comers to start on project. | + | Installing Ant and JDK can be pain. This post shows howto make Ant Java compiler part of your project. So it does not require installation. Only one external dependency needed to make build will be JRE. This setup makes it also much easier for new comers to start on project |
| Trick is to place Ant jars into your classpath and use manual script files to call them. Javac from JDK have many dependencies, but it can be replaced with compiler from Eclipse. | Trick is to place Ant jars into your classpath and use manual script files to call them. Javac from JDK have many dependencies, but it can be replaced with compiler from Eclipse. | ||
| ====Step 1==== | ====Step 1==== | ||
| - | Download Ant and place its jar files into *tools* subdirectory. For most purposes you will need those files: *ant.jar*, *ant-launcher.jar*, *ant-testutil.jar* and *ant-trax.jar* | + | Download Ant and place its jar files into **tools** subdirectory. For most purposes you will need those files: **ant.jar**, **ant-launcher.jar**, **ant-testutil.jar** and **ant-trax.jar** |
| ====Step 2==== | ====Step 2==== | ||
| - | Create custom script to launch Ant. Create *ant.bat* file in root of your project. This will launch ant and forward all parameters to it. This launcher also adds all jars in *tools* and *lib* directory into classpath. | + | Create custom script to launch Ant. Create **ant.bat** file in root of your project. This will launch ant and forward all parameters to it. This launcher also adds all jars in **tools** and **lib** directory into classpath. |
| <code> | <code> | ||
| java -Djava.ext.dirs=tools;lib -Xmx256m -jar tools/ant-launcher.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 | java -Djava.ext.dirs=tools;lib -Xmx256m -jar tools/ant-launcher.jar %1 %2 %3 %4 %5 %6 %7 %8 %9 | ||
| </code> | </code> | ||
| - | And for Linux use *ant.sh* | + | And for Linux use **ant.sh** |
| <code> | <code> | ||
| #!/bin/sh | #!/bin/sh | ||
| Line 27: | Line 27: | ||
| ====Step 3==== | ====Step 3==== | ||
| - | Get Eclipse JDT Compiler. It is only 1.6 MB jar without any dependencies. Download it at [http://download.eclipse.org/eclipse/downloads/drops/R-3.5.1-200909170800/index.php Eclipse Project Downloads] (search for JDT Core Batch Compile or ecj-3.5.1.jar). Then place this jar into *tools* directory | + | Get Eclipse JDT Compiler. It is only 1.6 MB jar without any dependencies. Download it at [http://download.eclipse.org/eclipse/downloads/drops/R-3.5.1-200909170800/index.php Eclipse Project Downloads] (search for JDT Core Batch Compile or ecj-3.5.1.jar). Then place this jar into **tools** directory |
| ====Step 4==== | ====Step 4==== | ||
| - | Use Eclipse JDT Compiler. To make use out of new compiler you need to set one property in *build.xml*: | + | Use Eclipse JDT Compiler. To make use out of new compiler you need to set one property in **build.xml**: |
| <code> | <code> | ||
| <!-- | <!-- | ||
| Line 40: | Line 40: | ||
| Ant will use Eclipse JDT Compiler, so it will not require JDK. It will still display message 'tools.jar not found' but will compile just fine. | Ant will use Eclipse JDT Compiler, so it will not require JDK. It will still display message 'tools.jar not found' but will compile just fine. | ||
| - | NOTE: In some IDEs you may have problem because ECJ will not be in Ant classpath. Easiest workaround is to unset this property and install JDT. Other solution is to extend Ant path in your IDE to include ECJ. | + | ====NOTE==== |
| + | In some IDEs you may have problem because ECJ will not be in Ant classpath. Easiest workaround is to unset this property and install JDT. Other solution is to extend Ant path in your IDE to include ECJ. | ||