2015-06-16 70 views
2

我是Java新手,這是我第一次使用Maven。我試圖通過將我讀過的各種東西拼接在一起並將它們複製並粘貼到pom.xml來嘗試構建一個工作pom.xml文件。這不起作用。Maven無法爲我的Java應用程序找到'main'類

我把我的java文件在此文件夾中:

src/main/java/com/ollio/nlp/ 

我的主類是在這裏:

src/main/java/com/ollio/nlp/Main.java 

其包:

package com.ollio.nlp; 

的代碼是巨大的,太多了在這裏重複,但類開始正常的方式:

public class Main { 

    public static void main(String...args){ 

我的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/maven-v4_0_0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.ollio.nlp</groupId> 
    <artifactId>nlp</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 

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

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

    <build> 
    <plugins> 

     <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <configuration> 
     <archive> 
     <manifest> 
      <mainClass>com.ollio.nlp.main</mainClass> 
     </manifest> 
     </archive> 
    </configuration> 
     </plugin> 

     <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <configuration> 
     <compilerArgument>-XDignore.symbol.file</compilerArgument> 
    </configuration> 
     </plugin> 

     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.4</version> 
     <configuration> 
      <!-- put your configurations here --> 
     </configuration> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>net.sf.supercsv</groupId> 
     <artifactId>super-csv</artifactId> 
     <version>2.0.0-beta-1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
     <version>3.0</version> 
    </dependency> 


    <dependency> 
     <groupId>edu.stanford.nlp</groupId> 
     <artifactId>stanford-corenlp</artifactId> 
     <version>3.5.2</version> 
    </dependency> 

    </dependencies> 

</project> 

如果我運行:

mvn package 

我看到一些錯誤,如:

[WARNING] Some problems were encountered while building the effective model for com.rollioapp.nlp:nlp:jar:1.0-SNAPSHOT 

[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 32, column 15 

[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 20, column 15 

但最終它說:

BUILD SUCCESS 

但如果我嘗試:

java -jar target/nlp-1.0-SNAPSHOT.jar   

我得到:

Error: Could not find or load main class com.ollio.nlp.main 

如何設置主類?

回答

3

類名區分大小寫。你的班級被稱爲Main,所以清單應該是:

<manifest> 
    <mainClass>com.ollio.nlp.Main</mainClass> 
</manifest> 
相關問題