Problems with maven while using intelij idea gui designer.

I have a form created via gui designer using http://www.jetbrains.com/idea/training/demos/GUI_Designer/GUI_Designer.html.
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>(MainForm.java:14)
 at Main.main(Main.java:13)

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(JRootPane.java:603)
 at javax.swing.JFrame.setContentPane(JFrame.java:671)
 at Main.main(Main.java:13)

What is the problem? Why it's null?



Attachment(s):
pom.xml
MainForm.java.zip
MainForm.form.zip
2 comments

Hello.

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:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <dependencies>
                    <dependency> <!-- A hack for this problem: http://stackoverflow.com/questions/2022622/java-home-gets-mangled-by-maven -->
                        <groupId>com.sun</groupId>
                        <artifactId>tools</artifactId>
                        <version>1.7.0</version>
                        <scope>system</scope>
                        <systemPath>${java.home}/../lib/tools.jar</systemPath>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <configuration>
                            <tasks>
                                <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>
                                <path id="j2sp">
                                    <pathelement location="${project.basedir}\src\main\java"/> <!-- Maybe finer paths could be defined. -->
                                </path>
                                <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"/>
                                </javac2>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Regards,
Alexander.

0

And what about in the case of Build Server?

It not contains a IDE installation.

0

Please sign in to leave a comment.