| 
 
 
 | One-JAR AppgenCaution -- Advanced Topic Ahead: this information is not required to use the Appgen capability. 
The One-JAR Application Generator (one-jar-appgen) creates a fully-functional One-JAR Eclipse/Ant
project, based on the structure of a template project.  This is similar in nature to the way that
Grails lets you build projects using code-generators that can be customized by changing template 
documents.
The default project  template is contained inside theone-jar-appgen-0.97.jar/one-jar-$project$.jarfile
and it has the following directory structure: The key elements of this template are: 
one-jar-appgen processes this directory structure (and the files inside it), performing
token substitution with the data entered by the user.  The substituted tokens are:src -- Source-code for the main programtest -- Source code for a stand-alone test junit -- Source code to bridge between JUnit and the stand-alone testone-jar -- Distribution of the One-JAR software for use building and testing the project: the project is self-containedlib -- A directory into which dependent libraries can be placed for building into a One-JARbuild.xml -- A build script that can build a project into the various artifacts (runnable jars) 
For example, when one-jar-appgen creates a project named$project$ -- the path of the project: the last element of which is used as a project name.$package$ -- the package name for the project (Java package, '.' separators) path/testin a package calledfoo.bar,$project$will expand totest, and$package$will expand tofoo.bar.  The output files
will be written underpath.The template build.xml file starts out as: 
 
<?xml version="1.0" encoding="UTF-8"?>
<project name="one-jar-$project$" basedir="." default="build">
and is transformed to: 
<?xml version="1.0" encoding="UTF-8"?>
<project name="one-jar-test" basedir="." default="build">
etc.  The end result is a new project which builds two One-JAR archives: 
The test-$project$.jar is special: it has a main.jar with a Test class
that acts as the main entry point.  This class extendsbuild/$project$.jar -- A simple main program examplebuild/test-$project$.jar -- A stand-alone test program that can be hooked into JUnit com.simontuffs.onejar.test.Testable, which can be used by the$package$.test.$project$Suiteclass to run a JUnit test suite.  This is demonstrated by thejunit.$project$target in the build.xml file.Roll Your Own Project Templateone-jar-appgen is extensible: if you supply your ownone-jar-$project$.jaras a third
argument to the program it will be used for template expansion instead of the built-in template.
The best way to roll-your-own template is to first extract and unpack theone-jar-$project$.jarfile from inside the one-jar-appgen jar.  You can then build it in-place (it does build itself) using Ant, 
and start adding in your own new files (with the tokens$project$and$packagein the appropriate places in file-content, filenames and directories.
Once the appgen results are what you want, running with the extra third argument, you can repack
theone-jar-appgenjar file with the new template, and start using it (and sending it 
to your customers).Roll Your Own AppgenIf you need more information, unpack theone-jar-appgenjar file and look at the Appgen source code 
which is under main.jar/src in the distribution.  There is no significant magic there, but there is
some logic which might not be obvious surrounding camel-case and conversion of '-' to '_' in various
places that you might wish to modify as you "roll-your-own appgen" too. |