Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » "The package javax.xml is accessible" error... but only in test classes?
"The package javax.xml is accessible" error... but only in test classes? [message #1849856] Fri, 04 February 2022 18:50 Go to next message
Dan Royer is currently offline Dan RoyerFriend
Messages: 9
Registered: May 2014
Junior Member
Hello, friends,

The project is https://github.com/MarginallyClever/Makelangelo-software in Java15 + Eclipse 2021-12 (4.22.0). After accepting a PR I am getting a lot of

The package javax.xml is accessible from more than one module: <unnamed>, java.xml


I use java.xml in application and in junit tests. The error appears ONLY in my test classes, not in my app classes. Nobody else involved seems to have this problem and I'm the only Eclipse user.

I have a src/main/java/module-info.java. JavaSE-15 is on the modulepath and Maven dependencies are on the classpath. Some of my dependencies are no longer supported and cannot be updated (org.kabeja). I'm not sure what is relevant to this bug, just trying to give all the information.

Naturally I tried refresh, then Maven update, then googled for a couple hours and I'm still stuck.

Do you know why I'm getting this error and what to do about it?

Thank you!

[Updated on: Fri, 04 February 2022 18:51]

Report message to a moderator

Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849858 is a reply to message #1849856] Fri, 04 February 2022 21:18 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 800
Registered: July 2009
Senior Member
I ran into this when I first started testing with post-java8 (java11). It's a little awkward to find the resolution to this, but the steps are "straightforward", at least.

In Java 9 and newer, it is invalid to include classes in the "java.xml.*" package in jar files other than the "legal" jar files for that package. In general, that's a bad thing to do, but now Java 9 protects you from it. I don't remember the details of how that works, but that's essentially what's happening.

What the error message is telling you is that some jar file, somewhere in your classpath, has one or more classes that are declared to be in the javax.xml.* package. At this point, you're wondering, ok, WHICH jar file has these offending classes?

Here's the straightforward, but potentially labor-intensive strategy for finding the jar file in question:

Do "Open Type". Enter "javax.xml." Look at the pages and pages of potential matches. You'll see that many of the instances are in the JDK. Your job at this point is to look at ALL the results, ignoring the ones in the JDK. For each one, check to see if the artifact on that line is a dependency of your project. You'll probably see "xml-apis" as one of them. Somewhere in that long list you're going to find an artifact that is one of your dependencies. You'll need to exclude that artifact from your dependencies, most likely a transitive exclusion.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849859 is a reply to message #1849858] Fri, 04 February 2022 23:03 Go to previous messageGo to next message
Dan Royer is currently offline Dan RoyerFriend
Messages: 9
Registered: May 2014
Junior Member
Hi David,

I found Navigate > Open Type and did as you said. Most lines end with [jdk-15.0.2] so those I ignored. All the rest are xml-apis-1.4.0.1.jar as you predicted.
IDK how to check if an artifact is a dependency.
Do I exclude it at the module-info.java level, or from Maven?

Thanks,
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849860 is a reply to message #1849859] Fri, 04 February 2022 23:25 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 800
Registered: July 2009
Senior Member
In Eclipse, while viewing the pom.xml, click on the "Dependency Hierarchy" tab. Enter the name of the artifact you want to check for in the filter field at the upper right. It will show where the artifact appears in the tree in the left box if it is a dependency, direct or transitive.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849861 is a reply to message #1849860] Fri, 04 February 2022 23:48 Go to previous messageGo to next message
Dan Royer is currently offline Dan RoyerFriend
Messages: 9
Registered: May 2014
Junior Member
Brilliant! That totally fixed it.

I traced it down to batik-all > xml-apis and excluded it from Maven. Everything works!

Now if I could just get these "name of automatic module ... is unstable" to go away....
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849863 is a reply to message #1849861] Sat, 05 February 2022 00:51 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 800
Registered: July 2009
Senior Member
For that one, probably would need more info here, or a new base note.

However, googling the common parts of that error message led me to this thread: https://github.com/npgall/cqengine/issues/237 . That might be useful.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849893 is a reply to message #1849863] Mon, 07 February 2022 18:00 Go to previous messageGo to next message
Dan Royer is currently offline Dan RoyerFriend
Messages: 9
Registered: May 2014
Junior Member
So the fix for batik-all worked for me but no one else on the team, who use IntelliJ or some other IDE. Not sure what to do now. Here's what I did.

		<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-xml -->
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>batik-all</artifactId>
			<version>1.14</version>
			<exclusions>
				<exclusion>
					<groupId>xml-apis</groupId>
					<artifactId>xml-apis</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849899 is a reply to message #1849893] Tue, 08 February 2022 00:40 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 800
Registered: July 2009
Senior Member
I'm not sure what you mean by this. The fix you put in is for the build, which is not IDE-specific. What was possibly IDE-specific was the strategy for finding the artifact(s) to exclude. Although I'm sure IntelliJ would have a similar strategy for finding these artifacts, that has no relation to the fix you put in.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849926 is a reply to message #1849899] Tue, 08 February 2022 18:20 Go to previous messageGo to next message
Dan Royer is currently offline Dan RoyerFriend
Messages: 9
Registered: May 2014
Junior Member
Then I don't understand, after identifying the offending package, how to fix it at the IDE level.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849930 is a reply to message #1849926] Tue, 08 February 2022 21:33 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 800
Registered: July 2009
Senior Member
You don't. You fix it in the pom.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849932 is a reply to message #1849930] Tue, 08 February 2022 23:24 Go to previous messageGo to next message
Dan Royer is currently offline Dan RoyerFriend
Messages: 9
Registered: May 2014
Junior Member
Now I'm more lost! lol I put my fix in the pom, you said "The fix you put in is for the build". so... how does one fix it for the IDE and not the build AND in the pom?
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1849933 is a reply to message #1849932] Tue, 08 February 2022 23:46 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 800
Registered: July 2009
Senior Member
I don't know how else to explain this. You have a BUILD problem, not an IDE problem. You can't fix this in the IDE because it's not an IDE problem. The ONLY way to fix this is to augment the pom.xml to exclude that transitive artifact. There is no way to fix this in the IDE.
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1856684 is a reply to message #1849933] Thu, 22 December 2022 14:19 Go to previous messageGo to next message
Timothy Eichfeld is currently offline Timothy EichfeldFriend
Messages: 3
Registered: December 2022
Junior Member
Hello,

I am having the same issue in eclipse with JRE19.
I removed all of the offending dependency issues, but still have a problem with org.w3c.dom (same issue as the javax)
All I have is a JAVA build, no POM (not a maven build)

The only thing referencing org.w3c.dom jar is the JDK-19.

How is this not an eclipse issue?
here is a link (remove the spaces): https: // i.stack.imgur.com / yd6k4.jpg

Please advise.

Thanks much,
-Timothy
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1856720 is a reply to message #1856684] Sat, 24 December 2022 12:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Is your Java project modular (i.e., does it have a module-info.java)? If so, you need to import the module containing org.w3c.dom:

https://docs.oracle.com/en/java/javase/19/docs/api/java.xml/org/w3c/dom/package-summary.html


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1856742 is a reply to message #1856720] Tue, 27 December 2022 22:27 Go to previous messageGo to next message
Timothy Eichfeld is currently offline Timothy EichfeldFriend
Messages: 3
Registered: December 2022
Junior Member
Hi Ed,

Thanks for having a look :)
No not modular, so no module-info. However, I did find that org.w3c.dom is referenced through batik, and batik was included in the referenced external-lib files.

As batik was not in the dependency list reported through eclipse (I actually did not see where it was used in code) so Types dependency would not find it. Problem was referencing jars not actually being used by code getting in the way.

Removing batik references allow me to build, but I still cannot get the UI enabled for some reason. I'm sure there is some other configuration/dependency that I have not wired up correctly.

If you are interested, the project I am trying to build is the latest WorldWind JAVA code. ( https : //github.com/NASAWorldWind/WorldWindJava )

Thanks much,
-Timothy
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1856748 is a reply to message #1856742] Wed, 28 December 2022 09:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
It looks like an interesting project! I don't see a pom.xml, nor a MANIFEST.MF, so I have no idea how this is being structured as an Eclipse Java project. I'm also not sure what you mean by "get the UI enabled"...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: "The package javax.xml is accessible" error... but only in test classes? [message #1856761 is a reply to message #1856748] Thu, 29 December 2022 13:34 Go to previous message
Timothy Eichfeld is currently offline Timothy EichfeldFriend
Messages: 3
Registered: December 2022
Junior Member
Hi Ed,

Right? There are individual mains as entry points, those bring up the worldwind 3D globe. I set to start from one of those to test.
I *think* I have it building and creating the worldwind.jar file... I will just have to wing it from here. if I can get the apis built and changed as I need for other work, I will call it success! It will make debugging more stressful - but if this work were easy, everyone would be doing it.
Previous Topic:cannot get remote repository refs
Next Topic:java plugin to see colors image on right side of the Color
Goto Forum:
  


Current Time: Thu Mar 28 16:40:11 GMT 2024

Powered by FUDForum. Page generated in 0.03786 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top