[英]run maven java project using batch file
我有一个Java应用程序,我在其中使用maven加载依赖项。 我的主要方法在App.java中,还有其他各种类。 这是基于弹簧的应用程序。 我必须使用批处理文件运行此应用程序。
到目前为止,这是我尝试过的:
但我想知道是否还有其他方法可以实现同一目标。 在清单中,我必须给所有罐子起个名字
同样在应用程序jar中,清单文件是自动创建的。 因此,我必须手动对其进行编辑以提供主类名称和所有相关的jar。
任何帮助表示赞赏。
谢谢。
使用Maven Jar插件执行您想要的操作。 您可以配置它以放置所有清单条目以满足您的需求。
<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依赖项插件 :
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.