开发者

Cannot find the main class after converting java project to maven

I have a very simple HelloWorld code in Java which works ok. I'm using Eclipse and trying to figure out how to import dependencies for a project with the maven2 eclipse plugin.

    public class testMavenDep {

        public static void main(String arg[]){
            System.out.println("Hello World");
        }
    }

However, when I right click on the project > configure > convert to maven project, and then try and run it gives me an error message saying...

Could not find the main class: testMavenDep.testMavenDep. Program will exit.

And the following in the console...

java.lang.NoClassDefFoundError: testMavenDep/testMavenDep Caused by: java.lang.ClassNotFoundException: testMavenDep.testMavenDep at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Exception in thread "main"

My pom file is...

<project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-    4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>testMavenDep</groupId>
  <artifactId>testMavenDep</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</pr开发者_Python百科oject>

My question is, for an already existing Java Project, what is the proper way to add maven dependencies? I can add the dependencies using the above method but I'm getting issues with it losing track of the main class. Thanks in advance!


What is the source folder that you are putting your main class in? By default, Eclipse puts it in src, but maven conventions are src/main/java. It could be that adding maven dependencies is changing your source folders so that your class is not compiled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜