如何为maven项目设置类路径

How to set classpath for a maven project

我用 eclipse 创建了一个 maven 项目,并用下面的命令从中生成了 jar 文件

mvn 包

当我尝试使用此命令了解我的 mvn 项目配置是否正确时

mvn exec:java -D exec.mainClass="giraph.helloworld.App"

我收到这个错误:

failed to execute goal
org.codehaus.mojo:exec-maven-plugin:1.2.1:java(default-cli) on project helloworld: An exception occured while executing the java class. null: InvocationTargetException: No arguments were provided

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>giraph</groupId>   
    <artifactId>helloworld</artifactId>  
    <version>0.0.1-SNAPSHOT</version>   
    <packaging>jar</packaging>

    <name>helloworld</name>   
    <url>http://maven.apache.org</url>

    <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>            
     </properties>

    <dependencies>      
    <dependency>
        <groupId>org.apache.giraph</groupId>
        <artifactId>giraph-core</artifactId>
        <version>1.1.0</version>    
    </dependency>       
    <dependency>    
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-compiler-plugin</artifactId>  
        <version>2.0.2</version>    
    </dependency>       
   <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.2.1</version>
   </dependency>    
   <dependency>     
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-surefire-plugin</artifactId>  
    <version>2.10</version>
   </dependency>  
 </dependencies>
 <build> 
   <plugins>
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
        <execution>
          <goals>
            <goal>java</goal>
          </goals>
         <configuration>
           <mainClass>giraph.helloworld.App</mainClass>
         </configuration>
        </execution>
       </executions>
     </plugin>
  </plugins>
 </build> 
</project>

我认为问题在于您的清单文件不包含有关您的 jar 入口点(主要 class)的信息。参见 Setting an Application entry point

有很多方法可以纠正这个问题。您可以使用 Maven 程序集插件。有关详细信息,请查看 here