用Maven给一个Maven工程打包,使用阿里云镜像解决mvn clean package出错的问题,使用plugin解决没有主清单属性的问题
本来在STS里做了一个极简Maven工程,内中只有一个Main方法的Java类,然后用新装的Maven3.6.3给它打包。
结果,Maven罢工,输出如下:
C:\personal\programs\ColoredText>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.hy:ColoredText >-------------------------
[INFO] Building ColoredText 0.0.-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.024 s
[INFO] Finished at: --28T09::+:
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.52.215] failed: Connection timed out: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help ] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
本着互联网就是知识库的理念,我开启了度娘查找模式,功夫不负有心人,在度娘的帮助下,短短几秒我就找到了解决方案:
<mirrors>
<!--配置阿里云maven私有仓库(即配阿里私服)-->
<mirror>
<id>alimaven</id>
<mirrorOf>*</mirrorOf>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
</mirrors>
上图深蓝色文字就是大招,把这段文字拷贝到Maven_HOME/conf/settings.xml(在我本机是C:\maven3.6.3\conf\settings.xml)里面的mirrors节点里就好了。
注意我是在家中电脑配置mirror节点,是不需要代理就能上网的环境,诸位如果公司电脑受限还需要设置代理,要不阿里云镜像还是访问不到。
之后再打包就一路绿灯了,输出一大堆文字,我截取了最后一部分贴出来:
us-interpolation-1.15.jar ( B at B/s)
Downloaded from alimaven: https://maven.aliyun.com/repository/central/org/codehaus/plexus/plexus-archiver/2.1/plexus-archiver-2.1.jar (0 B at 0 B/s)
Downloaded from alimaven: https://maven.aliyun.com/repository/central/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar (0 B at 0 B/s)
Downloaded from alimaven: https://maven.aliyun.com/repository/central/commons-lang/commons-lang/2.1/commons-lang-2.1.jar (0 B at 0 B/s)
[INFO] Building jar: C:\personal\programs\ColoredText\target\ColoredText-0.0.-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.497 s
[INFO] Finished at: --28T09::+:
[INFO] ------------------------------------------------------------------------
然后,我兴致勃勃地准备运行程序,结果当头被浇一盆冷水:
C:\personal\programs\ColoredText>cd target C:\personal\programs\ColoredText\target>java -jar ColoredText-0.0.-SNAPSHOT.jar
ColoredText-0.0.-SNAPSHOT.jar中没有主清单属性
我又在百度上查了一下,居然要我用winrar打开jar包修改Manifest.mf文件,添加“Main-class:类名”进去,这也太麻烦了,难道每次打出包来还要手动修改一次,没道理啊,于是我又在度娘的指引下找到了解决方案:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- 此处为程序主入口 -->
<mainClass>com.ufo.hy.EntryPoint</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
上面蓝色部分就是解决方案,设置此段到pom.xml后,指定Main-class的任务将由Maven代行,如果你的pom.xml中没有build节点你需要把整段都拷贝过去。
再次打包执行,久违的hello world就出现在控制台了。
ompress-1.11.jar ( kB at kB/s)
[INFO] Building jar: C:\personal\programs\ColoredText\target\ColoredText-0.0.-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.914 s
[INFO] Finished at: --28T10::+:
[INFO] ------------------------------------------------------------------------ C:\personal\programs\ColoredText>cd target C:\personal\programs\ColoredText\target>java -jar ColoredText-0.0.1-SNAPSHOT.jar
Hello world! C:\personal\programs\ColoredText\target>
以上代码工程链接在此:
https://files.cnblogs.com/files/xiandedanteng/ColoredText2020-03-28-1.zip
到此,打包并执行jar的任务就完成了。
喝水不忘挖井人,我找到的解决方案出处是:
https://blog.csdn.net/wudinaniya/article/details/98116734
https://www.cnblogs.com/wayoufeidie/p/11825773.html
在此感谢两位作者的付出。
--2020年3月28日--
用Maven给一个Maven工程打包,使用阿里云镜像解决mvn clean package出错的问题,使用plugin解决没有主清单属性的问题的更多相关文章
- maven项目新检出后不编译爬坑记 及 mvn clean package报错 WagonTransporterFactory: java.util.NoSuchElementException 异常【我】
从SVN新检出一个maven项目,配置好后,发现项目无法编译(只有一个test包中的代码显示编译报错,其他所有包中的代码都不编译,也不报错), 先注释掉报错的test包中的所有内容, 用Eclipse ...
- Maven命令行使用:mvn clean package(打包)
先把命令行切换到Maven项目的根目录,比如:/d/xxxwork/java/maven-test,然后执行命令: mvn clean package 执行结果如下: [INFO] Scanning ...
- SpringBoot通过maven打包成jar,设定主清单属性。
文章目录 原来普通的jar包一直是 <build> <plugins> <plugin> <groupId>org.apache.maven.plugi ...
- Maven 项目生成jar运行时提示“没有主清单属性”
新建了一个Maven的项目,mvn compile和mvn package后生成了jar文件,然后直接到target目录下去执行java -jar xxx.jar命令运行jar包时出现了"x ...
- eclipse maven .jar中没有主清单属性
报错环境: windows系统eclipse maven 打包jar包后, 运行 java -jar 报错 E:\My_java\mysql\target>java -jar original- ...
- Maven命令行使用 mvn clean package
先把命令行切换到Maven项目的根目录,比如:/d/xxxwork/java/maven-test,然后执行命令: mvn clean package 执行结果如下: [INFO] Scanning ...
- maven生成jar,运行却提示没有“没有主清单属性”
转自:http://www.jianshu.com/p/fd5bd8657852 修改pom.xml <project xmlns="http://maven.apache.org/P ...
- mvn clean package:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12
原文地址:https://www.cnblogs.com/lxcy/p/8279899.html 事故现场: 解决办法: 一是命令行, mvn clean package -Dmaven.test.s ...
- maven执行"mvn clean package" 命令报错
昨天利用mvn打包,执行程序'mvn clean package' 命令,发现打包失败 问题描述 具体看代码 发信tomcat下的log 清除不掉.为什么呢?忽然想起来我的项目服务还起着,于是我把服务 ...
随机推荐
- kubeadm部署1.17.3[基于Ubuntu18.04]
基于 Ubuntu18.04 使用 kubeadm 部署Kubernetes 1.17.3 高可用集群 环境 所有节点初始化 # cat <<EOF>> /etc/hosts ...
- [转]解决The requested resource is not available的方法
此博文为转载博文,首先感谢原作者 HTTP Status 404(The requested resource is not available)异常主要是路径错误或拼写错误造成的,请按以下步骤逐一排 ...
- 【JAVA】java中int转成String位数不足前面补零例如:1->001
String.format("%03d", 1); 0代表前面要补的字符3代表字符串长度d表示参数为整数类型 测试完数据:循环了100次 截取了一部分:
- Java 字符流
字符编码表:其实就是生活中字符和计算机二进制的对应关系表. 1.ascii: 一个字节中的7位就可以表示.对应的字节都是正数.0-xxxxxxx 2.iso-8859-1:拉丁码表 latin,用了一 ...
- Flutter 容器 (1) - Center
Center容器用来居中widget import 'package:flutter/material.dart'; class AuthList extends StatelessWidget { ...
- HTML基础-02
<header>网页头部 <hgroup>一个标题组 <main>网页主体 <article> ...
- ThinkPHP 6.0 基础教程 - 安装
ThinkPHP6.0 的环境: PHP >= 7.1.0 我本地环境: Win10 PhpStudy 安装 PhpStudy 如果你已经安装 PhpStudy 或其他环境,请忽略这里 安装方法 ...
- 汇编 | x86汇编指令集大全(带注释)
做mit-6.828的时候遇到了很多汇编知识,但是无奈学校还没学汇编,只能狠心啃啃硬骨头,在网上查到了很多的资料,归档!方便查看 ----------------------------------- ...
- hdfs常用api(java)
1.下载文件到本地 public class HdfsUrlTest { static{ //注册url 让java程序识别hdfs的url URL.setURLStreamHandlerFactor ...
- 每天都在用String,你真的了解吗?
1.String概述 java.lang.String 类代表字符串.Java程序中所有的字符串文字(例如"abc")都可以被看作是实现此类的实例 String 中包括用于检查各个 ...