4

Earlier I run .sh and .rb file in the maven life cycle using the following,

          <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>exec-maven-plugin</artifactId>
               <version>1.1</version>
               <executions>
                   <execution>
                       <id>Version Calculation</id>
                       <phase>generate-sources</phase>
                       <goals>
                           <goal>exec</goal>
                       </goals>
                   </execution>
               </executions>
               <configuration>
                     <executable>${basedir}/scripts/IndexRunner/test.rb</executable>
               </configuration>
           </plugin>

Now I want to run a .js file, I tried by replacing test.rb to some file test.js but its not working, any help to how to run a javascript file during maven lifecycle

2
  • What exactly would you execute inside that javascript? Commented Sep 19, 2011 at 5:54
  • I need to run some mongoDB commands in that JavaScript file Commented Sep 19, 2011 at 6:18

2 Answers 2

2

You should use a java class which is triggering javascript file. And with exec plugin you can run this file. The content of the file is like this.

import javax.script.*;
public class ExecuteScript {
    public static void main(String[] args) throws Exception {
       // create a script engine manager
       ScriptEngineManager factory = new ScriptEngineManager();
       // create a JavaScript engine
       ScriptEngine engine = factory.getEngineByName("JavaScript");
      // evaluate JavaScript code from String
      engine.eval("print('Welocme to java world')");
      // or call file as you wish
      engine.eval(new java.io.FileReader("welcome.js"));
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

FYI, there is also a maven plugin on Github (using Apache Bean Scripting Framework) for this task: https://github.com/alexec/script-maven-plugin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.