Gio*_*ato 7 java jpa java-9 module-info
我正在使用需要JPA(javax.persistence.*类)的项目来测试Java 9 .当我添加module-info.java并声明我的模块时,javax.persistece包下的所有类都变得不可用.
我搜索了很多,但我找不到要求在Java 9模块项目中使用JPA的模块.
更新 正如艾伦建议的那样,我跑了
$ jar --describe-module --file=javax.persistence-api-2.2.jar
No module descriptor found. Derived automatic module.
java.persistence@2.2 automatic
requires java.base mandated
contains javax.persistence
contains javax.persistence.criteria
contains javax.persistence.metamodel
contains javax.persistence.spi
Run Code Online (Sandbox Code Playgroud)
但仍然有这个 module-info.java
module my.module {
requires java.persistence;
}
Run Code Online (Sandbox Code Playgroud)
我找不到"module-info.java:[3,18]模块:java.persistence".
更新2 这是我的项目结构:
.
??? pom.xml
??? src
??? main
? ??? java
? ? ??? my
? ? ? ??? module
? ? ? ??? MyBean.java
? ? ??? module-info.java
? ??? resources
??? test
??? java
??? resources
Run Code Online (Sandbox Code Playgroud)
该pom.xml有javax.persistence-api依赖.
使用maven,您可以使用依赖项
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
与maven-compiler-plugin更新一起使用jdk9 详细说明.
与依赖gradle相似
compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
Run Code Online (Sandbox Code Playgroud)
它基于javaee/jpa-spec.这将有利于
requires java.persistence
Run Code Online (Sandbox Code Playgroud)
添加到详细信息,这在META-INF/MANIFEST.MF中定义为:
Manifest-Version: 1.0
Bundle-Description: Java(TM) Persistence 2.2 API jar
Automatic-Module-Name: java.persistence
...
Run Code Online (Sandbox Code Playgroud)
注意 - 根据Alan的建议找出模块名称的方法是准确的,但没有广告,我仍然更喜欢使用某个类的一个类,然后让IntelliJ(2017.2.4)为我说'导入类'然后'添加要求'.;)
| 归档时间: |
|
| 查看次数: |
2675 次 |
| 最近记录: |