wmdvanzyl
wmdvanzyl

Reputation: 362

Java project runs in IDE (IntelliJ Idea) but fails to run after Maven build

I have a Java project that is ready to ship, but i have stumbled at the last hurdle. The program runs fine in the IDE, but after i run mvn clean install and the target jar is created successfully, the application fails both on the command line AND in the IDE. I can get it to run again in the IDE by doing a rebuild from within the IDE.

Has anyone else experienced something similar?

The error after the mvn clean install is

2014-08-08_10:38:20.328 INFO  coza.modh.fxplatform.Controller - Application start
2014-08-08_10:38:20.344 INFO  c.m.f.c.p.DataSourceFactory - Connecting to Database.
2014-08-08_10:38:20.499 INFO  coza.modh.fxplatform.Controller - Model created
Exception in thread "main" java.lang.NullPointerException
    at coza.modh.fxplatform.view.MainView.<init>(MainView.java:46)
    at coza.modh.fxplatform.Controller.startup(Controller.java:40)
    at coza.modh.fxplatform.Application.main(Application.java:7)

The line it fails on looks like this:

setContentPane(contentPane);

If i rebuild from within the IDE then the variable is not null when it gets here, but after the mvn command the variable is null when it gets to this point.

EDIT: Someone pointed out that it might be related to the fact that i used the intelliJ GUI designer tools and that Maven might not gel with it. Possibility?

Upvotes: 1

Views: 2335

Answers (4)

Reg
Reg

Reputation: 11255

I had a similar problem today. To solve the issue -

Firstly, add the following to the pom.xml

<dependency>
   <groupId>com.intellij</groupId>
   <artifactId>forms_rt</artifactId>
   <version>5.0</version>
</dependency>

Secondly, as you stated, use the correct maven plugin to create the build.

See this for step by step instruction.

Upvotes: 2

kAmol
kAmol

Reputation: 1389

  • Install Maven on the system(not having IDE) before running the code
  • ensure you've got system property M2_HOME set to your Maven installation location and also Maven bin folder added to PATH
  • go to the directory,containing pom.xml of your project and type "mvn install" plus Enter to build your project

  • if it's for example simple project,packaged as JAR,you can run it then by typing something like this in the console:

$ java -cp target/simple-1.0-SNAPSHOT.jar org.yourcompany.projectNam.App and Enter

Upvotes: 0

Konrad H&#246;ffner
Konrad H&#246;ffner

Reputation: 12217

This can be caused by different library versions, do you have changed the build path in Eclipse? (Project->Properties->Build Path -> Libraries). There should only be "JRE System Library". If there is more, then it is possible that it is be loaded instead of one of your Maven dependencies. You using "mvn clean install" means it is compiled against the Maven dependencies and thus it runs differently.

Upvotes: 0

Joop Eggen
Joop Eggen

Reputation: 109613

Unlikely that contentPane is null, but check. Do a clean build anyway. Maybe the line number is not entirely correct.

Normally the problem are resources, like an application icon.

  • They are not File but zipped inside the jar. So paths like /src/main/resources/... will not do.
  • Neiter using a backslash \, and
  • furthermore the file paths are case sensitive.

Upvotes: 0

Related Questions