You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "jtulach (via GitHub)" <gi...@apache.org> on 2025/06/20 17:27:29 UTC
Re: [PR] Agent to change retention of `@JavaScriptBody` and `@JavaScriptResource` [netbeans-html4j]
jtulach commented on PR #54:
URL: https://github.com/apache/netbeans-html4j/pull/54#issuecomment-2992340563
### Testing with Native Image
The primary goal of this change is to allow integration with [GraalVM](http://graalvm.org). Let's do a small test. Take [GraalVM repository](https://github.com/oracle/graal) at [release/graalvm-25.0](https://github.com/oracle/graal/tree/release/graal-vm/25.0) branch, in particular commit bb84380ba769081088ed5a95c2a4f3df9f1ac652:
```bash
graal/web-image$ mx build
graal/web-image$ graal/web-image$ mx web-image
Error: Please specify class (or <module>/<mainclass>) containing the main entry point method. (see --help)
```
With the `mx web-image` tool functioning. Let's create `netbeans-html4j-test.sh` file with the following content:
```bash
#!/bin/bash
set -e
mkdir -p hi
V=2.0-SNAPSHOT
CP=$1
if ! [ -e "$CP" ]; then
echo Usage $0 '<path_to_net.java.html.boot.jar>'
echo - typical path may be: $HOME/.m2/repository/org/netbeans/html/net.java.html.boot/$V/net.java.html.boot-$V.jar
exit 1
fi
cat >hi/Hi.java <<KONEC
class Hi {
@net.java.html.js.JavaScriptBody(args="txt", body="""
console.log(txt);
return "...returning back from JavaScript...";
""")
private static native String hello(String txt);
public static void main(String... args) {
System.out.println("In JVM");
var hi = hello("Hi from JavaScript");
System.out.println(hi);
System.out.println("Back in JVM");
}
}
KONEC
javac -cp $CP hi/Hi.java -d hi
mx web-image -H:+UnlockExperimentalVMOptions -o hi -H:Path=hi \
-H:+SILENT_COMPILE -H:-ClosureCompiler -H:+DumpPreClosure \
-H:+VerificationPhases -H:JSRuntime=Generic -H:Class=Hi \
-cp hi \
-J-javaagent:$CP
node hi/hi.js
```
and then just launch it with
[net.java.html.boot-2.0-SNAPSHOT.jar.gz](https://github.com/user-attachments/files/20840550/net.java.html.boot-2.0-SNAPSHOT.jar.gz) after uncompressing it with `gzip -d`:
```bash
graal/web-image$ ./netbeans-html4j-test.sh net.java.html.boot-2.0-SNAPSHOT.jar
======================
GraalVM Native Image: Generating 'hi' (executable)...
======================
...
In JVM
Hi from JavaScript
...returning back from JavaScript...
Back in JVM
```
Heuréka. CCing @pziegler, @toni-epple, @fniephaus - everything seems to be working. The next version of NetBeans/HTML API will easily generate the right code with `mx web-image` tool (with the help of `-javaagent:net.java.html.boot.jar`)!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists