[英]Could not find or load main class : Executable JAR from Maven
I am trying to create an executable JAR from Maven with maven-assembly-plugin. 我正在尝试使用maven-assembly-plugin从Maven创建可执行JAR。 My Jars are getting created but without my source code.
正在创建我的Jar,但是没有我的源代码。 I have already mentioned goal as single in POM and creating jar with this command: "
mvn clean package assembly:single
". 我已经在POM中提到了目标,并使用以下命令创建jar:“
mvn clean package assembly:single
”。 But I am still getting this error: "Error: Could not find or load main class com.som.bau.report.MainClass". 但是我仍然收到此错误:“错误:找不到或加载主类com.som.bau.report.MainClass”。
Please see below my POM.xml 请在下面查看我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>VFIE_SOM_BAU_Report</groupId>
<artifactId>SOM_BAU_Report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<jdk.version>1.7</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.som.bau.report.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Dependencies code goes here ---!>
</dependencies>
</project>
You should append packaging type to root element. 您应该将包装类型附加到根元素。
...
<modelVersion>4.0.0</modelVersion>
<groupId>VFIE_SOM_BAU_Report</groupId>
<artifactId>SOM_BAU_Report</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
...
I found the solution for it. 我找到了解决方案。
Need to add this tag under build tag. 需要在build标签下添加此标签。
<sourceDirectory>src</sourceDirectory>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.