Problems with maven while using intelij idea gui designer.

I have a form created via gui designer using
It works fine, but when I create jar file of maven project, I can't run it.
Exception in thread "main" java.lang.NullPointerException
 at MainForm.<init>(
 at Main.main(

when I put content of constructor in comments it says:

Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
 at javax.swing.JRootPane.setContentPane(
 at javax.swing.JFrame.setContentPane(
 at Main.main(

What is the problem? Why it's null?

Comment actions Permalink


Basically the problem is that IDEA compiles GUI forms with its own so-called javac2 compiler, that inserts GUI initialization code into the resulted class files. You create jar with Maven, it has no such compiler, so resulted classes have no such code.

There is no IDEA Maven plugin for javac2, only an ant task. So, the solution could be to run an ant script using javac2 as a part of Maven build.

For the sample of javac2 ant task usage you can execute main menu / Build / Generate And Build with option "Enable UI forms compilation", then you'll get the ant script and may check how javac2 usage may look.

As an experiment, I have integrated such ant script into a Maven build. It looks dirty, but maybe shows the idea:

                    <dependency> <!-- A hack for this problem: -->
                                <property name="IDEA.home" value="C:/JetBrains/IDE X/132.0461-u"/> <!-- My IDEA home. -->
                                <path id="j2cp">
                                    <pathelement location="${IDEA.home}/lib/asm.jar"/>
                                    <pathelement location="${IDEA.home}/lib/asm4-all.jar"/>
                                    <pathelement location="${IDEA.home}/lib/javac2.jar"/>
                                    <pathelement location="${IDEA.home}/lib/jdom.jar"/>
                                    <pathelement location="${IDEA.home}/lib/jgoodies-forms.jar"/>
                                <path id="j2sp">
                                    <pathelement location="${project.basedir}\src\main\java"/> <!-- Maybe finer paths could be defined. -->
                                <taskdef name="javac2" classpathref="j2cp" classname="com.intellij.ant.Javac2"/>
                                <javac2 destdir="${project.basedir}\target\classes"> <!-- Maybe finer paths could be defined. -->
                                    <src refid="j2sp"/>


Comment actions Permalink

And what about in the case of Build Server?

It not contains a IDE installation.


Please sign in to leave a comment.