client_java
client_java copied to clipboard
References to internal com.sun.* packages in simpleclient_httpserver
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.
How do you propose keeping this working while still supporting Java 6?
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.
I hope to support newer versions also, however Java has been going out of its way to make breaking changes.
Java 6 is not supported since 2013 :O
Same here. Works in some places but this is pretty broken.
@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/
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.
@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
Are you saying that the standard Java 8 JREs come with no builtin HTTP server? That doesn't sound right at all.
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
Getting the same error when trying to use it on Android.