3.2.2. Configuring IntelliJ IDEA
For optimal use of MetaFactory with IntelliJ some configuration is required.
Plugin configuration
3.2.2.2. Resolving XML errors
When opening a MetaFactory pattern.xml, the namespace and schemalocation will be marked in red, as shown in the screenshot below:
Todo
Update namespaces in text and images
![../_images/IntelliJPatternXmlError-768x613.png](../_images/IntelliJPatternXmlError-768x613.png)
Now move your cursor to the red marked namespace and press ALT-ENTER to resolve the issue. Choose the option “Manually setup external resources”.
![../_images/IntelliJPatternFixXmlError-768x613.png](../_images/IntelliJPatternFixXmlError-768x613.png)
Subsequently navigate to the MetaFactory installation folder and select the right XSD in the support sub folder.
![../_images/IntelliJExternalResourceSelection.png](../_images/IntelliJExternalResourceSelection.png)
..rubric:: Namespaces**
file |
namespace |
xsd |
---|---|---|
metafactory.xml |
personal-iom-project.xsd |
|
pattern.xml |
pattern.xsd |
|
model.xml |
model.xsd |
3.2.2.3. Live Templates
In order to use the live templates with MetaFactory you need to copy the file Freemarker.xml from the support/idea folder of the installation path to the ‘Settings’ folder of IntelliJ.
OSX |
~/Library/Preferences/IntelliJIdea14/templates/Freemarker.xml |
Windows |
<user_home>/.IntelliJIdea14/config/templates/Freemarker.xml |
If the folder ‘templates’ does not exist, please create it.
The result will look as follows:
![../_images/IntelliJLiveTemplates-730x768.png](../_images/IntelliJLiveTemplates-730x768.png)
3.2.2.4. Implicit objects in Freemarker or Velocity templates
MetaFactory places a number of objects inside the context of Freemarker or Velocity. IntelliJ will need to know about these objects so that the error messages such as the ones shown below will disappear:
![../_images/IntelliJUnknownObjects-768x277.png](../_images/IntelliJUnknownObjects-768x277.png)
The first step to achieve this is to add 2 jars from the MetaFactory installation as a Global Library inside the project:
![../_images/IntelliJAddGlobalLibrary-768x735.png](../_images/IntelliJAddGlobalLibrary-768x735.png)
Add metafactory-api-<version>.jar, jdom2-<version>.jar and commons-lang3-<version>.jar as a Global Library.
Copy the files freemarker_implicit.ftl and velocity_implicit.vm from the support/idea sub folder of the MetaFactory installation to the snippets section of the MetaFactory project.
After copying these files to the sources root of IntelliJ they will be automatically detected and used. Whether the sources root is located at the module level or as a sub folder of that depends on the module. In some cases sources root doesn’t exist yet at all, then the directory will have to be explicitly marked as such:
![../_images/IntelliJMarkDirectoryAsSourcesRoot-608x768.png](../_images/IntelliJMarkDirectoryAsSourcesRoot-608x768.png)
When all of this has been done, the error messages will disappear from the Freemarker en Velocity editor
and auto complete can now be used on its objects.