A previous answer describes a way to get under the covers of JDK 8 to parse javascript. They are now mainlining it in Java 9. Nice!
This will mean that you don't need to include any libraries, instead we can rely on an official implementation from the java guys. Parsing javascript programmatically is much easier to achieve without stepping into taboo areas of java code.
Applications of this might be where you want to use javascript for a rules engine which gets parsed and compiled into some other language at runtime. The AST lets you 'understand' the logic as written in the the concise javascript language and then generate less pretty logic in some other language or framework for execution or evaluation.
http://openjdk.java.net/jeps/236
Summary from the link above:
Define a supported API for Nashorn's ECMAScript abstract syntax tree.
Goals
- Provide interface classes to represent Nashorn syntax-tree nodes.
- Provide a factory to create a configured parser instance, with configuration done by passing Nashorn command-line options via an API.
- Provide a visitor-pattern API to visit AST nodes.
- Provide sample/test programs to use the API.
Non-Goals
- The AST nodes will represent notions in the ECMAScript specification insofar as possible, but they will not be exactly the same. Wherever possible the javac tree API's interfaces will be adopted for ECMAScript.
- No external parser/tree standard or API will be used.
- There will be no script-level parser API. This is a Java API, although scripts can call into Java and therefore make use of this API.