Documentation

Contents

 

Command Line Generation

Usually its not necessary to run the Java code generator from command-line because the Java code is automatically generated and updated while editing a form in JFormDesigner. However in rare cases it is useful to re-generate the Java code of JFormDesigner forms. E.g. if you want upgrade to JGoodies FormLayout 1.2, which introduced a new much shorter syntax for encoded column and row specifications.

Requirements

You need an installation of the JFormDesigner stand-alone edition. If you usually use one of the IDE editions, then simply download the stand-alone edition and install it.

Preferences

The command-line Java code generator uses the preferences store of the stand-alone edition. If you use one of the IDE editions of JFormDesigner, you have to start the stand-alone edition and set the necessary preferences for the code generation. To transfer JFormDesigner preferences from an IDE to the stand-alone edition, you can use the Import and Export buttons in the Preferences dialogs. Make sure that the Code Style preferences are correct because they are not transfered from a IDE.

Command Line Syntax

Launch the code generator as follows, where [ ] means optional arguments and arguments in italics must be provided by you.

java -classpath <jfd-install>/lib/JFormDesigner.jar
    com.jformdesigner.application.JavaCodeGeneratorMain
    [-r] [-v]
    [<project-path>/MyProject.jfdproj]
    <folder> or <path>/MyForm1.jfd [...]

Option Description
-classpath <jfd-install>/lib/JFormDesigner.jar Specifies the JAR that contains the Java code generator. This is a standard argument of the Java application launcher.
com.jformdesigner.application.JavaCodeGeneratorMain The class name of the Java code generator.
-r Recursively process folders.
-v Prints file names of processed .jfd files to the console.
<project-path>/MyProject.jfdproj Optional JFormDesigner stand-alone edition project used to extend the classpath for the code generation. Useful when using custom components.
<folder> or <path>/MyForm1.jfd [...] List of folders or .jfd files. If a folder is specified, all .jfd files in the folder are processed.

Using custom components

If you're using custom components (JavaBeans) in your forms, it is necessary to tell the code generator the classpath of your components, because the code generator needs to load the classes of custom components. There are two options to specify the classpath for your custom components:

  • JFormDesigner stand-alone edition project: The JARs and folders specified on the Classpath page in the project settings are used by the code generator. This is the preferred way is you use the stand-alone edition.
  • Classpath of Java application launcher: Simply add your JARs to the -classpath option of the Java application launcher. This is the preferred way if you use Ant (see below) or one of the IDE editions (which don't use JFormDesigner project files).

Examples

Generate code for a single form:

cd C:\MyProject
java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar
    com.jformdesigner.application.JavaCodeGeneratorMain
    src/com/myproject/MyForm1.jfd

Generate code for all forms in a project that use custom components:

cd C:\MyProject
java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar;classes;swingx.jar
    com.jformdesigner.application.JavaCodeGeneratorMain
    -r src

Ant

Although we don't provide a special task for Ant, it is easy to invoke the JFormDesigner Java code generator from an Ant script. The <classpath> element makes it easy to specify JARs and folders of custom components.

<property name="jfd-install-dir" value="C:/Program Files/JFormDesigner"/>

<java classname="com.jformdesigner.application.JavaCodeGeneratorMain"
        fork="true" failonerror="true" logError="true">
    <classpath>
        <pathelement location="${jfd-install-dir}/lib/JFormDesigner.jar"/>
        <pathelement location="myLibrary.jar"/>
    </classpath>
    <arg value="-r"/>
    <arg value="src"/>
</java>

« previous | next »