当前位置: 首页>>代码示例>>Java>>正文


Java ScriptException.printStackTrace方法代码示例

本文整理汇总了Java中javax.script.ScriptException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptException.printStackTrace方法的具体用法?Java ScriptException.printStackTrace怎么用?Java ScriptException.printStackTrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.script.ScriptException的用法示例。


在下文中一共展示了ScriptException.printStackTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testJS

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
    public void testJS() {
        // https://stackoverflow.com/questions/22492641/java8-js-nashorn-convert-array-to-java-array
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("javascript");
        try {
            engine.put("line", "刘长炯 微信号weblogic (10.3.2) [46a5432f8fdea99a6186a927e8da5db7a51854ac]");
//            engine.put("regex", )
            String regex = "/(.*?) \\((.*?)\\) \\[(.*?)\\]/";
            String[] value = (String[])engine.eval("Java.to(line.match(" + regex + "),\"java.lang.String[]\" );");
            System.out.println(value.length);
            System.out.println(value[1]);
            String[] result = {"刘长炯 微信号weblogic (10.3.2) [46a5432f8fdea99a6186a927e8da5db7a51854ac]",
                    "刘长炯 微信号weblogic", "10.3.2", "46a5432f8fdea99a6186a927e8da5db7a51854ac"};
            Assert.assertArrayEquals("result shold match", result, value);
//            Collection<Object> val = value.values();
//            if(value.isArray()) {
//                System.out.println(value.getMember("1"));
//            }
        } catch (ScriptException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:beansoftapp,项目名称:react-native-console,代码行数:24,代码来源:TestParseIOSDevices.java

示例2: onInit

import javax.script.ScriptException; //导入方法依赖的package包/类
@Override
public final void onInit(ClientInfo info) {
    // Init and load module manager
    moduleManager = new ExampleModManager();
    moduleManager.load();

    // Init and load command manager
    commandManager = new ExampleCommandManager();
    commandManager.load();

    // Setup example script
    String scriptSource = new StreamReader(ExampleClient.class.getResourceAsStream("/lua/example.lua")).all();
    LuaScript script = LuaHandler.getHandler().createScript(LuaScript.Type.HOOK, scriptSource);
    try {
        script.compile();
        script.exec();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ImpactDevelopment,项目名称:ClientAPI,代码行数:21,代码来源:ExampleClient.java

示例3: getValue

import javax.script.ScriptException; //导入方法依赖的package包/类
@Override
public String getValue(String orginData)
{
	String value = null;
	ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
	try
	{
		Object resObj = engine.eval(orginData);
		if(resObj != null)
		{
			value = resObj.toString();
		}
		else
		{
			value = "js not return!";
		}
	}
	catch (ScriptException e)
	{
		value = e.getMessage();
		e.printStackTrace();
	}
	
	return value;
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:26,代码来源:JavaScriptDynamicData.java

示例4: jsMatchExpr

import javax.script.ScriptException; //导入方法依赖的package包/类
/**
 * Exec a string match function with JavaScript regex expression and return the match result.
 * @param str
 * @param regex
 * @return null if no match, otherwise a String[] result value
 */
public static String[] jsMatchExpr(String str, String regex) {
    // https://stackoverflow.com/questions/22492641/java8-js-nashorn-convert-array-to-java-array
    if(engine == null) {
        ScriptEngineManager manager = new ScriptEngineManager();
        engine = manager.getEngineByName("javascript");
    }
    try {
        engine.put("str", str);
        String[] value = (String[])engine.eval("Java.to(str.match(" + regex + "),\"java.lang.String[]\" );");
        return value;
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:beansoftapp,项目名称:react-native-console,代码行数:22,代码来源:JSExec.java

示例5: initJS

import javax.script.ScriptException; //导入方法依赖的package包/类
/**
 * Setup javascript shortcuts such as 'server'.
 */
private void initJS() {

    // Allow JS to load java classes.
    Thread currentThread = Thread.currentThread();
    ClassLoader previousClassLoader = currentThread.getContextClassLoader();
    currentThread.setContextClassLoader(Core.getInstance().getClass().getClassLoader());

    try {
        this.engine = new ScriptEngineManager().getEngineByName("JavaScript");
        engine.put("engine", engine); // Allow JS to do consistent eval.
        engine.eval(new InputStreamReader(Core.getInstance().getResource("boot.js"))); // Run JS startup.
        MechanicManager.getMechanics().forEach(this::bindObject); // Create shortcuts for all mechanics.
        bindClass(Utils.class);
        bindClass(KCPlayer.class);
        bindClass(ReflectionUtil.class);
    } catch (ScriptException ex) {
        ex.printStackTrace();
        Core.warn("Failed to initialize JS shortcuts.");
    } finally {
        // Set back the previous class loader.
        currentThread.setContextClassLoader(previousClassLoader);
    }
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:27,代码来源:CommandJS.java

示例6: putGlobalFunctionTest

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
public void putGlobalFunctionTest() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");

    e.put("callable", new Callable<String>() {
        @Override
        public String call() throws Exception {
            return "callable was called";
        }
    });

    try {
        e.eval("print(callable.call())");
    } catch (final ScriptException exp) {
        exp.printStackTrace();
        fail(exp.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ScriptEngineTest.java

示例7: factoryClassLoaderTest

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
public void factoryClassLoaderTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            final MyClassLoader loader = new MyClassLoader();
            // set the classloader as app class loader
            final ScriptEngine e = nfac.getScriptEngine(loader);
            try {
                e.eval("Packages.foo");
                // check that the class loader was attempted
                assertTrue(loader.reached(), "did not reach class loader!");
            } catch (final ScriptException se) {
                se.printStackTrace();
                fail(se.getMessage());
            }
            return;
        }
    }

    fail("Cannot find nashorn factory!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TrustedScriptEngineTest.java

示例8: noLoaderPerCompilerTest

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
/**
 * Test repeated evals with --loader-per-compile=false
 * We used to get "class redefinition error".
 */
public void noLoaderPerCompilerTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            final String[] options = new String[] { "--loader-per-compile=false" };
            final ScriptEngine e = nfac.getScriptEngine(options);
            try {
                e.eval("2 + 3");
                e.eval("4 + 4");
            } catch (final ScriptException se) {
                se.printStackTrace();
                fail(se.getMessage());
            }
            return;
        }
    }
    fail("Cannot find nashorn factory!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:TrustedScriptEngineTest.java

示例9: noLoaderPerCompilerWithSameNameTest

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
/**
 * Test that we can use same script name in repeated evals with --loader-per-compile=false
 * We used to get "class redefinition error" as name was derived from script name.
 */
public void noLoaderPerCompilerWithSameNameTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            final String[] options = new String[] { "--loader-per-compile=false" };
            final ScriptEngine e = nfac.getScriptEngine(options);
            e.put(ScriptEngine.FILENAME, "test.js");
            try {
                e.eval("2 + 3");
                e.eval("4 + 4");
            } catch (final ScriptException se) {
                se.printStackTrace();
                fail(se.getMessage());
            }
            return;
        }
    }
    fail("Cannot find nashorn factory!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TrustedScriptEngineTest.java

示例10: testDriver

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
public void testDriver() throws IOException {
    WebDriver driver = new RemoteWebDriver(toUrl("http://localhost:9515"), DesiredCapabilities.chrome());
    driver.get(URL2);

    String response = driver.getPageSource();
    Document doc = Jsoup.connect(URL2).ignoreContentType(true).get();
    Elements scriptTags = doc.select("body");

    // get All functions


    try {
        String result = (String) engine.eval(response);
    } catch (ScriptException e) {
        e.printStackTrace();
    }

    log.info("PageSource " + response);

    driver.quit();
}
 
开发者ID:robevansuk,项目名称:delay-repay-bot,代码行数:23,代码来源:PhantomJSTest.java

示例11: getInfoFor

import javax.script.ScriptException; //导入方法依赖的package包/类
public String getInfoFor(Player player, String string) {
	string = string
			.replaceAll(Variables.statueVariable,
					AuthMeApi.getInstance().isRegistered(player.getName()) ? Variables.registeredStatueMessage
							: Variables.unregisteredStatueMessage)
			.replaceAll(Variables.playerVariable, player.getName())
			.replaceAll(Variables.playerCustomVariable, player.getCustomName())
			.replaceAll(Variables.playerDisplayVariable, player.getDisplayName())
			.replaceAll(Variables.playerIpVariable, player.getAddress().getHostString())
			.replaceAll(Variables.serverIpVariable, Bukkit.getIp())
			.replaceAll(Variables.playerLevelVariable, player.getExpToLevel() + "");
	if (Variables.script.isEmpty()) {
		return string;
	}
	ScriptEngineManager manager = new ScriptEngineManager();
	ScriptEngine engine = manager.getEngineByName(Variables.scriptEngine);
	Bindings bindings = engine.createBindings();
	bindings.put("line", string);
	bindings.put("player", player);
	bindings.put("plugin", plugin);
	try {
		string = engine.eval(Variables.script, bindings).toString();
	} catch (ScriptException e) {
		e.printStackTrace();
	}
	return string;
}
 
开发者ID:lj2000lj,项目名称:AuthMeGUI,代码行数:28,代码来源:LoginWindow.java

示例12: caculate

import javax.script.ScriptException; //导入方法依赖的package包/类
private String caculate(StringBuilder expression) {
    String result = "";
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
    try {
        System.out.println("expression=" + expression);
        result = engine.eval(expression.toString()).toString();
    } catch (ScriptException e) {
        e.printStackTrace();
    }

    return result;
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:13,代码来源:Caculator.java

示例13: parseArgs

import javax.script.ScriptException; //导入方法依赖的package包/类
public double parseArgs(String type, String str, CommandSender sender){
  	
  	double result = 0;
  	
  	switch(type){
  		case "x":
      		str = str.replaceAll("~", String.valueOf(((Player) sender).getX()));
      		break;
      		
  		case "y":
  			str = str.replaceAll("~", String.valueOf(((Player) sender).getY()));
      		break;
      		
  		case "z":
  			str = str.replaceAll("~", String.valueOf(((Player) sender).getZ()));
      		break;
      		
  		case "yaw":
  			str = str.replaceAll("~", String.valueOf(((Player) sender).getYaw()));
      		break;
      		
  		case "pitch":
  			str = str.replaceAll("~", String.valueOf(((Player) sender).getPitch()));
      		break;
  	}

  	try {    	
      	ScriptEngineManager manager = new ScriptEngineManager();
	result = (double) manager.getEngineByName("JavaScript").eval(str);
} catch (ScriptException e) {
	e.printStackTrace();
}
  	
return result;
  	
  }
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:37,代码来源:TeleportCommand.java

示例14: formatFunction

import javax.script.ScriptException; //导入方法依赖的package包/类
public void formatFunction() {
	Double lower;
	Double upper;
	while(function.indexOf(']')>0) {
		lower = Double.parseDouble(function.substring((function.indexOf('[')+1),function.indexOf(':')));
		upper = Double.parseDouble(function.substring((function.indexOf(':')+1),function.indexOf(']')));
		function = function.substring(0, function.indexOf('v'))+variableMaker(lower,upper)+function.substring(function.indexOf(']')+1);
	}
	try {
		findAnswer();
	} catch (ScriptException e) {
		e.printStackTrace();
	}
}
 
开发者ID:Abelito75,项目名称:betterQuizlit,代码行数:15,代码来源:Maths.java

示例15: accessGlobalTest

import javax.script.ScriptException; //导入方法依赖的package包/类
@Test
public void accessGlobalTest() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");

    try {
        e.eval("var x = 'hello'");
        assertEquals(e.get("x"), "hello");
    } catch (final ScriptException exp) {
        exp.printStackTrace();
        fail(exp.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ScriptEngineTest.java


注:本文中的javax.script.ScriptException.printStackTrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。