Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages accessible from more than one module due to GWT SDK from Eclipse plugin #10051

Closed
RemiFermentin opened this issue Dec 3, 2024 · 11 comments

Comments

@RemiFermentin
Copy link

RemiFermentin commented Dec 3, 2024

**GWT version: 2.12.1
**Browser (with version): N/A
Operating System: MACOS


Description

I have an error on some package since I try to move from java 8 to java 17.

In fact, i compile good through my gradle commands (so I build correctly the project)... But i still have many errors on Eclipse.
I have some errors like:
The package javax.xml.parsers is accessible from more than one module: , java.xml

The main Reason of that this is because on gwt-dev.jar that is included in the GWT SDK from the eclipse plugin. It contains it.

Of course the GWT SDK is in the classpath for the project... and then, I have this error... (as it goes through a conflict)

I am pretty sure somebody ran into this at some point, but i didn't have any clues at the moment.

The easiest solution would be to trick my "gwt-dev.jar" to remove the unnecessary classes but that's not a suitable way to do in the long run...
(like doing:
zip -d gwt-dev.jar "org/w3c/" "org/xml/" "javax/xml/" "netscape/javascript/"
)

If it is possible to exclude during runTime the "xerces" group from the gwt-dev.jar, that would be great, but as it is inside the "SDK" I cannot manipulate as I would like to. (it is not installed through a "normal" Gradle implmentation).

I have some gradle command to "install the SDK" automatically through gradle task (I use "org.wisepersist.gwt" version "1.1.19"):

eclipse {
	project {
		natures 'com.gwtplugins.gwt.eclipse.core.gwtNature'
		buildCommand 'com.gwtplugins.gwt.eclipse.core.gwtProjectValidator'
		buildCommand 'com.gwtplugins.gdt.eclipse.core.webAppProjectValidator'
	}
	classpath {
		containers 'com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER'
	}
	synchronizationTasks gwtpluginsGdtCorePrefs
}
task gwtpluginsGdtCorePrefs() {
	doLast {
		// Create GWT eclipse settings
		delete("${project.projectDir}/.settings/com.gwtplugins.gdt.eclipse.core.prefs")
		File corePrefs = file("${project.projectDir}/.settings/com.gwtplugins.gdt.eclipse.core.prefs")
		corePrefs.getParentFile().mkdirs()
		if (corePrefs.exists()) {
			logger.warn("GWT core preferences already exist and will not be overridden. Use task 'cleanEclipse' first.")
		} else {
			corePrefs.write('eclipse.preferences.version=1\n')
			corePrefs.append('jarsExcludedFromWebInfLib=\n')
			corePrefs.append('warSrcDir=\n')
			corePrefs.append('warSrcDirIsOutput=true\n')
		}
	}
}

Happy to know if someone has any idea :)

@niloc132
Copy link
Member

niloc132 commented Dec 3, 2024

Can you clarify when/how you get those errors? Is it from the eclipse plugin, or from running the gradle build, and if so, can you share logs and the full stack trace?

There is no GWT 2.11.2, can you clarify which version you are using?

@RemiFermentin
Copy link
Author

Sorry, I type wrong, GWT 2.12.1

THe, error, is it from Eclipse directly. It saying I have a compile error:

In my import javax.xml.parsers.*;

The package javax.xml.parsers is accessible from more than one module: , java.xml

No error on my builds command from the gradle build.

Like I said, it comes the "" module comes from the gwt-dev.jar that includes the package as well which generates the conflict.

Again sorry, to say it again, If I remove those close from the gwt-dev.jar (included in the Eclipse GWT Plugin) Everything is working fine but I don't like to trick the tool by removing classes :/

@RemiFermentin
Copy link
Author

Adding a screenshot
image

@niloc132
Copy link
Member

niloc132 commented Dec 3, 2024

This looks like server code, and those packages are only shaded into gwt-dev.jar or gwt-user.jar, not one of the servlet/server jars. The non-servlet/server jars must not be present on your server classpath - this includes gwt-dev.jar and gwt-user.jar. Allowing those to be present in your server classpath may shadow some "real" classes, and prevent your own classpath from working correctly.

I believe this is doubly important if you support jpms modules in your server , as you've discovered, since gwt-dev.jar at this time doesn't respect those boundaries, but instead tries to ship a complete classpath. Using the unnamed module may resolve this - but I strongly urge you to remove gwt-user and gwt-dev from your server classpath.

I can only find org.w3c.dom in gwt-user, but cannot find javax.xml nor org.xml.sax in any GWT jars in the maven distributed jars. That is to say, you can also somewhat simplify this by getting dependencies (and transitive dependencies) from maven, rather than the GWT SDK jars which include some dependencies internally.

@RemiFermentin
Copy link
Author

RemiFermentin commented Dec 3, 2024

So in other words, you tell me to remove the SDK from my classpath right?
Screenshot 2024-12-03 at 16 37 17

@RemiFermentin
Copy link
Author

Here last input for you,
the issue comes from net.sourceforge.htmlunit:neko-htmlunit . Here attached one depedency I saw on 2.11.0 (didn't run it through 2.12.1 but as i have the same issue on both version, likely same thing).

image

@niloc132
Copy link
Member

niloc132 commented Dec 3, 2024

Client and server code should not be on the same classpath, the same source directories, the same project. Client dependencies apply to client projects, and server dependencies to server projects. There are a number of good reasons to do this, and this has been the suggestion for new projects (though the GWT Plugin for Eclipse has come under new management, and this part hasnt been updated yet I believe.

Using JPMS is an optional feature for Java projects, and results in the error you are seeing, but only if classpaths are mixed in this way. If you want to use Java modules, you will need to have a modularized project, or apply specific javac/java args to manage exports/opens/etc to allow this.

Regardless of how you decide to manage this, please ensure that neither gwt-dev nor gwt-user are in your deployed server classpath.


Your last screenshot seems to show that you are using maven, as well as the GWT sdk (but not from maven). I suggest picking one and using it, rather than letting your CI, prod, cli builds use maven, and your IDE builds use eclipse.

@RemiFermentin
Copy link
Author

I agree to all above you are saying. We did d split front and back end but didnt put in place module yet.

Again my issue is not the client/server packaging but the interaction with Eclipse GWT PLuging as it seems the pluging give me additional classes that create dependencies issue.

But now, there is another issue when i remove the GWT SDK. i have tthis error:

The project 'webapp' does not have any GWT SDKs on its build path.
image

Only to get rid of is to Remove the flag "Use GWT"... but then, I cannot compile from the gwt eclipse plugin anymore :/.

So best practise is to remove the sdk because it contains gwt-dev and gwt-user... (and gwt-dev has too much dependency on java.xml) but I somehow need it so that the gwt plugin is functional?

any idea here?

@niloc132
Copy link
Member

niloc132 commented Dec 3, 2024

At this point, I think you should consider moving this to https://github.com/gwt-plugins/gwt-eclipse-plugin/ - there might be a setup issue, or a bug with the plugin. But removing GWT from the server project should not prevent the client project from still having GWT enabled, using the version of your choice, and compiling from the plugin.

@RemiFermentin
Copy link
Author

Ok, I start to get it now, yes I think i'll move over there.

I saw: gwt-plugins/gwt-eclipse-plugin#414 which might be related or very close to my issue BUT I don't see how to fix that.

I'll recreate there and close this one

@RemiFermentin
Copy link
Author

gwt-plugins/gwt-eclipse-plugin#504 - follow up FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants