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

References to internal com.sun.* packages in simpleclient_httpserver #533

Open
albsch opened this issue Feb 26, 2020 · 11 comments
Open

References to internal com.sun.* packages in simpleclient_httpserver #533

albsch opened this issue Feb 26, 2020 · 11 comments

Comments

@albsch
Copy link

albsch commented Feb 26, 2020

The HTTPServer.java class (in simpleclient_httpserver) references internal com.sun.* packages, which makes the server unsable for modern Java build setups:

import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpExchange;

Starting the server results in the exception:

java.lang.NoClassDefFoundError: com/sun/net/httpserver/HttpHandler

Tested with simpleclient_httpserver v0.8.1 and openjdk version "12.0.2" 2019-07-16 on a Jigsaw Java project.

Similar to issue #478.

@albsch albsch changed the title References to internal com.sun.* packages in simplehttp_httpserver References to internal com.sun.* packages in simpleclient_httpserver Feb 26, 2020
@brian-brazil
Copy link
Contributor

How do you propose keeping this working while still supporting Java 6?

@albsch
Copy link
Author

albsch commented Feb 26, 2020

I don't know. Is support for newer Java releases planned while providing support for Java 6? I'm interested to know if I can use this dependency in the near future with up to date Java versions.

@brian-brazil
Copy link
Contributor

I hope to support newer versions also, however Java has been going out of its way to make breaking changes.

@llech
Copy link

llech commented Sep 25, 2020

Java 6 is not supported since 2013 :O

@shea-hawkins
Copy link

Same here. Works in some places but this is pretty broken.

@shea-hawkins
Copy link

shea-hawkins commented Oct 26, 2020

@brian-brazil The problem is that you're assuming com.sun is part of the JDK running the code, which isn't guaranteed. To fix this, it can be included as a transitive dependency.

Mostly:

Don't treat com.sun.xxx packages as if they're part of the standard library. Oracles java distribution may the most common, but it isn't the only one.

https://stackoverflow.com/questions/30134507/cannot-use-com-sun-net-httpserver-java-8

You can also switch to the apache http core, which is open-source and won't have different behaviors depending on the distribution of JDK you use (Oracle vs AdoptOpen vs Open) https://hc.apache.org/

@brian-brazil
Copy link
Contributor

To fix this, it can be included as a transitive dependency.

How does one do this?

You can also switch to the apache http core

3rd party dependencies are purposefully avoided in the library where we don't strictly need them, to avoid potential conflicts with dependencies an application itself may have.

@shea-hawkins
Copy link

@brian-brazil this may be a case where you strictly need them. The only dependency on central that I can find for this library is this unofficial one: https://mvnrepository.com/artifact/com.sun.net.httpserver/http/20070405

@brian-brazil
Copy link
Contributor

Are you saying that the standard Java 8 JREs come with no builtin HTTP server? That doesn't sound right at all.

@dhoard
Copy link
Collaborator

dhoard commented Sep 14, 2021

sun.* packages are Oracle-specific and may not exist on non-Oracle JDKs/JREs. Code that calls sun.* packages is technically not 100% Java compliant.

Reference: https://www.oracle.com/java/technologies/faq-sun-packages.html

@ylz-at
Copy link

ylz-at commented Sep 22, 2021

Getting the same error when trying to use it on Android.

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

7 participants
@brian-brazil @ylz-at @dhoard @llech @albsch @shea-hawkins and others