简体   繁体   English

如何使用 Maven 类路径运行 Java 主 class?

[英]How to use Maven classpath to run Java main class?

I'm currently using Maven to build my Rhino JavaScript project, download dependent libraries, and manage the classpath at runtime.我目前正在使用 Maven 来构建我的 Rhino JavaScript 项目,下载依赖库,并在运行时管理类路径。 I'm able to run the JavaScript entry point by using the Maven exec plugin, in the following way:我可以使用 Maven exec 插件运行 JavaScript 入口点,方法如下:

        <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.这很好用,但问题是 maven 需要大约 10 秒才能启动,这比我的程序运行时间长大约 10 倍。 Is there a way to either:有没有办法:

  1. improve the performance of the maven exec plugin so that it takes less time to start, or提高 maven exec 插件的性能,以缩短启动时间,或
  2. export the classpath that maven would use at runtime, so that I can just start my program from a script?导出 maven 将在运行时使用的类路径,以便我可以从脚本启动我的程序?
  1. You can use the -o / --offline switch to tell Maven to not bother checking for snapshot or plugin updates.您可以使用-o / --offline开关告诉 Maven 不要检查快照或插件更新。

  2. Use the appassembler or assembly plugins to generate startup scripts which will automatically (in the case of appassembler) reference the desired classpath.使用appassemblerassembly插件生成启动脚本,这些脚本将自动(在 appassembler 的情况下)引用所需的类路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM