I'm trying to familiarise myself with Java 9's module system and have come across something I can't immediately see how to resolve.
I have a Maven project that has dependencies on both JDK9's java.sql
and hibernate-core
(5.2.11.Final). Hibernate transitively pulls in jboss-transaction-api_1.2_spec
. Both that jar and the java.sql
module contain the package: java.transaction.xa
, therefore the compiler throws a load of these errors at me:
Error:java: the unnamed module reads package javax.transaction.xa from both jboss.transaction.api.1.2.spec and java.sql
I thought I'd resolved this by doing this:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-entitymanager.version}</version>
<exclusions>
<exclusion>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<groupId>org.jboss.spec.javax.transaction</groupId>
</exclusion>
</exclusions>
</dependency>
However, though it compiles it later throws this exception at runtime:
Caused by: java.lang.ClassNotFoundException: javax.transaction.SystemException
It turns out that javax.transaction.SystemException
is in the excluded jboss-transaction-api_1.2_spec
dependency, so I can't exclude it. But neither can I not depend on java.sql
which contains java.sql.DataSource
which I also use!
How do I resolve this problem of a module and .jar ('Automatic module'?) containing two equivalently named packages, but containing different classes? Both of which I need!
EDIT
I took a look at Hibernate, Java 9 and SystemException but that seems to shift the problem, so now the compiler just complains about the same package in java.sql
and javax.transaction.api
Error:java: the unnamed module reads package javax.transaction.xa from both java.sql and javax.transaction.api
The crux of the problem is that the java.transaction.xa
package exists in both modules.
It seems this is a known problem, I can't see if there's any clear/easy resolution to it: