【发布时间】:2021-05-30 05:35:39
【问题描述】:
这是我第一次尝试 maven,我不明白为什么每次我尝试构建时都会收到 classnotfoundexception。这是我收到的错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< owmapi:owmapi >----------------------------
[INFO] Building OwmAPICase 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ owmapi ---
[WARNING]
java.lang.ClassNotFoundException: owmapi.Main
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:246)
at java.base/java.lang.Thread.run(Thread.java:832)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.582 s
[INFO] Finished at: 2021-02-28T14:09:17+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project owmapi: An exception occured while executing the Java class. owmapi.Main -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
这是我的 pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>owmapi</groupId> <!-- case.se.ctk -->
<artifactId>owmapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>OwmAPICase</name>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>owmapi.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.aksingh/owm-japis -->
<dependency>
<groupId>net.aksingh</groupId>
<artifactId>owm-japis</artifactId>
<version>2.5.3.0</version>
</dependency>
</dependencies>
</project>
如果我只是在 Eclipse 中将项目作为 java 应用程序运行,那么一切正常,但由于某种原因,它不适用于 maven。我想问题出在我的 pom 中的 mainClass 上,但我尝试了几种解决方案都无济于事。
【问题讨论】:
-
你能得到整个堆栈跟踪而不是几行。它有助于追踪真正的问题。
-
@KidusTekeste 抱歉,认为一切都不需要。我现在已经编辑了我的问题。
-
Main类的包是否与 pom 文件中的所有包一起正确定义?在 pom 配置的<mainClass></mainClass>内? -
或者只是
owmapi.Main你的正确包名?如果您留下了一些其他包名,请指定完整的包名。以防你没有添加完整的包。 -
@KidusTekeste 抱歉,我现在已经修好了,我没有意识到“Main”是类名的意思。好傻
标签: java maven exec-maven-plugin