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

JEP 445 support: Unnamed Classes and Instance Main Methods #1629

Closed
linux-china opened this issue Jun 7, 2023 · 5 comments · Fixed by #1633
Closed

JEP 445 support: Unnamed Classes and Instance Main Methods #1629

linux-china opened this issue Jun 7, 2023 · 5 comments · Fixed by #1633
Labels
ideas Some idea/suggestion around jbang behavior/feature set

Comments

@linux-china
Copy link
Contributor

linux-china commented Jun 7, 2023

JEP 445 support for JBang.

Create Main.java Java file:

///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 21
//JAVAC_OPTIONS --enable-preview -source 21
//JAVA_OPTIONS --enable-preview

void main(){
        System.out.println("Hello, World!");
}

Then run jbang run --verbose Main.java, and statcktrace as following:

[jbang] [0:286] jbang version 0.107.0
[jbang] [0:299] Resolving resource ref: Main.java
[jbang] [0:302] Resolved resource ref as: Main.java (cached as: /Users/linux_china/IdeaProjects/java21-in-action/Main.java)
[jbang] [0:359] Looking for JDK: 21
[jbang] [0:363] Using JDK: 21 (21, current, /Users/linux_china/.jbang/cache/jdks/21)
[jbang] [0:363] No build required. Reusing jar from /Users/linux_china/.jbang/cache/jars/Main.java.8f8f49b93db276e6a59a1b145e26592539e968c045885a1b51ea31d3959ca24d/Main.jar
[jbang] [0:365] Looking for JDK: 21
[jbang] [0:366] Using JDK: 21 (21, current, /Users/linux_china/.jbang/cache/jdks/21)
[jbang] [0:366] Looking for JDK: 21
[jbang] [0:366] Using JDK: 21 (21, current, /Users/linux_china/.jbang/cache/jdks/21)
[jbang] [0:368] [ERROR] no main class deduced, specified nor found in a manifest
dev.jbang.cli.ExitException: no main class deduced, specified nor found in a manifest
	at dev.jbang.source.generators.JarCmdGenerator.generateCommandLineList(JarCmdGenerator.java:168)
	at dev.jbang.source.generators.BaseCmdGenerator.generate(BaseCmdGenerator.java:56)
	at dev.jbang.cli.Run.doCall(Run.java:99)
	at dev.jbang.cli.BaseCommand.call(BaseCommand.java:145)
	at dev.jbang.cli.BaseCommand.call(BaseCommand.java:21)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
	at picocli.CommandLine.access$1300(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
	at dev.jbang.cli.JBang$3.handle(JBang.java:148)
	at dev.jbang.cli.JBang$3.handle(JBang.java:143)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
	at picocli.CommandLine.execute(CommandLine.java:2078)
	at dev.jbang.Main.main(Main.java:14)
[jbang] [0:368] If you believe this a bug in jbang, open an issue at https://github.com/jbangdev/jbang/issues

You can run it with jbang run --verbose -m Main Main.java, and it works well.

JEP 445 has been implemented on openjdk/jdk@98b53c0, and next version of JDK 21 will include this feature.

@linux-china linux-china added the ideas Some idea/suggestion around jbang behavior/feature set label Jun 7, 2023
@maxandersen
Copy link
Collaborator

Is there a build one can download and try ?

We really just need to detect the new method generated and could then remove need for manual main.

@maxandersen
Copy link
Collaborator

managed to build a jdk - I can't get -m Main to work.

@maxandersen
Copy link
Collaborator

sorry - it does work - had typo.

@linux-china
Copy link
Contributor Author

JDK 21 build 26 implemented JEP 445 already. https://jdk.java.net/21/

@maxandersen
Copy link
Collaborator

Done in 0.108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ideas Some idea/suggestion around jbang behavior/feature set
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants