如何使用Maven类路径运行Java主类?
我目前正在使用 Maven 构建我的 Rhino JavaScript 项目、下载依赖库并在运行时管理类路径。我可以通过使用 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>
这效果很好,但问题是 Maven 需要大约 10 秒才能启动,这比我的时间长了大约 10 倍。程序来运行。有没有办法:
- 提高 maven exec 插件的性能,以便减少启动时间,或者
- 导出 maven 在运行时使用的类路径,以便我可以从脚本启动我的程序?
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:
- improve the performance of the maven exec plugin so that it takes less time to start, or
- export the classpath that maven would use at runtime, so that I can just start my program from a script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
-o
/--offline
开关告诉 Maven 不要费心检查快照或插件更新。使用
appassembler
或assemble
插件来生成启动脚本,该脚本将自动(在应用程序汇编器的情况)参考所需的类路径。You can use the
-o
/--offline
switch to tell Maven to not bother checking for snapshot or plugin updates.Use the
appassembler
orassembly
plugins to generate startup scripts which will automatically (in the case of appassembler) reference the desired classpath.