How to use Maven classpath to run Java main class?
Asked Answered
C

1

7

I'm currently using Maven to build my Rhino JavaScript project, download dependent libraries, and manage the classpath at runtime. I'm able to run the JavaScript entry point by using the Maven exec plugin, in the following way:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>org.mozilla.javascript.tools.shell.Main</mainClass>
                <classpathScope>runtime</classpathScope>
                <arguments>
                    <argument>path/to/entryPoint.js</argument>
                </arguments>
            </configuration>
        </plugin>

This works well, but the problem is that maven takes about 10 seconds just to start, which is about 10 times longer than it takes my program to run. Is there a way to either:

  1. improve the performance of the maven exec plugin so that it takes less time to start, or
  2. export the classpath that maven would use at runtime, so that I can just start my program from a script?
Coma answered 7/6, 2011 at 2:44 Comment(0)
I
4
  1. You can use the -o / --offline switch to tell Maven to not bother checking for snapshot or plugin updates.

  2. Use the appassembler or assembly plugins to generate startup scripts which will automatically (in the case of appassembler) reference the desired classpath.

Iwo answered 7/6, 2011 at 2:53 Comment(3)
-o didn't seem to affect maven startup performance, but appassembler appears to be exactly what I was looking for with respect to the second clause.Coma
is there a way to customize the output of the appassembler program to specify default arguments to pass to the main class in the generated script? e.g. path/to/entryPoint.js in the original question.Coma
I don't believe so, but you could write a wrapper script which invokes the generated one. Alternatively, you could just package your own startup script, given that (I assume) the classpath/dependencies are not really changing that often.Iwo

© 2022 - 2024 — McMap. All rights reserved.