mojohaus / exec-maven-plugin

Exec Maven Plugin
https://www.mojohaus.org/exec-maven-plugin/
Apache License 2.0
163 stars 96 forks source link

Add support for Implicitly Declared Classes and Instance Main Methods (Second Preview) OpenJDK JEP 463 #411

Closed fabgio closed 4 months ago

fabgio commented 5 months ago

Given the JEP below:

https://openjdk.org/jeps/463

I wish to add support for unnamed classes and instance main method such as: void main() { System.out.println("Hello, World!"); }

I declared only a main method and a class named Main.java: public static void main(String...args) {

} ``

Main

``

fabgio commented 5 months ago

I got a runtime error:" symbolic reference class is not accessible: class Main, from class org.codehaus.mojo.exec.ExecJavaMojo (unnamed module @6326c6cb)", The bytecode is final synthetic class Main {

// compiled from: Main.java // access flags 0x19 public final static INNERCLASS java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles Lookup

// access flags 0x0

()V L0 LINENUMBER 2 L0 ALOAD 0 INVOKESPECIAL java/lang/Object. ()V RETURN L1 LOCALVARIABLE this LMain; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x89 public static varargs main([Ljava/lang/String;)V Any Idea about how to get access to the unnamed Main class?
fabgio commented 4 months ago

@lacostej I tried to give access to the unnamed mainClass as such: (ExecJavaMojo.java) Method mainMethod = bootClass.getDeclaredMethod("main"); mainMethod.setAccessible(true);

but I got this "java.lang.Exception: The specified mainClass doesn't contain a main method with appropriate signature." Any tip? Thanks

fabgio commented 4 months ago

I found out the unnamed main class is package private so it seems impossibile to access it