Vin*_*ati 8 java maven java-10
我只是在我的mac机器上安装了JDK 10.检查版本: -
localhost:java-10 vinayprajapati$ java -version
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
Run Code Online (Sandbox Code Playgroud)
为了确保使用的编译器也是同一个版本,我运行如下: -
localhost:java-10 vinayprajapati$ javac -version
javac 10
Run Code Online (Sandbox Code Playgroud)
我创建了一个简单的Maven项目,其结构如下:
localhost:java-10 vinayprajapati$ tree
.
??? pom.xml
??? src
? ??? main
? ? ??? java
? ? ??? com
? ? ??? practice
? ? ??? java_10
? ? ??? App.java
? ??? test
? ??? java
? ??? com
? ??? practice
? ??? java_10
? ??? AppTest.java
??? target
Run Code Online (Sandbox Code Playgroud)
我的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.practice</groupId>
<artifactId>java-10</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>java-10</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我的App.java文件是: -
package com.practice.java_10;
import java.util.ArrayList;
public class App {
public static void main(String[] args) {
var list = new ArrayList<String>();
System.out.println("Hello Java 10! Shall I welcome you?");
}
}
Run Code Online (Sandbox Code Playgroud)
我跑了mvn compile,mvn install两个都成功了.证明如下: -
localhost:java-10 vinayprajapati$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.practice:java-10 >------------------------
[INFO] Building java-10 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ java-10 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/vinayprajapati/Desktop/project/java-10/java-10/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ java-10 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/vinayprajapati/Desktop/project/java-10/java-10/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.823 s
[INFO] Finished at: 2018-03-23T01:49:13+05:30
[INFO] ------------------------------------------------------------------------
localhost:java-10 vinayprajapati$ mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.practice:java-10 >------------------------
[INFO] Building java-10 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ java-10 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/vinayprajapati/Desktop/project/java-10/java-10/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ java-10 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ java-10 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/vinayprajapati/Desktop/project/java-10/java-10/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ java-10 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/vinayprajapati/Desktop/project/java-10/java-10/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ java-10 ---
[INFO] Surefire report directory: /Users/vinayprajapati/Desktop/project/java-10/java-10/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.practice.java_10.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.029 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ java-10 ---
[INFO] Building jar: /Users/vinayprajapati/Desktop/project/java-10/java-10/target/java-10-0.0.1-SNAPSHOT.jar
[INFO] META-INF/maven/com.practice/java-10/pom.xml already added, skipping
[INFO] META-INF/maven/com.practice/java-10/pom.properties already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ java-10 ---
[INFO] Installing /Users/vinayprajapati/Desktop/project/java-10/java-10/target/java-10-0.0.1-SNAPSHOT.jar to /Users/vinayprajapati/.m2/repository/com/practice/java-10/0.0.1-SNAPSHOT/java-10-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/vinayprajapati/Desktop/project/java-10/java-10/pom.xml to /Users/vinayprajapati/.m2/repository/com/practice/java-10/0.0.1-SNAPSHOT/java-10-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.157 s
[INFO] Finished at: 2018-03-23T01:49:22+05:30
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
跑步时mvn exec:java -Dexec.mainClass="com.practice.java_10.App",我收到如下错误: -
localhost:java-10 vinayprajapati$ mvn exec:java -Dexec.mainClass="com.practice.java_10.App"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.practice:java-10 >------------------------
[INFO] Building java-10 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ java-10 ---
[WARNING]
java.lang.Error: Unresolved compilation problem:
var cannot be resolved to a type
at com.practice.java_10.App.main (App.java:11)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:282)
at java.lang.Thread.run (Thread.java:844)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.019 s
[INFO] Finished at: 2018-03-23T01:51:02+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project java-10: An exception occured while executing the Java class. Unresolved compilation problem:
[ERROR] var cannot be resolved to a type
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我会收到此错误.欢迎任何想法.同时我尝试寻找根本原因.
您必须将运行时插件设置为Java 10或根配置.现在它只是编译器.
| 归档时间: |
|
| 查看次数: |
3394 次 |
| 最近记录: |