js2jar
v1.0.6
Published
Compile Nashorn JavaScript code to .jar
Downloads
2
Maintainers
Readme
JS2Jar
Compile Nashorn script to Java application
Install
- Install dependencies
- Install JS2Jar
npm install -g js2jar
Usage
Create an app
js2jar create myApp
Build and run the app
cd path/to/myApp
js2jar build
or
js2jar build path/to/myApp
It will build the application in the build directory
Project structure
myApp
|---build
| |---lib //.jar libraries
| └---media //Media files like images, sounds, videos
└---src
└---main.js //Main script file
Example
myApp
|---build
| |---lib
| | └---mylib.jar
| └---media
| └---mypic.jpg
└---src
|---main.js
└---foo.js
foo.js
print("Hello! I am foo.js")
main.js
load("foo.js")
var JFrame = Java.type("javax.swing.JFrame");
var JPanel = Java.type("javax.swing.JPanel");
var JButton = Java.type("javax.swing.JButton");
var JLabel = Java.type("javax.swing.JLabel");
var ImageIcon = Java.type("javax.swing.ImageIcon");
var MyLib = Java.type("com.mylib.MyClass");
var win = new JFrame("My Window");
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setSize(400, 400);
var panel = new JPanel();
win.add(panel);
var picLabel = new JLabel(new ImageIcon("media/mypic.jpg"));
panel.add(picLabel);
win.setVisible(true);