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

[GR-62394] Espresso: "java.lang.NoSuchMethodError: getMainType" was thrown when running a Java-11 application #10694

Open
shiaoguo opened this issue Feb 16, 2025 · 7 comments
Assignees
Labels

Comments

@shiaoguo
Copy link

Hi,
I'm trying to run James 3.6.2 (Java Apache Mail Enterprise Server) using Espresso. I built the James project upon OpenJDK11, so I ran it with --java.JavaHome pointing to the OpenJDK11. However, I got the following error:

java.lang.NoSuchMethodError: getMainType
Exception in thread "main" java.lang.NoSuchMethodError: getMainType

Even if I ran a simple program printing "Hello World", the same error happened. I'm wondering how to fix it.
Thanks a lot.

Environment:
Ubuntu 20.04
espresso-java21-24.1.2-linux-amd64
OpenJDK 11

@shiaoguo shiaoguo added the bug label Feb 16, 2025
@selhagani selhagani self-assigned this Feb 17, 2025
@selhagani
Copy link
Member

Hi @shiaoguo,

Thank you for reaching out!
Could you try running a simple Java program like this to check if Espresso is working correctly?

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

If this fails with the same NoSuchMethodError, the issue is likely related to your Espresso setup.

If Hello World works, but James Mail Server still fails, then the issue may be due to James and we might need to investigate further.

@shiaoguo
Copy link
Author

Hi @selhagani ,

Thanks for your reply!
I've run the HelloWorld program by the following steps:

  1. Download Espresso from https://gds.oracle.com/download/espresso/archive/espresso-java21-24.1.2-linux-amd64.tar.gz.
  2. Unzip the archive: tar -xzf <archive>.tar.gz.
  3. Compile the HelloWorld program using java-11-openjdk-amd64 on Ubuntu 24.04.
  4. Run the program using graalvm-espresso-jdk-21.0.2+13.1/bin/java --java.JavaHome=/usr/lib/jvm/java-11-openjdk-amd64 HelloWorld

and the same error happened.

Also, I've tried these commands:

Command:

graalvm-espresso-jdk-21.0.2+13.1/bin/java --java.JavaHome=/usr/lib/jvm/java-11-openjdk-amd64 -version

Output:

OpenJDK Runtime Environment (build 11.0.26+4-post-Ubuntu-1ubuntu124.04)
Espresso 64-Bit VM (build 11-espresso-24.1.2, mixed mode)

Command:

graalvm-espresso-jdk-21.0.2+13.1/bin/java HelloWorld

Output:

Hello, World!

Command:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java HelloWorld

Output:

Hello, World!

I'm new to Espresso and set it up according to https://www.graalvm.org/latest/reference-manual/espresso/. Maybe I've missed something important?

Thank you again for the advice and looking forward to your reply!

@selhagani
Copy link
Member

Could you please try running the same example except this time instead of compiling using java-11-openjdk-amd64 use GraalVM for jdk 21 instead?

@shiaoguo
Copy link
Author

Doing so, I got these results:

Command:

graalvm-espresso-jdk-21.0.2+13.1/bin/java HelloWorld

Output:

Hello World!

Command:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java HelloWorld

Output:

Error: LinkageError occurred while loading main class HelloWorld
	java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 55.0

Command:

graalvm-espresso-jdk-21.0.2+13.1/bin/java --java.JavaHome=/usr/lib/jvm/java-11-openjdk-amd64 HelloWorld

Output:

Error: LinkageError occurred while loading main class HelloWorld
	java.lang.UnsupportedClassVersionError: Unsupported major.minor version 65.0

@selhagani selhagani changed the title Espresso: "java.lang.NoSuchMethodError: getMainType" was thrown when running a Java-11 application [GR-62394] Espresso: "java.lang.NoSuchMethodError: getMainType" was thrown when running a Java-11 application Feb 19, 2025
@selhagani
Copy link
Member

Thank you for sharing the results with me. We will take a closer look into this and I'll make sure to keep you updated.

@shiaoguo
Copy link
Author

Thanks. By the way, is --java.JavaHome=/usr/lib/jvm/java-11-openjdk-amd64 the right way to run a Java-11 application using Espresso? (I don't know if I had a good understanding of the manual.) If not, could you please tell me how to do it, and is there any possibility that some libraries could be missing?

@gilles-duboscq
Copy link
Member

Regarding the issues with "class file version 65.0", you should use JDK 11 to compile this HellowWorld if you want to run it on JDK 11.

By the way, is --java.JavaHome=/usr/lib/jvm/java-11-openjdk-amd64 the right way to run a Java-11 application using Espresso?

In an embedding scenario, where you setup a polyglot context programmatically, using the java.JavaHome option is indeed the right approach.

When using the standard espresso standalone this could work but as the java launcher (and libjli.so) that is used comes from a different JDK (in this case 21) which might be incompatible since it uses some internal JDK APIs (e.g., sun.launcher.LauncherHelper).

Regarding you initial issue (java.lang.NoSuchMethodError: getMainType), that's exactly the kind of incompatibilities that can happen when using a new libjli.so with an older standard library.

You can create a "JDK 11 espresso standalone" yourself though:

# copy the JDK, dereferencing links to make it "standalone"
$ cp -L -r /usr/lib/jvm/java-11-openjdk jdk11
# add espresso library and files from the JDK 21 espresso standalone
$ cp -r graalvm-espresso-jdk-21.0.2+13.1/languages/ jdk11/
$ cp -r graalvm-espresso-jdk-21.0.2+13.1/lib/truffle/ jdk11/lib/
# edit jdk11/lib/jvm.cfg and add `-truffle KNOWN` as the first line
$ vim jdk11/lib/jvm.cfg
$ jdk11/bin/java -version
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[java] SEVERE: Configuration specified a Java version incompatible with the pre-initialized language - expected: 21, got: 11.
openjdk version "11.0.26" 2025-01-21
OpenJDK Runtime Environment (Red_Hat-11.0.26.0.4-1) (build 11.0.26+4)
Espresso 64-Bit VM (Red_Hat-11.0.26.0.4-1) (build 11-espresso-24.1.2, mixed mode)
$ jdk11/bin/javac HelloWorld.java
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[java] SEVERE: Configuration specified a Java version incompatible with the pre-initialized language - expected: 21, got: 11.
$ jdk11/bin/java HelloWorld
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[java] SEVERE: Configuration specified a Java version incompatible with the pre-initialized language - expected: 21, got: 11.
Hello, Espresso!

This warning it's printing is a bit annoying but it does run the workload with JDK 11.

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

No branches or pull requests

3 participants