-1

Trying to put in your application code of Ace Editor: http://ace.c9.io/#nav=embedding. I found something like this: http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/ and I put this code:

engine.eval(new java.io.FileReader("ace-builds/src-noconflict/ace.js"));

But I have build errors.

Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "window" is not defined. (<Unknown source>#1513) in <Unknown source> at line number 1513
    at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
    at javaapplication9.JavaApplication9.main(JavaApplication9.java:28)
Caused by: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "window" is not defined. (<Unknown source>#1513)
    at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(ScriptRuntime.java:3770)
    at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(ScriptRuntime.java:3748)
    at sun.org.mozilla.javascript.internal.ScriptRuntime.notFoundError(ScriptRuntime.java:3833)
    at sun.org.mozilla.javascript.internal.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1826)
    at sun.org.mozilla.javascript.internal.ScriptRuntime.name(ScriptRuntime.java:1765)
    at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Interpreter.java:1785)
    at sun.org.mozilla.javascript.internal.Interpreter.interpret(Interpreter.java:849)
    at sun.org.mozilla.javascript.internal.InterpretedFunction.call(InterpretedFunction.java:162)
    at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(ContextFactory.java:430)
    at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall(RhinoScriptEngine.java:116)
    at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall(RhinoScriptEngine.java:109)
    at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(ScriptRuntime.java:3160)
    at sun.org.mozilla.javascript.internal.InterpretedFunction.exec(InterpretedFunction.java:173)
    at sun.org.mozilla.javascript.internal.Context.evaluateReader(Context.java:1169)
    at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:214)
    ... 2 more

Do any of you know how can I do this? Thans for help and Happy Holidays!

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
Ursinus
  • 1
  • 2

1 Answers1

1

Keep in mind that you are executing a Javascript file out of context.

This Javascript file is usually executed with the browser JS engine so if you are not in that context you could not access to some objects like navigator, window... etc.

vzamanillo
  • 9,905
  • 1
  • 36
  • 56
  • So this can not be done? Is there a way? Or is there a similar program in Java, which I can use? – Ursinus Dec 20 '13 at 15:23
  • What are you trying to do? That guide is intended to embed ACE in a web application. – vzamanillo Dec 20 '13 at 15:27
  • Yes it is and I know it. I want to make a program in the style of a notebook that will be used Ace as a text editor. – Ursinus Dec 20 '13 at 15:32
  • Take a look at http://stackoverflow.com/questions/853071/wysiwyg-text-editor-in-java and http://stackoverflow.com/questions/196980/can-anyone-recommend-a-java-rich-text-editor – vzamanillo Dec 20 '13 at 16:14
  • @Ursinus It can be done with some code, however this code was clearly designed only to be used in a webpage context, trying to get the computed CSS of elements and asking about the user's browser. – Vitruvie Dec 20 '13 at 16:44
  • Ok I understund. And if you put it in with the JEditorPane? Could we save the code created in the editor? – Ursinus Dec 20 '13 at 17:00
  • Ok. I give up the idea. Just tell me how to do syntax highlighting in a simple text editor? – Ursinus Dec 20 '13 at 21:04