标签: java-module

使用Java EE API替换已弃用的JPMS模块

Java 9 弃用了六个包含Java EE API的模块,它们很快被删除:

  • javax.activation包的java.activation
  • java.corbajavax.activity,javax.rmi,javax.rmi.CORBA,和org.omg.*
  • javax.transaction包的java.transaction
  • 包含所有javax.xml.bind.*包的java.xml.bind
  • java.xml.wsjavax.jws,javax.jws.soap,javax.xml.soap,和所有javax.xml.ws.*
  • javax.annotation包的java.xml.ws.annotation

哪些维护的第三方工件提供了这些API?它们提供这些API或它们必须提供的其他功能并不重要 - 重要的是,它们是这些模块/包的直接替代品吗?

为了更容易收集知识,我回答了迄今为止我所知道的并将答案作为社区维基.我希望人们能够扩展它,而不是写出自己的答案.


在您投票结束之前:

  • 是的,已经有一些关于单个模块的问题,这个问题的答案当然会复制这些信息.但AFAIK没有任何一点可以了解所有这些,我认为这些有很大的价值.
  • 提出图书馆建议的问题通常被认为是偏离主题的,因为"他们倾向于吸引自以为是的答案和垃圾邮件",但我不认为这适用于此.明确描述了一组有效的库:它们必须实现特定的标准.除此之外别无其他,所以我没有看到很多意见和垃圾邮件的风险.

java java-ee java-9 java-module

150
推荐指数
6
解决办法
5万
查看次数

什么是非法反射访问

关于Java 9中的非法反射访问存在很多问题.

现在我找不到的是因为所有谷歌都在努力解决错误信息,实际上是非法的反射访问.

所以我的问题很简单:

什么定义非法反射访问以及什么情况触发警告?

我已经收集到它与Java 9中引入的封装原则有关,但它们如何挂在一起以及什么触发警告在什么情况下我找不到解释.

java java-9 java-module

82
推荐指数
4
解决办法
7万
查看次数

需求和需要Java 9中的传递语句有什么区别?

需求需要模块声明中的传递模块语句有什么区别?

例如:

module foo {
    requires java.base;
    requires transitive java.compiler;
}
Run Code Online (Sandbox Code Playgroud)

java requires java-9 java-module module-info

54
推荐指数
3
解决办法
6606
查看次数

当module-info.java存在时,findResource("")返回null,为什么会这样?

我正在调试为什么在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

51
推荐指数
1
解决办法
1264
查看次数

JDK9:发生了非法的反射访问操作.org.python.core.PySystemState

我正在尝试使用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

java java-9 java-module

44
推荐指数
2
解决办法
6万
查看次数

org.springframework.cglib.core.ReflectUtils $ 1的非法反射访问

我的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,用于处理不同库中的类似症状.

java spring spring-boot java-9 java-module

40
推荐指数
3
解决办法
3万
查看次数

在JDK 11中是否有CORBA的替换库

JDK-11将删除JDK的许多旧部分(JEP-320).对于其中一些(例如JAXB),功能将作为常规库提供.您只需添加另一个依赖项,一切正常.

但对于CORBA则不然,因为

使用Java中的CORBA开发现代应用程序没有太大的兴趣

然而,我仍然处于痛苦的境地,需要维护仍旧需要CORBA的旧应用程序,同时仍希望更新到JDK-11.

在没有删除这些应用程序的CORBA功能的情况下,是否有替换库或迁移到JDK-11的另一种好方法?

java corba java-module java-11

35
推荐指数
3
解决办法
5787
查看次数

Java 9 + maven + junit:测试代码是否需要自己的module-info.java以及放置它的位置?

假设我有一个使用Maven 3和junit的Java项目.有src/main/javasrc/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.javasrc/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 junit maven java-9 java-module

32
推荐指数
2
解决办法
7404
查看次数

Java 9中--add-exports和--add-opens之间有什么区别?

由于新的模块系统,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

29
推荐指数
1
解决办法
9828
查看次数

我该如何命名我的Java 9模块?

假设我有一个带groupId = org.abc和的库artifactId = myLibrary.模块名称的推荐名称是什么:myLibraryorg.abc.myLibrary?是否有任何命名方案的官方指南?

java java-9 java-module

24
推荐指数
2
解决办法
3409
查看次数