Documentation

Command Line Tool

The command-line tool allows you to run some commands (e.g. Java code generation) on many forms.

Available commands

  • Java Code 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 (or later), which introduced a new much shorter syntax for encoded column and row specifications.
  • Externalize strings: If you have to localize many existing non-localized forms, then this command does the job very quickly.
  • Convert layout manager: Allows you to convert all usages of one layout manager to another one. Useful for migrating forms to a modern powerful layout manager (e.g. MigLayout).
  • Convert .jfd file format: Since version 5.1, JFormDesigner supports the compact, easy-to-merge and fast-to-load persistence format JFDML. This command allows you to convert all your .jfd files from XML to JFDML and benefit from the new format.

Requirements

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

Preferences

To specify preferences for the command-line tool, you should create a stand-alone edition project, enable and set project specific settings and pass the project .jfdproj file to the command-line tool.

If you usually use the JFormDesigner stand-alone edition and already have a .jfdproj file, then you can use it for the command-line tool. Otherwise, start the JFormDesigner stand-alone edition and create a new project.

If you don't use a project, then the command-line tool uses the preferences store of the stand-alone edition. If you use one of the IDE plug-ins of JFormDesigner, you have to start the stand-alone edition and set the necessary preferences. 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 transferred from the IDE.

Command Line Syntax

Launch the command-line tool 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.CommandLineMain
    [--generate|--i18n-externalize|--convert-layout|--convert-jfd]
    [--dry-run] [--verbose|-v] [--recursive|-r]
    [<command-specific-options>]
    [<project-path>/MyProject.jfdproj]
    <folder> or <path>/MyForm1.jfd
[...]
Option Description
-classpath <jfd-install>/lib/JFormDesigner.jar Specifies the JAR that contains the command-line tool. This is a standard argument of the Java application launcher.
com.jformdesigner.application.CommandLineMain The class name of the command-line tool.
--generate Generate Java code for the given forms or folders.
--i18n-externalize Externalize strings in the given forms or folders. This requires that you've specified Source Folders in the used project.
--convert-layout Convert one layout manager to another one.
--convert-jfd Convert the given .jfd files to another format.
--dry-run Execute the given command, but do not save modifications. Only shows what would happen. This option enables --verbose.
--verbose or -v Prints file names of processed .jfd and .java files to the console.
--recursive or -r Recursively process folders.
--bundle-name=<bundleName> Only used for --i18n-externalize.
The resource bundle name used to store strings. You can use variables {package} (package name of form) and {basename} (basename of form). Default is "{package}.Bundle", which creates Bundle.properties in same package as the form. This option is ignored when processing already localized forms.
--key-prefix=<keyPrefix> Only used for --i18n-externalize.
The prefix for generated key. You can use variable {basename} (basename of form). Default is "{basename}". This option is ignored when processing already localized forms.
--auto-externalize=<true|false> Only used for --i18n-externalize.
Set the auto-externalize option in the processed forms. Default is true.
--old-layout=<layoutClassName> Only used for --convert-layout.
The full qualified class name of the layout manager that will be converted to another layout manager.
--new-layout=<layoutClassName> Only used for --convert-layout.
The full qualified class name of the target layout manager.
--lookandfeel=<lookAndFeelClassName> Only used for --convert-layout.
The full qualified class name of a look and feel that will be used for layout manager conversion. This is useful if the old layout manager uses units that depend on the look and feel (e.g. FormLayout dialog units). Default is the system look and feel.
--format=<JFDML|XML> Only used for --convert-jfd.
The target format into which the .jfd files will be converted. Default is "JFDML".
--encoding=<encoding> Only used for --convert-jfd.
The encoding used to store JFDML content. See java.nio.charset.Charset for supported encodings. Defaults is "UTF-8".
--header-comment=<headerComment> Only used for --convert-jfd.
A comment that is stored in the header of the converted .jfd files. May contain "\n", which is converted to real newline character.
<project-path>/MyProject.jfdproj Optional JFormDesigner stand-alone edition project used to extend the classpath and to specify other preferences. 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.

The options and parameters are processed in the order they are passed. An option is always used for subsequent parameters, but not for preceding ones. E.g. "src1 --recursive src2" processes src2 recursively, but not src1. It is also possible to specify options or projects more than once. E.g. "project1.jfdproj src1 project2.jfdproj src2" uses project1.jfdproj for src1 and project2.jfdproj for src2.

Using custom components

If you're using custom components (JavaBeans) in your forms, it is necessary to tell the command-line tool the classpath of your components, because e.g 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 command-line tool. 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).

Examples

Generate code for a single form:

cd C:\MyProject
java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar
    com.jformdesigner.application.CommandLineMain
    --generate 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.CommandLineMain
    --generate --recursive src

Externalize strings in all forms of the src folder and use one bundle file per form and no key prefix:

cd C:\MyProject
java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar
    com.jformdesigner.application.CommandLineMain
    --i18n-externalize --recursive
    --bundle-name={package}.{basename} --key-prefix=
    MyProject.jfdproj src

Convert all usages for FormLayout to MigLayout in all forms of the src folder:

cd C:\MyProject
java -classpath C:\ProgramFiles\JFormDesigner\lib\JFormDesigner.jar
    com.jformdesigner.application.CommandLineMain
    --convert-layout
    --old-layout=com.jgoodies.forms.layout.FormLayout
    --new-layout=net.miginfocom.swing.MigLayout
    --lookandfeel=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
    --recursive
    MyProject.jfdproj src

Ant

Although we don't provide a special task for Ant, it is easy to invoke the JFormDesigner command-line tool 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.CommandLineMain"
        fork="true" failonerror="true" logError="true">
    <classpath>
        <pathelement location="${jfd-install-dir}/lib/JFormDesigner.jar"/>
        <pathelement location="myLibrary.jar"/>
    </classpath>
    <arg value="--generate"/>
    <arg value="--recursive"/>
    <arg value="src"/>
</java>