1

In Eclipse I am using JavaFX, Maven with jre 1.8.0_45.

Normally, when I try to compile with Maven this way (Run As -> Maven compile) it will throw an error for not using the jdk.

When I change it to jdk (everywhere like in configuration, window - properties, maven configuration) and try to run/build/compile/whatever I get the error

Error: Could not find or load main class

Without giving me any class up there. Just this.

I kind o' fixed this by adding to my pom the path to javac and staying with the jre package

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler.version}</version>
    <configuration>

        <!-- With JRE: -->
        <fork>true</fork>
        <executable>C:\Program Files\Java\jdk1.8.0_45\bin\javac.exe</executable>

        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
</plugin>

This works.

But still I wish to know - why is this error happening? What am I doing wrong?

I've used Project -> Clean and Maven -> Update. Restarted Eclipse many times. Closed and opened the project. My Main class is given in my Run Configuration (application.Main).

EDIT:

Resolved. Answered my (own) question below.

Isaiah Alchemoth
  • 61
  • 1
  • 1
  • 6

5 Answers5

2

Hey Pleased set the path environment variable mentioning the installtion path of java.

https://www.java.com/en/download/help/path.xml

1

Could not find or load main class HelloWorldApp.class

A common mistake made by programmers is to try and run the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java HelloWorldApp. Remember, the argument is the name of the class that you want to use, not the filename.

Resource Link:

  1. https://docs.oracle.com/javase/tutorial/getStarted/problems/
  2. https://bbs.archlinux.org/viewtopic.php?id=187463
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • I've already answered your comment in my post. `@SkyWalker, I am familiar with this topic. In command line everything's ok. My error is just Error: Could not find or load main class. No actual class given.` I don't see this as an answer to my problem for now. Perhaps you should read my op, I am using Eclipse. :) – Isaiah Alchemoth Apr 12 '16 at 09:27
  • @IsaiahAlchemoth http://stackoverflow.com/questions/29920434/maven-adding-mainclass-in-pom-xml-with-the-right-folderpath and http://stackoverflow.com/questions/2022032/building-a-runnable-jar-with-maven-2- you can go through this. Hope it will clarify your knowledge about classpath related issue. – SkyWalker Apr 12 '16 at 09:59
1

I managed to resolve the problem.

What I did was a uninstall and a clean install of jdk, a clean install of eclipse and all eclipse plugins I was using.

Possible reasons for the problem:

  1. Some path problem and/or confusion in jdk/jre versions. @Lokesh Nandanwar was close.
  2. Some kind of eclipse problem, don't know what though

Thank you for your answers. Usually this is a CLASSPATH problem, but not this time.

Conclusion is:

If the Error is "Could not find or load main class SomeMainClass.class" you have a classpath problem or have not used java(c) command line properly. See @SkyWalker 's suggestions.

In Eclipse "refreshment" is needed. Close and open the project, clean the project, etc. With Maven+Eclipse the reason could be wrong path to Main class given in the POM file.

If the error is just "Could not find or load main class", something's messed up with the environment.

Isaiah Alchemoth
  • 61
  • 1
  • 1
  • 6
0

I also ran into same issue. by default JRE libraries are also added under libraries tab in "Buildpath panel of project properties in eclipse. still it was giving me same error when I build application as standalone java application. But later I found that JRE is not checked under "Order and Export" tab (next to the libraries tab). So, I just checked it and build application. it is working now.

sanket patel
  • 489
  • 1
  • 4
  • 7
0

One of the reasons can be : Mistakenly you have added multiple version of JRE system Library.