Eclipse配置项目为Maven问题
我创建了带有 Main 类和 public static void main 的简单项目 和 System.out.println("Hello world"); 配置为maven项目后。 在这个 main 不起作用之后:
java.lang.NoClassDefFoundError: main/Main
Caused by: java.lang.ClassNotFoundException: main.Main
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"
为什么会发生这种情况?如何修复? 谢谢。
I have created simple project with class Main and public static void main
and System.out.println("Hello world");
And after have configured as maven project.
After this main doesn't work:
java.lang.NoClassDefFoundError: main/Main
Caused by: java.lang.ClassNotFoundException: main.Main
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"
Why this happens? How to fix?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
maven 清除项目设置和源文件夹。
maven clear project settings and also source folder.
为什么不尝试使用 archetype,然后比较差异。
建议您选择原型 maven-archetype-simple
mvn archetype:generate -D archetypeGroupId=org.apache.maven.archetypes -D maven-archetype-simple -D groupId=com.mycompany.mygroup -D artifactId=myapp< /code>
将其导入到 eclipse 中,最好使用 m2eclipse 插件或
mvn eclipse:eclipse
生成 eclipse .project 文件等Why don't you try creating a simple project using an archetype, and then compare the differences.
Suggest you choose the archetype maven-archetype-simple
mvn archetype:generate -D archetypeGroupId=org.apache.maven.archetypes -D maven-archetype-simple -D groupId=com.mycompany.mygroup -D artifactId=myapp
The import it to eclipse using prefererably the m2eclipse plugin or
mvn eclipse:eclipse
to generate the eclipse .project files etc.