The command-line tool allows you to run some commands (e.g. Java code generation) on many forms.
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.
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 transfered from the IDE.
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 usefull 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
.
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:
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 srcConvert 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
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>