Skip to content

jutils/jsen-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSEN JS - JavaScript Engine for Java

Implementation of JavaScript engine for Java which makes easier to execute scripts in Java code. Interpreting of JavaScript is assured by Rhino. Library provides especially simple and customizable way of exporting Java objects to JavaScript. Exporting is assured automatically or using special Java annotations. Interface that is used for executing scripts is familiar to JSR 223.

This library is fork of ScriptBox and is based on the abstract engine core jsen-core.

Building library

Requirements

  1. Have installed JDK 1.6 or newer - JDK 1.8 is recommended
  2. Have installed Maven build manager
  3. Have set system variable JAVA_HOME to directory with installed JDK and have its binary directory in the system variable PATH - e.g. on Windows add to PATH variable %JAVA_HOME%\bin (more here)
  4. Have in the system variable PATH the directory with Maven installation

Building

Simply run command: mvn package

Using the library

Using Maven

<dependency>
	<groupId>com.jsen</groupId>
	<artifactId>jsen-js</artifactId>
	<version>0.0.1</version>
</dependency>

Custom way

Have built library (see previous section) and have it specified on classpath

Example of using library

public class GlobalObject {

	@ScriptGetter(field="state")
	public ITransformationState getState() {}
		
	@ScriptFunction(name="write")
	public void print(Object obj) throws TransformationException {}
}

GlobalObject globalObject = new GlobalObject();
		
AbstractScriptEngine engine = ScriptEngineManager.getInstance().getBrowserScriptEngine("text/javascript", 
	new GlobalObjectScriptSettings<Generator>(globalObject)
);

engine.eval(script);

For more examples see:

  • Test of Java script annotations here
  • Package com.jsen.script.annotation
  • Another classes like Window, Location, etc. defined in ScriptBox project

Known issues

If you run into any bug, please report on:
https://github.com/ITman1/jsen-js/issues

Issue list:

  1. Thrown error during javac build: error: annotation XYZ is missing value for the attribute <clinit>

Contact and credits

Author: Radim Loskot
gmail.com: radim.loskot (e-mail)

Please feel free to contact me if you have any questions.

About

Customable JavaScript engine for Java following JSR 223

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages