Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
What can i do to parse javascript classes from java?

I need to parse JavaScript from java. I have already tried the NashornScriptEngine (builtin in the jdk), and RhinoScriptEngine, but they both (apparently) do not support the "class" keyword.

This is what i tried:

public static void main(String[] args) throws Throwable {
    RhinoScriptEngineFactory factory = new RhinoScriptEngineFactory();
    RhinoScriptEngine engine = (RhinoScriptEngine) factory.getScriptEngine();

    engine.eval(new FileReader("js/SomeClass.js"));
}

And this is the content of SomeClass.js:

class SomeTestClass {
}

function start() {
    print("hello")
}

And this is the stacktrace:

Exception in thread "main" javax.script.ScriptException: identifier is a reserved word: class in eval at line number 0 at column number 6
    at org.mozilla.javascript.engine.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
    at com.clut.MyMain.main(MyMain.java:21)

So what can i do to parse javascript containing classes? I can even use another library if its needed

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found out that GraalVm has builtin javascript parsing

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!