Open rmannibucau opened 4 years ago
Having a tinyjbang as one that does the same or similar but without full mvn dep resolution could be interesting; bascially user would have to list all dependencies explicitly and not rely on any transitive deps.
About your specific points I want to grok if you think these are not somehow supported to day or not...comments below.
- It must be able to resolve maven dependencies to add them in the script classloader/cp
Yes - we do that today afaik. If not let me know what you think is different/missing.
- It must not use SW resolver (TomEE resolver is enough with slight changes: apache/tomee@
master
/container/openejb-loader/src/main/java/org/apache/openejb/loader/provisining/)
Yes - this would be the new "feature"; allowing to choose which way you want to resolve these with the cost of lost functionallity but the gain of jbang being much smaller.
- It must support a simplified entry point "à la python" (ie instead of
public static void main(String...)
, justvoid main()
and use the script as the class content.
I don't understand what this is. What is the win here over what is there today of simply just running any "bare" java code via jshell ?
- In terms of dependency it should be a vanilla jbang, ie no opiniated predefined choice like picocli or so, just let user write a custom entry point (main) - goal being to let all script use that technic
jbang uses picocli for its own command line parsing but there are zero requirements to users on what their scripts uses to parse command line arguments. Thus not sure what you are referring to here ?
- It must be officially delivered as a fatjar (it is not in download area today, guess it is just a matter of uploading the fatjar but a small todo to add)
and this is because you only want/need it to work on bash/linux based scripts; you don't care about Windows enablement and the optional automatic download of java etc. ?
Would require jbang itself launches the external java process though ... loosing quite of flexibility.... I assume your javabien.jar above launches such process or are you dynamically compile and loading the class ?
@maxandersen to answer your questions:
jbang would just use contextual java to compile/launch the script.
- the main point is about starting to align script on common scripts (python as a ref there) + not have to use jshell at all - my code runs on j8 too, it is just a matter of defining an entry point, main being the simplest flavor I think
again - not fully following what you are getting at here (except that jshell needs java9). Can you give the example code you want to have executed ? It sounds to me you want this to be treated as valid to execute:
import x.y.z
...
void main(String args[]) {
}
i.e you'll need to parse/split the code to know what it needs/does.
Do I have it right?
- There is no need to parse much options but just rewrite the script to create the env and run it after having compiled it (uing javac for ex), options needed are very light (I can only think about a --debug one which does not need any cli parser)
Your issue is with jbang depending on picocli because it adds ~300K to the jar then.
I would still like tinyjbang to have the edit and a few other facilities ... would hate to handle that without picocli ...lets see how bad it gets before I commit to try that ;)
- the fatjar works well on windows, it is just not launched with a chbang like script but the main drops # lines so it works
sure; so you'll have to know how to call:
java -jar /opt/rmannibucau/dev/javabien/target/javabien-2.0.0-SNAPSHOT.jar script.java
instead of tinyjbang script.java
Is your script launching 2 java processes or dynamic loading it ?
note, if we remove the mvn dependency need tinyjbang could more easily just be built as a native binary....would be bigger though ;)
More exactly this (with args being optional):
import x.y.z
...
void main() {
}
My current impl 1. compiles the script having having rewritten part of it and parsed the metadata, 2. load the class in a custom classloader and 3. execute the entrypoint by reflection.
My launcher is not forking.
Ok. Not exactly a fan of that format as it won't work in any Ide. Jsh and java syntax does.
Nor sure how you would handle method and classes nicely.
I guess could just strip lines with import/package/comments and wrap everything else in a class...but not seeing the big win here. You loose a lot by this.
I don't dynamically load in jbang to allow script to tweak launch options.
@maxandersen advantage is really about scripting and not just doing deployment. Jshell is quite limited today so inheriting from it is not a thing. Most IDE support this kind of partial classes "correctly" and it enables a better readability in full script mode (several scripts will not even use an IDE, if it becomes too complex it will become an app with a real build system). About classes, since a class can have inner classes then it is not a big deal and works as in my sample. Same for methods - you are in a class so you have methods ;)). Once again it is not perfect but does what it intends for, for only 35k.
Hmm.... what Ide setup do you have that supports such syntax ? By support I mean content assist.
@maxandersen Intellij, VSCode and vim with java support (didn't test vanilla eclipse or netbeans). It does not support this syntax by itself but it is close enough to keep completion working (intellisense). Didn't test enough to say it was due to a previous indexation or not but didn't get an issue while it stays a single file (multiple files would make it "too red" ;)).
I get red syntax errors and it's not picking up the imports. At best just content assist on jdk classes.
Hmm, guess you didnt set the classpath in the project (project settings for ex)?
This is old issue but I still can't get any of my IDE's to stop complaining about top level methods unless you treat it as jshell thus not buying into introduing a third syntax.
Hi,
I have some use cases for a very light jbang flavor, here are the thing I'd like to drop from jbang and things I need:
public static void main(String...)
, justvoid main()
and use the script as the class content.Sample script I'm using today (simplified):