我在通过shell命令运行jar时遇到问题,因为我不断收到“找不到或加载主类错误”
将jar文件放入我的服务器后。我执行以下命令
java -jar mapr.jar
但是我收到一条错误消息-无法找到或加载主类
下面是我的项目结构-
mapreduce (projectname)
--src/main/java
--mapreduce (packagename)
--Map.java
--ZipProcessor.java (main Class)
和我的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>com.project.hadoop</groupId>
<artifactId>mapreduce</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MapReduce</name>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-common</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
<build>
<finalName>mapr</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>ZipProcessor</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
我使用以下插件解决了问题
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>
com.application.ZipProcessor
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
答案 0 :(得分:3)
<manifest>
<mainClass>ZipProcessor</mainClass>
</manifest>
应完成以上对主类的声明,包括包名和类名。
如果您的软件包名称是 com.test.processor ,并且您的类名称是 App ,则上述主类声明应如下:
<manifest>
<mainClass>com.test.processor.App</mainClass>
</manifest>
希望这可以解决您的问题。