2

I am trying to run my program via the command line using Maven. The location of the class which starts everything off is projectFolder -> src -> frogger -> game -> MainMenu.java

I've tried running mvn evec:java and I am getting the following error:

[WARNING]
java.lang.ClassNotFoundException: frogger.game.MainMenu
    at java.net.URLClassLoader.findClass (URLClassLoader.java:466)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:566)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:499)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:281)
    at java.lang.Thread.run (Thread.java:844)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.510 s
[INFO] Finished at: 2019-12-17T17:50:48Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project mainProject: An exception occured while executing the Java class. frogger.game.MainMenu -> [Help 1]

I've already tried running mvn clean install then mvn exec:java as suggested in this thread: Class Not Found exception with exec-maven-plugin when run on Linux but the issue still persists.

I've also tried running mvn exec:java -D"exec.mainClass"="frogger.game.MainMenu" which I found elsewhere but it gave me the same issue as above.

EDIT: Managed to fix it by rearranging my folder structure to match src/main/java

mievvin
  • 55
  • 1
  • 7
  • You need to compile it before you can `exec` it... – Powerlord Dec 17 '19 at 18:41
  • @Powerlord would that be with the ``mvn compile`` command? I've just tried the sequence of ``mvn clean install`` -> ``mvn compile`` -> ``mvn exec:java`` and still the same issue – mievvin Dec 17 '19 at 18:45
  • @ArvindKumarAvinash I have yeah, I think that + my folder structure were the two main problems but it's fixed and working now, thanks for the help! – mievvin Dec 17 '19 at 23:39

1 Answers1

0

Do it as follows:

mvn -X clean install exec:java -Dexec.mainClass="frogger.game.MainMenu"
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110