猿问

如何将 Maven 项目部署为 jar 文件

我已经阅读了很多关于“构建” pom.xml 文件的内容,我在清理项目后多次完成了该文件。

我在设置目标时已经打包并编译并尝试安装。它创建了一个“快照”jar 文件,但是当我尝试执行它时没有任何反应。

我尝试在命令行 (CMD) 上执行它以查看错误并收到以下信息:

没有主要清单属性,在 smart.mirror-0.0.1-SNAPSHOT.jar

任何帮助,将不胜感激。

慕标琳琳
浏览 136回答 2
2回答

FFIVE

您确实需要使用 maven jar 插件并定义主类。&nbsp;<plugin>&nbsp;&nbsp; &nbsp; &nbsp;<groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp;<artifactId>maven-jar-plugin</artifactId>&nbsp; &nbsp; &nbsp;<configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <archive>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <manifest>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <mainClass>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;com.yourpackage.YourMainClass&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </mainClass>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </manifest>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </archive>&nbsp; &nbsp; &nbsp;</configuration></plugin>通常,您确实有依赖项,如有必要,您可以使用 Shade 插件将其打包到您自己的 jar 中。

素胚勾勒不出你

基本上,您需要将依赖项添加到您的 pom 中,而不是重建它。请将此依赖项添加到您的 pom 中:<dependency>&nbsp; &nbsp; <groupId>com.mashape.unirest</groupId>&nbsp; &nbsp; <artifactId>unirest-java</artifactId>&nbsp; &nbsp; <version>1.4.9</version></dependency>之后,右键单击该项目并选择 maven 并清理它。清洁后,按照相同的步骤并选择构建。它将构建可执行的 jar。您必须使用 Maven Assembly Plugin 而不是 Jar 来部署具有可执行 Jar 的依赖项。它在你的 pom 中丢失了。它应该类似于下面提到的插件配置:<plugin>&nbsp; <artifactId>maven-assembly-plugin</artifactId>&nbsp; <configuration>&nbsp; &nbsp; <archive>&nbsp; &nbsp; &nbsp; <manifest>&nbsp; &nbsp; &nbsp; &nbsp; <mainClass>fully.qualified.MainClass</mainClass>&nbsp; &nbsp; &nbsp; </manifest>&nbsp; &nbsp; </archive>&nbsp; &nbsp; <descriptorRefs>&nbsp; &nbsp; &nbsp; <descriptorRef>jar-with-dependencies</descriptorRef>&nbsp; &nbsp; </descriptorRefs>&nbsp; </configuration></plugin>
随时随地看视频慕课网APP

相关分类

Java
我要回答