我是Java新手,这是我第一次使用Maven。我试图通过将我读过的各种东西拼接在一起并将它们复制并粘贴到pom.xml来构建一个有效的pom.xml文件。这不起作用。
我把我的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
如何设置主类?
答案 0 :(得分:3)
类名区分大小写。您的班级名为Main
,因此清单应为:
<manifest>
<mainClass>com.ollio.nlp.Main</mainClass>
</manifest>