Skip to content

Latest commit

 

History

History
78 lines (69 loc) · 1.55 KB

README.md

File metadata and controls

78 lines (69 loc) · 1.55 KB

JS2Jar

Compile Nashorn script to Java application

Install

  1. Install dependencies
  1. 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);

See more about Nashorn