Eclipse Developers - Problems with Java Modules

361 views
Skip to first unread message

ma...@makr.zone

unread,
Apr 6, 2023, 8:24:43 AM4/6/23
to OpenPnP
Hi all,

Eclipse Developers might encounter problems with Java Modules, now that we use a more modern Java platform (errors see below).

I was able to resolve it like that:
  1. Exit Eclipse.
  2. Open the .settings/org.eclipse.jdt.core.prefs file inside your openpnp git directory.
  3. Add the following line:
    org.eclipse.jdt.core.compiler.ignoreUnnamedModuleForSplitPackage=enabled
  4. Restart Eclipse.
  5. Maven / Update Project ... (or Alt-F5).
Source:
https://stackoverflow.com/a/74890645/15218951

_Mark

Annex, errors:

Eclipse Module errors.png

The package javax.xml.transform.sax is accessible from more than one module: <unnamed>, java.xml    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 11    Java Problem
The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 10    Java Problem
The package org.xml.sax.helpers is accessible from more than one module: <unnamed>, java.xml    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 24    Java Problem
The package org.xml.sax is accessible from more than one module: <unnamed>, java.xml    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 22    Java Problem
The package org.xml.sax is accessible from more than one module: <unnamed>, java.xml    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 23    Java Problem
XMLReader cannot be resolved to a type    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 49    Java Problem
XMLReaderFactory cannot be resolved    EagleLoader.java    /openpnp/src/main/java/org/openpnp/model/eagle    line 49    Java Problem


Niclas Hedhman

unread,
Apr 6, 2023, 10:05:43 AM4/6/23
to ope...@googlegroups.com

I think, this is related to the Java Module System that was introduced
in Java 9. And if I am not mistaken, the "override/work-around" flag
that you use is a) only for the Eclipse compiler (I assume that they
still haven't moved to the OpenJDK compiler) and b) the option was
announced to be removed in a later Java edition, to force the eco-system
towards compliance with the module system.

Niclas

On 2023-04-06 14:24, ma...@makr.zone wrote:
> Hi all,
>
> Eclipse Developers might encounter problems with Java Modules, now
> that we use a more modern Java platform (errors see below).
>
> I was able to resolve it like that:
>
> * Exit Eclipse.
> * Open the .settings/org.eclipse.jdt.core.prefs file inside your
> openpnp git directory.
>
> * Add the following line:
> org.eclipse.jdt.core.compiler.ignoreUnnamedModuleForSplitPackage=enabled *
> Restart Eclipse.
> * Maven / Update Project ... (or Alt-F5).
>
> Source:
> https://stackoverflow.com/a/74890645/15218951
>
> _Mark
>
> Annex, errors:
>
> --
> You received this message because you are subscribed to the Google
> Groups "OpenPnP" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to openpnp+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/openpnp/2f44b631-9742-4c3e-8583-d4bdf9dcefa9n%40googlegroups.com
> [1].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/openpnp/2f44b631-9742-4c3e-8583-d4bdf9dcefa9n%40googlegroups.com?utm_medium=email&utm_source=footer

Mark

unread,
Apr 6, 2023, 11:37:27 AM4/6/23
to ope...@googlegroups.com

Hi Niclas,

frankly, this is all way over my head. 😅

But please read the link I provided, which points out that there is a rather relevant (but not legally binding) spec document saying:

> If a package is defined in both a named module and the unnamed module then the package in the unnamed module is ignored.

The javac (compiler) is behaving according to this document, and still does after many years and many JDK versions. Using the said option makes Eclipse behave the same way as javac.

For an IDE to behave the same way as the compiler sounds rather convincing to me. 😎

Now, it is clear that it would probably be better to make OpenPnP into a proper module itself. Although frankly, I really don't see why you should be forced to explicitly use a new, complex concept that in itself has (to my knowledge) absolutely no merit for our use case. If this is true, then the above sounds like a reasonable implicit default behavior.

But again, this is all over my head. 😇

_Mark

Niclas Hedhman

unread,
Apr 6, 2023, 2:01:50 PM4/6/23
to ope...@googlegroups.com
On 2023-04-06 17:37, Mark wrote:
> But please read the link I provided [1], which points out that there
> is a rather relevant (but not legally binding) spec document saying:
>
> _> __If a package is defined in both a named module and the unnamed
> module then the package in the unnamed module is ignored._
>
> The javac (compiler) is behaving according to this document, and still
> does after many years and many JDK versions. Using the said option
> makes Eclipse behave the same way as javac.

I don't follow the Java Spec discussions as much as I used to, but
already from the start, this behavior was said to be "transitionary",
and I vaguely recall that they recently announced that javac will start
transitioning to be strict(er). So maybe Eclipse is slightly ahead of
the curve to nudge people away from it.

> For an IDE to behave the same way as the compiler sounds rather
> convincing to me. 😎

:-) That's funny, because in the early days, the Microsoft Java IDE and
compiler were more Specification compliant than the Sun javac compiler,
especially when detecting errors.

> Now, it is clear that it would probably be better to make OpenPnP into
> a proper module itself. Although frankly, I really don't see why you
> should be _forced _to explicitly use a new, complex concept that in
> itself has (to my knowledge) absolutely no merit for our use case.

It is very simple in reality. I can take a look during Easter and see if
there is anything problematic. Typically only a matter of a module file,
and IntelliJ (don't know about Eclipse) will more or less do the job
(Intentions).


Cheers
Niclas

Mark

unread,
Apr 6, 2023, 2:08:09 PM4/6/23
to ope...@googlegroups.com

> It is very simple in reality. I can take a look during Easter and see if there is anything problematic.

Yes, please! 😁

Tao Qu

unread,
Apr 9, 2023, 4:22:30 AM4/9/23
to ope...@googlegroups.com
Hi Mark
Thank you very much for the perfect solution to the problem that has plagued me for a long time.
Well Done.png

ma...@makr.zone <ma...@makr.zone> 于2023年4月6日周四 20:24写道:
--
You received this message because you are subscribed to the Google Groups "OpenPnP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpnp+u...@googlegroups.com.

Niclas Hedhman

unread,
Apr 9, 2023, 12:19:33 PM4/9/23
to ope...@googlegroups.com

UPDATE;
I have spent ~5-6 hours on the issue and I think it is no longer worth
more time.

a. OpenPNP depends on a fair amount of artifacts that are not Java 9
enabled. That is normally not an issue, as default module names are
derived from jar names. However, it requires that separate jars are not
using the same package names. This exists in com.google.zxing where
"core" and "javase" has shared names. But the 2 classes that OpenPnp
uses in the latter, can simply be copied into openpnp itself (its own
package) and all is good.

b. Other issue was around the onvif dependency, which Jason has
repackaged. A simple
Automatic-Module-Name: de.onvif
in the Manifest and that is ok.

c. The OpenCV dependency, which is an openpnp project as well, is
messing around with the internals of classloaders. And Java 9 is not
happy about that;

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make
field private static java.lang.String[] java.lang.ClassLoader.usr_paths
accessible: module java.base does not "opens java.lang" to module opencv

I don't know for sure that the java.lang package can be opened, but if
so, then that should happen in the openpnp/opencv project. And not
knowing how many other issues in the serialization system that would
surface if I fix this, I have decided to cut the losses and not pursue
it further.


Summary; When dependencies are not "Java 9 Ready", then it is a lot
harder to make one's project "Java 9 Ready".

Niclas


On 2023-04-06 20:08, Mark wrote:
> _> It is very simple in reality. I can take a look during Easter and
> see if there is anything problematic. _
> --
> You received this message because you are subscribed to the Google
> Groups "OpenPnP" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to openpnp+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/openpnp/8ac47f61-7a38-37f0-5564-62751e97eaae%40makr.zone
> [1].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/openpnp/8ac47f61-7a38-37f0-5564-62751e97eaae%40makr.zone?utm_medium=email&utm_source=footer

markmaker

unread,
Apr 9, 2023, 12:46:04 PM4/9/23
to ope...@googlegroups.com, Niclas Hedhman
Reply all
Reply to author
Forward
0 new messages