我导入了一个Maven项目,它使用了Java 1.5,尽管我将1.6配置为我的Eclipse默认值Preferences->Java->Installed JREs
.
当我改变Maven项目以使用1.6 JRE时,它仍然存在从项目使用Java 1.5时遗留的构建错误(我在前面描述了这些构建错误:我在m2eclipse中构建错误但在命令行上没有使用maven2 - 我的m2eclipse是否配置错误?)
我要删除该项目并再次尝试,但我想确保这次它从一开始就使用Java 1.6来查看是否可以消除构建问题.
如何在导入项目时确保项目使用Java 1.6?
我正在使用IntelliJ IDEA Ultimate 2019.3.1。每当我尝试启动任何简单的 Java Maven 项目(甚至可能是一个简单的 Hello World)时,我都会收到以下错误:
Error:java: error: release version 5 not supported
Run Code Online (Sandbox Code Playgroud)
java --version
通过终端运行我得到以下输出:
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.1)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.1, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)
javac --version
通过终端运行我得到以下输出:
javac 11.0.5
Run Code Online (Sandbox Code Playgroud)
要在Java编译器的设置(如建议在这里)我看到这一点:
我尝试将“目标字节码版本”编辑为1.8,但出现以下错误:
Error:(1, 26) java: package javafx.application does not exist
Error:(2, 20) java: package javafx.stage does not exist
Error:(4, 27) java: cannot find symbol
symbol: class Application
Error:(12, 23) java: cannot …
Run Code Online (Sandbox Code Playgroud) 使用JDK/12 EarlyAccess Build 10,JEP-325 Switch Expressions已作为JDK中的预览功能集成.表达式的示例代码(如在JEP中一样):
Scanner scanner = new Scanner(System.in);
Day day = Day.valueOf(scanner.next());
switch (day) {
case MONDAY, TUESDAY -> System.out.println("Back to work.") ;
case WEDNESDAY -> System.out.println("Wait for the end of week...") ;
case THURSDAY,FRIDAY -> System.out.println("Plan for the weekend?");
case SATURDAY, SUNDAY -> System.out.println("Enjoy the holiday!");
}
Run Code Online (Sandbox Code Playgroud)
在哪里Day
作为一个枚举
public enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
Run Code Online (Sandbox Code Playgroud)
该预览语言和VM特点JEP-12已经阐述了如何功能可以编译和使用运行时期间启用javac
和java
.
如何使用Maven试用这个功能?
我正在尝试编译我的maven
项目,Java 10
但我遇到了麻烦.在我的IDE(IntelliJ IDEA
)中,所有内容都编译并运行得很好Java 10
.我安装了最新maven
版本3.5.4
并指出JAVA_HOME
了JDK 10
:
$ mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Maven\bin\..
Java version: 10.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-10.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Run Code Online (Sandbox Code Playgroud)
maven
我使用的命令是:
mvn package -Dmaven.test.skip
Run Code Online (Sandbox Code Playgroud)
在我,pom.xml
我有以下Java 8
工作正常:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<libraries.directory>libraries</libraries.directory>
</properties>
Run Code Online (Sandbox Code Playgroud)
因为Java 10
我把它改成了以下内容:
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target> …
Run Code Online (Sandbox Code Playgroud) 我不确定最新版本的eclipse即Oxygen是否支持java 10.我从我的mac机器上的首选项配置了Java 10的JRE.
另外,我尝试将maven编译器插件添加到我的pom.xml中: -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
<compilerVersion>10</compilerVersion>
<fork>true</fork>
<executable>/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home</executable>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
设置运行配置后我也尝试了如下: -
有人知道我怎么能让它适用于java-10.
我尝试运行以下代码: -
public class App {
public static void main(String[] args) {
var list = new ArrayList<String>();
System.out.println("Hello World!");
}
}
Run Code Online (Sandbox Code Playgroud)
更新: -我在评论中应用了建议的补丁,但仍然失败.
截图如下: -
另外,我按照这篇文章进行编译.所以,编译实际上是从eclipse(maven install
)工作的,但是当我尝试运行应用程序时它仍然失败.
我正在从 Java 8 迁移到 Java 11 并遇到了这个问题。我应该使用:
但是在启动时不断出现错误:
合并bean定义后处理失败;嵌套异常是 java.lang.NoSuchMethodError: javax.annotation.Resource.lookup()Ljava/lang/String;
我找到了多种方法来修复它。尝试添加依赖项:
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
尝试添加扩展名:
<extensions>
<extension>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</extension>
</extensions>
Run Code Online (Sandbox Code Playgroud)
这些都没有帮助。
这是 maven-compiler-plugin 配置:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
请帮忙寻找解决办法!!
我在Windows 10上运行Eclipse 2018-09(4.9.0).我正在使用Open JDK 11 GA.我有一个Maven项目被指定为使用Java 8源代码.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
在命令行上使用Maven 3.5.3编译很好.使用Eclipse Eclipse 2018-09(4.9.0)编译也很好.
我将编译Java版本更改为Java 11:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
使用Maven 3.5.3在命令行上仍然可以正常构建.但是在Eclipse 2018-09中,我在整个地方都遇到了错误:
'<>' operator is not allowed for source level below 1.7
Constructor references are allowed only at source level 1.8 or above
Default methods are allowed only at source level 1.8 or above
你明白了.
我已经习惯Alt+F5
在Eclipse中更新我的Maven项目(和子项目).我做了一个完整的清洁和重建.
因为这在命令行上使用Maven编译得很好,这必然是一个Eclipse问题,不是吗?当然,Eclipse不支持所有新的Java 11功能,但此代码没有Java 11特定功能.怎么了?
我使用了JoséPeredaMaven方法,它在NetBeans中运行良好,但是当我尝试使用"java -jar mavenproject1-1.0-SNAPSHOT-jar-with-dependencies.jar"在外面运行时,我收到以下错误
"错误:JavaFX缺少运行时组件,并且需要运行此应用程序
"md.mavenproject1.MainApp"只是一个临时名称,而我试图解决这个问题.
我的pom文件看起来像:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>md</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mavenproject1</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>md.mavenproject1.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11-ea+25</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11-ea+25</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>11</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1.1</version>
<!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions> …
Run Code Online (Sandbox Code Playgroud) 我知道这听起来可能像这个或其他一些的重复,但请耐心听我说。
我有一个非常基本的 JAX-RS 资源,添加了我在本教程中看到的所有必需注释,我在此处遵循。
但我不断HTTP Status 500
在 Eclipse 控制台中收到以下日志输出。
Mar 18, 2021 1:35:23 AM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/xml, type=class com.varun.demorest.model.User, genericType=class com.varun.demorest.model.User.
Run Code Online (Sandbox Code Playgroud)
使用 Maven,但即使在添加了我在类似问题上找到的大多数建议后,我发现它大部分已经包含在
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.varun</groupId>
<artifactId>demorest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demorest</name>
<build>
<finalName>demorest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use …
Run Code Online (Sandbox Code Playgroud) 我有一个用 Java 11 编写的简单应用程序。mvn clean verify
(maven 3.6.0)执行时出错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project parser: Compilation failure
[ERROR] ...src/main/java/module-info.java:[2,32] module not found: org.apache.logging.log4j
Run Code Online (Sandbox Code Playgroud)
依赖项:
<log4j.version>2.11.1</log4j.version>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
模块信息.java:
module abc {
requires org.apache.logging.log4j;
}
Run Code Online (Sandbox Code Playgroud)
Log4j2 配置是默认的并且在 .xml 文件中。用法:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
private static final Logger logger = LogManager.getLogger(Abc.class);
logger.info("Boom!");
Run Code Online (Sandbox Code Playgroud)
我在 stackoverflow 上尝试了所有相关问题,但没有成功。