Can I exclude an exported package from a Java module?

我怕爱的太早我们不能终老 提交于 2019-12-19 02:59:30

问题


Modules jta and java.sql export package javax.transaction.xa to module dom4j

As you can see, both modules jta and java.sql export the same package, javax.transaction.xa. However, the package in jta has classes that I require that are not present in java.sql. I would simply not require the java.sql module, but I need java.sql.SQLException.

Is it possible to prevent java.sql from exporting javax.transaction.xa?


回答1:


The JTA GitHub reads the following in confirmation to what @Alan already pointed out in a comment -

This standalone release of Java(TM) Java Transaction API (JTA), uses a Java Platform Module System "automatic" module name of java.transaction, to match the module name used in JDK 9. A future version will include full module metadata. Moreover javax.transaction.xa package is now owned by Java SE.

You can use the version with Maven(e.g) using :-

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.3</version>
</dependency>

Here is the release notes for JTA1.3MR.


Additionally the JEP 320: Remove the Java EE and CORBA Modules elaborates on the same -

... The javax.transaction.xa package supports XA transactions in JDBC. This "XA package" is co-located with JDBC in the java.sql module in Java SE 9. Because the java.sql module is not upgradeable, it is not possible for a standalone version of JTA to override the Java SE version of the XA package

and to further note for extensibility in your solution

...For ease of maintenance, the XA package in Java SE may be moved to a different non-upgradeable module in the future, but as an architectural matter it will remain in Java SE alongside JDBC for the long term...

and as planned

In early 2018, JTA 1.3 will be defined to consist of just the CORBA interop package; the JAR file will be updated accordingly.




回答2:


You could use javac -d -cp /PATHTOYOURFILE -d and -cp flags to compile only required directories and classpath. Classpath can also be comma seperated.



来源:https://stackoverflow.com/questions/51004100/can-i-exclude-an-exported-package-from-a-java-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!