Java 9 弃用了六个包含Java EE API的模块,它们将很快被删除:
javax.activation
包的java.activationjavax.activity
,javax.rmi
,javax.rmi.CORBA
,和org.omg.*
包javax.transaction
包的java.transactionjavax.xml.bind.*
包的java.xml.bindjavax.jws
,javax.jws.soap
,javax.xml.soap
,和所有javax.xml.ws.*
包javax.annotation
包的java.xml.ws.annotation哪些维护的第三方工件提供了这些API?它们提供这些API或它们必须提供的其他功能并不重要 - 重要的是,它们是这些模块/包的直接替代品吗?
为了更容易收集知识,我回答了迄今为止我所知道的并将答案作为社区维基.我希望人们能够扩展它,而不是写出自己的答案.
在您投票结束之前:
关于Java 9中的非法反射访问存在很多问题.
现在我找不到的是因为所有谷歌都在努力解决错误信息,实际上是非法的反射访问.
所以我的问题很简单:
什么定义非法反射访问以及什么情况触发警告?
我已经收集到它与Java 9中引入的封装原则有关,但它们如何挂在一起以及什么触发警告在什么情况下我找不到解释.
需求和需要模块声明中的传递模块语句有什么区别?
例如:
module foo {
requires java.base;
requires transitive java.compiler;
}
Run Code Online (Sandbox Code Playgroud) 我正在调试为什么在module-info.java
我的Spring Boot应用程序中,spring-orm
在启动时抛出异常.这是例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/UserTransaction
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.beans@5.0.8.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar:na]
at spring.context@5.0.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.8.RELEASE.jar:na]
at spring.context@5.0.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.8.RELEASE.jar:na]
at spring.context@5.0.8.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.8.RELEASE.jar:na]
at spring.boot@2.0.4.RELEASE/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:na]
at spring.boot@2.0.4.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:na]
at spring.boot@2.0.4.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:na]
at spring.boot@2.0.4.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:na]
at spring.boot@2.0.4.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:na]
at spring.boot@2.0.4.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:na]
at tech.flexpoint.dashmanserver/tech.flexpoint.dashmanserver.DashmanServerApplication.main(DashmanServerApplication.java:13) [classes/:na] …
Run Code Online (Sandbox Code Playgroud) java java-platform-module-system spring-boot java-10 java-module
我正在尝试使用Java9(JDK9)运行DMelt程序(http://jwork.org/dmelt/)程序,它给了我错误,例如:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Run Code Online (Sandbox Code Playgroud)
我该如何解决?我试图将-illegal-access = permit添加到脚本"dmelt.sh"的最后一行(我在Linux中使用bash),但这并没有解决这个问题.我很沮丧.我经常使用这个程序很长一段时间.也许我永远不应该转向JDK9
我的JDK 9 + 181 Spring Boot 2.0.0.BUILD-SNAPSHOT CLI应用程序在启动时显示此警告:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (jar:file:/home/jan/src/fm-cli/target/fm-cli-0.1.0-SNAPSHOT.jar!/BOOT-INF/lib/spring-core-5.0.0.RELEASE.jar!/) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
Run Code Online (Sandbox Code Playgroud)
这是一个控制台应用程序,所以我需要禁用此警告 - 我该怎么做?
注意:此问题询问如何禁用Spring触发此警告的具体问题; 它不是JDK9的副本:发生了非法的反射访问操作.org.python.core.PySystemState,用于处理不同库中的类似症状.
JDK-11将删除JDK的许多旧部分(JEP-320).对于其中一些(例如JAXB),功能将作为常规库提供.您只需添加另一个依赖项,一切正常.
但对于CORBA则不然,因为
使用Java中的CORBA开发现代应用程序没有太大的兴趣
然而,我仍然处于痛苦的境地,需要维护仍旧需要CORBA的旧应用程序,同时仍希望更新到JDK-11.
在没有删除这些应用程序的CORBA功能的情况下,是否有替换库或迁移到JDK-11的另一种好方法?
假设我有一个使用Maven 3和junit的Java项目.有src/main/java
和src/test/java
目录分别包含主要来源和测试来源(一切都是标准的).
现在我想将项目迁移到Java 9. src/main/java
内容代表Java 9模块; 有com/acme/project/module-info.java
看大约是这样的:
module com.acme.project {
require module1;
require module2;
...
}
Run Code Online (Sandbox Code Playgroud)
如果测试代码需要module-info.java
自己怎么办?例如,添加对某些模块的依赖性,该模块仅用于测试,而不是生产代码.在这种情况下,我必须把module-info.java
以src/test/java/com/acme/project/
给模块不同的名称.这样Maven似乎将主要源和测试源视为不同的模块,因此我必须将包从主模块导出到测试模块,并且需要测试模块中的包,如下所示:
主模块(in src/main/java/com/acme/project
):
module prod.module {
exports com.acme.project to test.module;
}
Run Code Online (Sandbox Code Playgroud)
测试模块(in src/test/java/com/acme/project
):
module test.module {
requires junit;
requires prod.module;
}
Run Code Online (Sandbox Code Playgroud)
这产生了
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project test-java9-modules-junit: Compilation failure: Compilation failure:
[ERROR] /home/rpuch/git/my/test-java9-modules-junit/src/test/java/com/acme/project/GreeterTest.java:[1,1] package exists in another module: prod.module
Run Code Online (Sandbox Code Playgroud)
因为一个包在两个模块中定义.所以现在我必须在主模块和测试模块中有不同的项目,这是不方便的.
我觉得我走错了道路,一切都开始看起来非常难看.如何module-info.java
在测试代码中拥有自己的代码,或者如何在没有测试代码的情况下实现相同的效果(require …
由于新的模块系统,Java 9(jdk-9 + 170)默认情况下不允许应用程序查看JDK中的所有类,这与以前的所有Java版本不同.
要解决此问题,java
命令行会提供一个新参数--add-exports
,允许按如下方式中断封装:
java -jar josm.jar --add-exports java.base/sun.security.util=ALL-UNNAMED --add-exports java.base/sun.security.x509=ALL-UNNAMED
这在JEP 261中得到了很好的解释.
我已经阅读了--add-opens
使用相同语法的类似选项,但是JEP 261尚未更新来描述它(最后更新:2017/03/08 13:58).
这两个选项有什么区别?
编辑:JEP 261已在2017-09-22更新以解释它.
java command-line-arguments java-platform-module-system java-9 java-module
假设我有一个带groupId = org.abc
和的库artifactId = myLibrary
.模块名称的推荐名称是什么:myLibrary
或org.abc.myLibrary
?是否有任何命名方案的官方指南?
java ×10
java-module ×10
java-9 ×8
java-platform-module-system ×2
spring-boot ×2
corba ×1
java-10 ×1
java-11 ×1
java-ee ×1
junit ×1
maven ×1
module-info ×1
requires ×1
spring ×1