EvalFile.java revision 67:5c2ed5d89524
1226031Sstas/* 2226031Sstas * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3226031Sstas * 4226031Sstas * Redistribution and use in source and binary forms, with or without 5226031Sstas * modification, are permitted provided that the following conditions 6226031Sstas * are met: 7226031Sstas * 8226031Sstas * - Redistributions of source code must retain the above copyright 9226031Sstas * notice, this list of conditions and the following disclaimer. 10226031Sstas * 11226031Sstas * - Redistributions in binary form must reproduce the above copyright 12226031Sstas * notice, this list of conditions and the following disclaimer in the 13226031Sstas * documentation and/or other materials provided with the distribution. 14226031Sstas * 15226031Sstas * - Neither the name of Oracle nor the names of its 16226031Sstas * contributors may be used to endorse or promote products derived 17226031Sstas * from this software without specific prior written permission. 18226031Sstas * 19226031Sstas * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20226031Sstas * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21226031Sstas * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22226031Sstas * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23226031Sstas * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24226031Sstas * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25226031Sstas * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26226031Sstas * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27226031Sstas * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28226031Sstas * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29226031Sstas * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30226031Sstas */ 31226031Sstas 32226031Sstasimport javax.script.*; 33226031Sstas 34226031Sstaspublic class EvalFile { 35226031Sstas public static void main(String[] args) throws Exception { 36226031Sstas // create a script engine manager 37226031Sstas ScriptEngineManager factory = new ScriptEngineManager(); 38226031Sstas // create JavaScript engine 39226031Sstas ScriptEngine engine = factory.getEngineByName("nashorn"); 40226031Sstas // evaluate JavaScript code from given file - specified by first argument 41226031Sstas engine.eval(new java.io.FileReader(args[0])); 42226031Sstas } 43226031Sstas} 44226031Sstas 45226031Sstas