S.Lee
S.Lee

Reputation: 236

Java 11 compile error: Package xxx exists in another module

There is a class in my project. This class in package javax.swing extends javax.swing.JOptionPane because I want to use some protected methods of JOptionPane.

When the compiler is JDK 8 it works fine. I update the JDK version to 11 then I've got a compile error: Package 'javax.swing' exists in another module: java.desktop.

My IDE is Intellij idea. I opened the Settings--Build,Execution,Deployment--Java Compiler and added an item to 'Override compiler parameters pre-module'. The Module is my project. The compilation options is

--patch-module java.desktop=src -d mypatches/java.desktop/src/java.desktop/javax/swing/Top.java

But it does not work.

My project tree is 'GreatProject/src/javax/swing/Top.java'.

What's the 'src -d' means?

What's the right '--patch-module'?

Upvotes: 4

Views: 9935

Answers (1)

Egor Klepikov
Egor Klepikov

Reputation: 5829

Starting from Java 9 version, full support for the jigsaw project was added to ensure the project's modularity. This system can cause problems at the compile process if the same names are present in packages.

  • Please, check this topic about the module patching process to adapt your module for javax.swing package.

  • Also, you may try to use Reflection API for getting elements from 'JOptionPane' class.

Upvotes: 1

Related Questions