The MyBatis Generator feature includes a custom launcher for running MyBatis generator. The launcher leverages Eclipse's launch support and enables you to create any number of custom launches. The launcher has far more capability than the previous popup menu action. Further, the launch support does not alter the Eclipse IDE classpath - which could happen inadvertently with the prior popup menu action.
While a code generation is running, the Eclipse progress view will show the progress of the generation run. The launch will also create a new MyBatis Generator console view that shows status messages and any warnings from the run. If you configure logging to log to the console, then logging messages will also be in the MyBatis Generator console.
On this page we will cover some of the technical internals of the launcher. We assume you are familiar with how the Eclipse launch support works in general. If you are not familiar with Eclipse launching, just know that launch configurations can be accessed with the Run>Run Configurations... or Run>Debug Configurations... menu options.
The launcher allows you to add entries to the runtime classpath of the launch. Classpath entries should be added for the following things:
The launcher will automatically add the Java project containing the configuration file to the classpath.
Adding entries to the launcher classpath is generally preferable to using
a <classPathEntry>
configuration element in the generator
configuration file. However, if you use a dependency JAR that relies on native code
(such as some DB2 drivers) it would be better to use the
<classPathEntry>
configuration element. This because native
code can only be loaded by a single classloader and it is likely that
the generator classloader will be garbage collected before the launch classloader.
If you launch in debug mode, rather than run mode, the launcher will launch Ant in debug mode and will log all messages to a the MyBatis Generator console. This can be useful when using an SQL script as you will be able to see the script progress in the console. You will also see many Ant configuration messages.
Currently the launcher does not support breakpoints in dependent projects. If you are developing a plugin you may add the plugin project to the launcher classpath and the plugin will be executed, but any breakpoints set in plugin code will be ignored. This is a limitation of Ant support.
Internally the launcher uses the MyBatis Generator Ant task to run the generator. The launcher creates an Ant build script based on attributes in the launch configuration and then uses Eclipse's Ant support to run the script.
The launch configuration allows you to specify a SQL script to run before the generator is run. This can be useful when using in-memory databases and is used during testing of the feature. Running a SQL script is accomplished by using Ant's built in SQL task to run a script you specify. See the Ant documentation for details about the capabilities of the SQL task.
If you specify a password for connecting to a database with the Ant script, you have options on how that password is stored.
If you select the check box specifying that credentials should be stored in secure storage, then the user ID and password will be stored in Eclipse's internal secure storage system. The password will be encrypted using Eclipse's default support. The password will be in clear text in the generated Ant script while the launch is running, but the generated Ant file will be deleted after the launch completes.
If you do not select the check box specifying that credentials should be stored in secure storage, then the user ID and password will be stored in clear text in the Eclipse launch configuration. The password will also be in clear text in the generated Ant script while the launch is running, and the generated Ant file will not be deleted after the launch completes.
Launch configuration files are stored in
<workspace-directory>/.metadata/.plugins/org.eclipse.debug.core/.launches
The generated Ant files are stored in
<workspace-directory>/.metadata/.plugins/org.mybatis.generator.eclipse.ui/.generatedAntScripts