Skip to content

Commit

Permalink
JavaScript Nashorn
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagogomes187 committed Aug 27, 2023
1 parent d181e4f commit 9976038
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions JavaScriptPrj/JavaScriptPrj.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
27 changes: 27 additions & 0 deletions JavaScriptPrj/src/JavaScriptExemplo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.FileReader;

import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class JavaScriptExemplo {

public static void main(String[] args) {

ScriptEngine ee = new ScriptEngineManager().getEngineByName("Nashorn");

Bindings bind = ee.getBindings(ScriptContext.ENGINE_SCOPE);

bind.put("goodbye", " Até logo!!!");

try {
ee.eval(new FileReader("olamundo.js"));
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
3 changes: 3 additions & 0 deletions olamundo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var saudacao = "Olá Mundo!";
var goodbye;
print(saudacao + goodbye);

0 comments on commit 9976038

Please sign in to comment.