mikelangelo-project / capstan

Capstan, a tool for packaging and running your application on OSv.
http://osv.io/capstan/
Other
19 stars 7 forks source link

ClassNotFoundException with very basic Java examples #90

Closed redblade closed 6 years ago

redblade commented 6 years ago

Hi, I am using the RuntimeJava and I am getting a ClassNotFoundException error in many cases. I am working on Ubuntu with OpenJDK8 used to compile the source code.

An easy example is the following

import java.sql.*;

public class Test{
  public static void main(String[] args) throws Exception{
    System.out.println("Example");
    if(args.length > 0) throw new java.sql.SQLException();
  }
}

where the result is

java.so: Starting JVM app using: io/osv/nonisolated/RunNonIsolatedJvmApp
java.so: Setting Java system classloader to NonIsolatingOsvSystemClassLoader
io.osv.AppThreadTerminatedWithUncaughtException: java.lang.NoClassDefFoundError: java/sql/SQLException
    at io.osv.nonisolated.NonIsolatedJvm.runSync(NonIsolatedJvm.java:81)
    at io.osv.RunJvmAppHelper.runSync(RunJvmAppHelper.java:40)
    at io.osv.nonisolated.RunNonIsolatedJvmApp.main(RunNonIsolatedJvmApp.java:34)
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at io.osv.Jvm.runMain(Jvm.java:117)
    at io.osv.nonisolated.NonIsolatedJvm.access$100(NonIsolatedJvm.java:20)
    at io.osv.nonisolated.NonIsolatedJvm$1.run(NonIsolatedJvm.java:46)
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more

It looks like some Java packages are not available in the openjdk8 zulu image that is loaded by OSv Do you have any advise about how to configure/fix this?

miha-plesko commented 6 years ago

Hi @redblade, please try to also include package openjdk8-zulu-compact3-with-java-beans in your unikernel by adding this line to your meta/package.yaml:

name: javatest
title: JavaTest
author: miha
require:
  - openjdk8-zulu-compact3-with-java-beans  # <------------- require this package

By default the runtime: java requires the most stripped version of Java, openjdk8-zulu-compact1. I have no idea what's in there and what not, but I know that the -witha-java-beans package is the most complete (an also the largest in size).

Please let me know if it works, and thanks for providing small reproducible example!

wkozaczuk commented 6 years ago

For sure java.sql.* is not part of compact 1 profile.

Sent from my iPhone

On Jan 26, 2018, at 09:38, Miha Pleško notifications@github.com wrote:

Hi @redblade, also include package openjdk8-zulu-compact3-with-java-beans in your unikernel by adding this line to your meta/package.yaml:

name: javatest title: JavaTest author: miha require:

  • openjdk8-zulu-compact3-with-java-beans # <------------- require this package By default the runtime: java requires the most stripped version of Java, openjdk8-zulu-compact1. I have no idea what's in there and what not, but I know that the -witha-java-beans package is the most complete (an also the largest in size).

Please let me know if it works, and thanks for providing small reproducible example!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

miha-plesko commented 6 years ago

Haha, thanks @wkozaczuk for joining the debate! @redblade: HE is the one that kindly provided all the recent Java packages for Capstan so if he doesn't know, then I'm not sure who would 😄

Btw @wkozaczuk I see there is now also openjdk8-zulu-full and even openjdk9-java-base available, thanks for your efforts! When I have some more time I should probably port them to capstan-packages (or you can open a PR and I'd gladly review it, should you have any extra time) ;)

redblade commented 6 years ago

Thanks @miha-plesko and @wkozaczuk, it works! For the records, I am testing an easy example from spring-boot, and a bigger one with microservices, they both work as a charm 👍

redblade commented 6 years ago

sorry to bug you, after some more tests, I am now getting a java.lang.ClassNotFoundException: javax.xml.bind.JAXBException for this example (the second one I mentioned before).

Is it similar to the sql problem?

miha-plesko commented 6 years ago

@wkozaczuk you think providing package openjdk8-zulu-full would help resolving this issue?

wkozaczuk commented 6 years ago

For sure. I would expect that compact3 with java beans should be enough for most cases. But java full should cover all cases. That is the order to try.

The best approach is to runs jdeps tool against your java app jars to determine what profile is enough to satisfy your needs.

This article explains what is part of each Java 8 profile - http://openjdk.java.net/jeps/161.

@miha-plesko https://github.com/miha-plesko It would be also nice to add Java 9 to the java runtimes. Please note that the one in osv-apps provides minimal java 9 runtime with java.base.

On Fri, Jan 26, 2018 at 10:33 AM, Miha Pleško notifications@github.com wrote:

@wkozaczuk https://github.com/wkozaczuk you think providing package openjdk8-zulu-full would help resolving this issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mikelangelo-project/capstan/issues/90#issuecomment-360816750, or mute the thread https://github.com/notifications/unsubscribe-auth/AFDSIQVmlguk3DcVpLqwZM9gufbvCDb5ks5tOfBFgaJpZM4RuWso .

redblade commented 6 years ago

Thanks for the feedback. So, if I get it right, having available the full release and the different compact ones could help to choose the most appropriate for each project according to the dependencies got by jdeps, correct?

In my case, I guess the next step is to try the full one, as from here I can't find the javax.xml.bind package.

Is there any plan to make the full version available to capstan?

miha-plesko commented 6 years ago

Hi @redblade , I've prepared openjdk8-zulu-full package for you, here's the recipe for it. It's not yet available in our public Capstan repository, but you can download the package from here: http://x.k00.fr/javafull

So what you need to do is to upload package to your Capstan repository (you're using your own, right?) and update your meta/package.yaml to somethning like this:

name: javatest
title: JavaTest
author: miha
require:
  - openjdk8-zulu-full  # <------------- require this package

Please let me know if it works!

redblade commented 6 years ago

Hi @miha-plesko, using a private repo (configured in the .capstan/config.yaml), I only had to copy the openjdk full in the repo folder, launch the microservice example with capstan run myartefact --boot conf -p qemu -f 18090:8090, and it worked perfectly

Thanks!