我有一个 java 应用程序,我在其中使用 maven 来加载依赖项。我的主要方法在 App.java 中,还有其他各种类。这是一个基于 Spring 的应用程序。 我必须使用批处理文件运行此应用程序。
这是我到目前为止尝试过的:
- 制作 list 文件以提供主类名称
- 生成了一个应用程序 jar
- 在一个 lib 文件夹中放置了我的应用程序使用的所有 jar
- 在 list 中给出了所有的 jar 路径
但我想知道是否有任何其他方法可以实现同样的目标。在 list 中,我必须给所有的 jar 命名
同样在应用程序 jar 中,会自动创建一个 list 文件。所以我必须手动编辑它以提供主类名称和所有依赖的 jar。
感谢任何帮助。
谢谢。
最佳答案
使用 Maven Jar Plugin做你想做的事。您可以将其配置为放置所有 list 条目以满足您的需要。
<plugin>
<!-- jar plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>package.path.for.App</Main-Class>
<implementation-version>1.0</implementation-version>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix> <!-- use this to specify a classpath prefix, in your case, lib -->
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
为了便于将所有依赖项复制到特定文件夹,请使用 Maven Dependency Plugin :
<plugin>
<!-- copy all dependencies of your app to target folder-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory> <!-- use this field to specify where all your dependencies go -->
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
关于java - 使用批处理文件运行 maven java 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27510656/