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

Java 11 compatibility #4

Open
djechelon opened this issue Mar 2, 2022 · 2 comments
Open

Java 11 compatibility #4

djechelon opened this issue Mar 2, 2022 · 2 comments

Comments

@djechelon
Copy link

I am trying to build a Docker image of the Anychart server based on Java 11, which is LTS and better suited for security-critical scenarios unlike Java 8.

Here is my Dockerfile

FROM ubuntu AS phantomjs

RUN apt update && apt install wget -y

RUN wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
RUN tar -xjf phantomjs-2.1.1-linux-x86_64.tar.bz2

#RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz
#RUN tar -zxf geckodriver-v0.30.0-linux64.tar.gz

#RUN wget https://chromedriver.storage.googleapis.com/94.0.4606.41/chromedriver_linux64.zip
#RUN tar -zxf chromedriver_linux64.zip

RUN wget https://static.anychart.com/cdn/export-server/export-server.jar
RUN wget https://repo1.maven.org/maven2/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar
RUN wget https://github.com/AnyChart/export-server/blob/master/lib/org.eclipse.wst.xml.xpath2.processor_1.1.0.jar
RUN wget https://repo1.maven.org/maven2/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar
RUN wget https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-runtime/3.0.2/jaxb-runtime-3.0.2.jar
RUN wget https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api/3.0.1/jakarta.xml.bind-api-3.0.1.jar
#RUN wget http://www.jabylon.org/maven/org/eclipse/wst/xml/xpath2/processor/2.1.100/processor-2.1.100.jar

FROM openjdk:11-jre-slim

COPY --from=phantomjs /phantomjs-2.1.1-linux-x86_64 /usr/lib/
COPY --from=phantomjs /*.jar /app/
COPY settings.toml /app/
RUN ln -s /usr/lib/phantomjs-2.1.1-linux-x86_64 /usr/lib/phantomjs
RUN ln -s /usr/lib/phantomjs/bin/phantomjs /usr/bin/phantomjs

WORKDIR /app

CMD java -Dphantomjs.binary.path=/usr/bin/phantomjs -jar /app/export-server.jar -C /app/settings.toml

settings.toml

# can be "server" or "cmd"
mode = "server"
engine = "phantom"

[server]
port = 8081
host = "127.0.0.1"
allow-scripts-executing = true
log = "/var/log/export-server.log"

[server.sharing]
# MySQL settings
#port = 3306
#db = "shared_db"
#user = "export_server_user"
#password = "export_server_password"

[server.sharing.twitter]
# settings from twitter app settings for sharing in Twitter
#key = "key"
#secret = "secret"
#callback = "http://example.com/sharing/twitter_oauth"

The build succeeds, but I get a class error on startup

Exception in thread "main" java.lang.ExceptionInInitializerError

at java.base/java.lang.Class.forName0(Native Method)

at java.base/java.lang.Class.forName(Unknown Source)

at clojure.lang.RT.classForName(RT.java:2168)

at clojure.lang.RT.classForName(RT.java:2177)

at clojure.lang.RT.loadClassForName(RT.java:2196)

at clojure.lang.RT.load(RT.java:443)

at clojure.lang.RT.load(RT.java:419)

at clojure.core$load$fn__5677.invoke(core.clj:5893)

at clojure.core$load.invokeStatic(core.clj:5892)

at clojure.core$load.doInvoke(core.clj:5876)

at clojure.lang.RestFn.invoke(RestFn.java:408)

at clojure.core$load_one.invokeStatic(core.clj:5697)

at clojure.core$load_one.invoke(core.clj:5692)

at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)

at clojure.core$load_lib.invokeStatic(core.clj:5736)

at clojure.core$load_lib.doInvoke(core.clj:5717)

at clojure.lang.RestFn.applyTo(RestFn.java:142)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$load_libs.invokeStatic(core.clj:5774)

at clojure.core$load_libs.doInvoke(core.clj:5758)

at clojure.lang.RestFn.applyTo(RestFn.java:137)

at clojure.core$apply.invokeStatic(core.clj:650)

at clojure.core$use.invokeStatic(core.clj:5860)

at clojure.core$use.doInvoke(core.clj:5860)

at clojure.lang.RestFn.invoke(RestFn.java:436)

at export_server.core$loading__5569__auto____4031.invoke(core.clj:1)

at export_server.core__init.load(Unknown Source)

at export_server.core__init.<clinit>(Unknown Source)

at java.base/java.lang.Class.forName0(Native Method)

at java.base/java.lang.Class.forName(Unknown Source)

at clojure.lang.RT.classForName(RT.java:2168)

at clojure.lang.RT.classForName(RT.java:2177)

at clojure.lang.RT.loadClassForName(RT.java:2196)

at clojure.lang.RT.load(RT.java:443)

at clojure.lang.RT.load(RT.java:419)

at clojure.core$load$fn__5677.invoke(core.clj:5893)

at clojure.core$load.invokeStatic(core.clj:5892)

at clojure.core$load.doInvoke(core.clj:5876)

at clojure.lang.RestFn.invoke(RestFn.java:408)

at clojure.lang.Var.invoke(Var.java:379)

at clojure.lang.Util.loadWithClass(Util.java:250)

at export_server.core.<clinit>(Unknown Source)

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter

at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)

at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)

at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

at java.base/java.lang.Class.forName0(Native Method)

at java.base/java.lang.Class.forName(Unknown Source)

at clojure.lang.RT.classForName(RT.java:2168)

at clojure.lang.RT.classForNameNonLoading(RT.java:2181)

at org.httpkit.server$loading__5569__auto____5568.invoke(server.clj:1)

at org.httpkit.server__init.load(Unknown Source)

at org.httpkit.server__init.<clinit>(Unknown Source)

... 42 more

I tried to add as many XML jars as possible to support Java 11, in particular from this discussion. But same error.

Could you advise on running Anychart server on a newer Java version?

@Shestac92
Copy link

@djechelon
Unfortunately, the export server is compatible with Java 8 only. Version 11 is not supported.

@djechelon
Copy link
Author

Unfortunately I'm not an expert of Clojure, but very experienced in Java.
Would you accept help from community members? I am available to provide help.

Java version compatibility is mainly a cybersecurity issue. Java 8 has gone EOL since long, and it is advisable to switch to a newer version, possibly LTS.

In my case, the Anychart http server is jailed into a local container network, so I already did my job of preventing attacks from the external. But in case the server is to be exposed over the internet, a potential vulnerability in Java 8 (which won't likely be fixed) could be used to make harm.

I could personally call it a day and go live to production with my super-jailed Docker image.

Or...... I could say that the XML error is caused by some Java-XML packages, part of Java EE specifications, dropped out of the standard JRE, causing major compatibility issues with older projects.

There are two simple ways to fix this kind of problems in Java applications:

  • One is to assess the real need of the Java EE classes in a Java SE project. Sometimes a developer puts a javax.xml annotation inside their code because it looks cool or explanatory, indeed creating a dependency
  • Another is to add proper jar dependencies blindly, which is fastest

I'll be glad to contribute up to my best

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