我尝试在Maven中执行Hello World,但在执行mvn compile
时无法正常工作:
我的来源:
我对maven的错误:
我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
<source>9</source>
<target>9</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我的档案:
Greeter.java:
package hello;
public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
HelloWorld.java
package hello;
public class HelloWorld {
public static void main(String[] args) {
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
编辑:
我的java版本:
openjdk 9
OpenJDK Runtime Environment (build 9+181)
OpenJDK 64-Bit Server VM (build 9+181, mixed mode)
My Maven版本:
Apache Maven 3.5.0 (NON-CANONICAL_2017-04-10T13:56:20+03:00_root; 2017-04-10T12:56:20+02:00)
Maven home: /opt/maven
Java version: 9, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-9-openjdk
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "4.13.7-1-arch", arch: "amd64", family: "unix"
我尝试更改pom.xml,但结果相同......
我不知道为什么会出错?
答案 0 :(得分:0)
尝试通过在<plugins>
部分
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
</configuration>
</plugin>