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

Quarkus and Java 21 Instance Main Methods is not working #36154

Closed
rsvoboda opened this issue Sep 26, 2023 · 2 comments · Fixed by #36164
Closed

Quarkus and Java 21 Instance Main Methods is not working #36154

rsvoboda opened this issue Sep 26, 2023 · 2 comments · Fixed by #36164
Labels
area/core kind/bug Something isn't working
Milestone

Comments

@rsvoboda
Copy link
Member

rsvoboda commented Sep 26, 2023

Describe the bug

I tried customized QuarkusMain method as shown in https://quarkus.io/guides/lifecycle#the-main-method with Java 21 Instance Main Methods (preview feature).

Code example in https://github.com/rsvoboda/code-with-quarkus/tree/21-main

@QuarkusMain
public class Main {
    void main() {
        System.out.println("==> Running main method");
        Quarkus.run();
    }
}

maven-compiler-plugin enabled to use preview features

    <maven.compiler.release>21</maven.compiler.release>
...
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${compiler-plugin.version}</version>
        <configuration>
          <compilerArgs>
            <arg>--enable-preview</arg>
          </compilerArgs>
        </configuration>
      </plugin>

And I received:

Exception in thread "main" java.lang.NoSuchMethodException: org.acme.Main.main([Ljava.lang.String;)
	at java.base/java.lang.Class.getMethod(Class.java:2395)
	at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:61)
	at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:32)

I checked if I will see System.out.println("==> Running main method"); when calling the compiled jar just to ensure compilation went well. Message was printed

java --enable-preview -cp target/quarkus-app/app/code-with-quarkus-1.0.0-SNAPSHOT.jar org.acme.Main

==> Running main method
Exception in thread "main" java.lang.NoClassDefFoundError: io/quarkus/runtime/Quarkus
	at org.acme.Main.main(Main.java:10)
Caused by: java.lang.ClassNotFoundException: io.quarkus.runtime.Quarkus
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 1 more

Expected behavior

Quarkus boots

Actual behavior

Quarkus fails to start

How to Reproduce?

Output of uname -a or ver

macOS

Output of java -version

Java 21

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.4.1

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 26, 2023

/cc @Sanne (core), @aloubyansky (core), @gsmet (core), @radcortez (core), @stuartwdouglas (core)

@geoand
Copy link
Contributor

geoand commented Sep 26, 2023

Interesting find!

Seems like we'll need to follow the rules in Selecting a main method of https://openjdk.org/jeps/445.

geoand added a commit to geoand/quarkus that referenced this issue Sep 26, 2023
geoand added a commit to geoand/quarkus that referenced this issue Sep 26, 2023
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
geoand added a commit to geoand/quarkus that referenced this issue Sep 27, 2023
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
geoand added a commit to geoand/quarkus that referenced this issue Sep 28, 2023
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
geoand added a commit to geoand/quarkus that referenced this issue Sep 29, 2023
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
geoand added a commit to geoand/quarkus that referenced this issue Oct 2, 2023
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
geoand added a commit to geoand/quarkus that referenced this issue Oct 2, 2023
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
geoand added a commit that referenced this issue Oct 2, 2023
Support Java 21 main launch protocol
@quarkus-bot quarkus-bot bot added this to the 3.5 - main milestone Oct 2, 2023
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Feb 8, 2024
This solution is based on transforming the main class
so call-sites don't need to change

Closes: quarkusio#36154
Alternative to: quarkusio#36158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core kind/bug Something isn't working
Projects
None yet
2 participants