【发布时间】:2016-02-18 07:19:16
【问题描述】:
我正在编写一个 Java 应用程序,该应用程序使用了在我的服务器上运行的另一个第三方应用程序的一些库。目前我正在使用 appassembler-maven-plugin 构建我的应用程序。这个插件将我的 jars(应用程序和依赖项)复制到 lib 文件夹中,并在 bin 目录中生成一个 shellscript。
类路径是在这个 shellscript 中生成的。该解决方案有效,但我复制了依赖罐(在我的应用程序和第三方应用程序中按时编写应用程序)。我的第三方应用程序的类路径设置在 $THIRDPARTYAPP_CLASSPATH 之类的系统变量中。
我想将我的 pom.xml 中的依赖项设置为提供,以便 appassembler 不会将它们添加到 lib 和类路径中,并希望在我的 shellscript 中添加 systemvar $THIRDPARTYAPP_CLASSPATH,以便我的应用程序使用来自已安装的第三方应用程序。
目前我正在手动执行此操作(在构建后编辑 shellscript)并且它可以工作。 appassembler-maven-plugin 中是否有任何方法可以自动将系统变量添加到类路径中?
我在文档中找不到任何内容,此处有关类似问题的其他问题没有得到很好的回答。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<configuration>
<assembleDirectory>${project.build.directory}/appassembler</assembleDirectory>
<extraJvmArguments>-Xms512m -Xmx1024m</extraJvmArguments>
<generateRepository>true</generateRepository>
<repositoryName>lib</repositoryName>
<repositoryLayout>flat</repositoryLayout>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<platforms>
<platform>unix</platform>
</platforms>
<programs>
<program>
<mainClass>${mainClass}</mainClass>
<id>app</id>
</program>
</programs>
</configuration>
</plugin>
【问题讨论】:
-
首先为什么要配置默认值
assembleDirectory?您可以配置创建一个<environmentSetupFileName>setup-env</environmentSetupFileName>,它可以通过CLASSPATH_PREFIX定义一个新的类路径部分,这应该可以解决您的问题。 (顺便说一句:为什么不使用最新版本的 appassembler?)... -
谢谢!这正是我想要的。并感谢有关版本和目录的提示。
标签: java maven classpath maven-assembly-plugin