maven私有仓库jar上传,本地无法识别,这个问题遇见好几次了。
如下是私有仓库上传jar的页面:
上传后经常出现本地工程无法获取该jar包的情况。检查后发现是因为jar未上传前,pom文件已经去获取过一次,会生成对应的jar包目录,该目录下没有该jar。jar包上传后,eclipse发现本地库已经有目录不会去更新仓库的jar包。
解决方案,找到本地的maven目录,删除jar包对应的目录就可以。
maven私有仓库jar上传,本地无法识别,这个问题遇见好几次了。
如下是私有仓库上传jar的页面:
上传后经常出现本地工程无法获取该jar包的情况。检查后发现是因为jar未上传前,pom文件已经去获取过一次,会生成对应的jar包目录,该目录下没有该jar。jar包上传后,eclipse发现本地库已经有目录不会去更新仓库的jar包。
解决方案,找到本地的maven目录,删除jar包对应的目录就可以。
前几天听说github更新了UI,今天休假逛了逛,发现了一个好玩的东西。github居然可以用来作为Maven仓库。
# 基本Steps:
- 生成用于发布、安装和删除 GitHub 包的访问令牌。
- 配置你的
.m2/settings.xml
。- 设置你需要发布的maven项目。
- deploy。
- 愉快的使用
- say: ??
1. 生成TOKEN令牌
- 路径:Settings -> Developer settings -> Person Access Tokens
image.png image.png
设置该Token的名字与授权的权限
生成成功(记得保存好自己的TOKEN哟,如果遗失了也可以重新生成)
2. 设置你的
.m2/settings.xml
<profiles>
<profile>
<id>githubid>
<repositories>
<repository>
<id>centralid>
<url>https://repo1.maven.org/maven2url>
<releases><enabled>trueenabled>releases>
<snapshots><enabled>trueenabled>snapshots>
repository>
<repository>
<id>githubid>
<name>GitHub OWNER Apache Maven Packagesname>
<url>https://maven.pkg.github.com/OWNER/REPOSITORYurl>
repository>
repositories>
profile>
profiles>
<servers>
<server>
<id>githubid>
<username>USERNAMEusername>
<password>TOKENpassword>
server>
servers>
USERNAME
替换为你的github账号。TOKEN
替换为第一步生成的访问令牌。OWNER
替换为拥有该仓库的用户或组织帐户的名称REPOSITORY
替换为包含项目的仓库的名称- 看起来长这样:
image.png 3. 设置项目的POM文件
- 设置pom文件
githubGitHub OWNER Apache Maven Packageshttps://maven.pkg.github.com/OWNER/REPOSITORY
- 注意
id
需要设置成第二步中设置的server.id
OWNER
替换为拥有该仓库的用户或组织帐户的名称REPOSITORY
替换为包含项目的仓库的名称- 看起来长这样:
image.png 4. deploy
到目前为止你的github-packages可能还长这样
但是一炷香之后...
在项目中执行
mvn deploy -Dmaven.test.skip=true
将项目生成的依赖发布到github现在看看~满满登登嘚
点进去还可以看到历史版本
image.png
- 注意:同一个版本号不可重复deploy,否则会失败
5. 使用
- 使用刚刚发布的依赖坐标
com.lazy.starterlazy-cache1.2.5
- 如果出现无法下载的情况,需要在pom文件中添加仓库信息
githubhttps://maven.pkg.github.com/FutaoSmile/LazyStartertruetrue
- Downloading from github
6. ??
# 其他
- Github相关文章地址: https://help.github.com/cn/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages#authenticating-to-github-packages
- 其他类型项目发布:Github https://help.github.com/cn/packages/using-github-packages-with-your-projects-ecosystem
最近开发noCloud过程中,在更新maven库时,如果网络问不定或者是一些自己手动安装到本地maven库的jar包,在中心库找不到对应的jar,会生成一些.lastUpdated文件,会导致m2e工具无法找到依赖的jar包,从而提示编译错误。
对于该问题,我也没有找到很好的解决方案,只能手动删除一下lastUpdated文件。文件多时十分繁琐。网上看到别人的解决方案也有利用命令行命令,匹配文件扩展名批量删除的。命令行不会,于是就写了几行代码用于删除.lastUpdated文件。
如有其他直接的解决方案,望不吝赐教,写代码实属无奈之举。
- public class DelLastUpdated {
- private static PropertyHelper propHelper = new PropertyHelper("config");
- private static final String KEY_MAVEN_REPO = "maven.repo";
- private static final String MAVEN_REPO_PATH = propHelper
- .getValue(KEY_MAVEN_REPO);
- private static final String FILE_SUFFIX = "lastUpdated";
- private static final Log _log = LogFactory.getLog(DelLastUpdated.class);
- /**
- * @param args
- */
- public static void main(String[] args) {
- File mavenRep = new File(MAVEN_REPO_PATH);
- if (!mavenRep.exists()) {
- _log.warn("Maven repos is not exist.");
- return;
- }
- File[] files = mavenRep.listFiles((FilenameFilter) FileFilterUtils
- .directoryFileFilter());
- delFileRecr(files,null);
- _log.info("Clean lastUpdated files finished.");
- }
- private static void delFileRecr(File[] dirs, File[] files) {
- if (dirs != null && dirs.length > 0) {
- for(File dir: dirs){
- File[] childDir = dir.listFiles((FilenameFilter) FileFilterUtils
- .directoryFileFilter());
- File[] childFiles = dir.listFiles((FilenameFilter) FileFilterUtils
- .suffixFileFilter(FILE_SUFFIX));
- delFileRecr(childDir,childFiles);
- }
- }
- if(files!=null&&files.length>0){
- for(File file: files){
- if(file.delete()){
- _log.info("File: ["+file.getName()+"] has been deleted.");
- }
- }
- }
- }
- }
配置文件:config.properties
- maven.repo=D:\\.m2\\repository
源码下载地址:
svn: https://svn.code.sf.net/p/maventools/code/trunk/maven-tools
工程里还包括一个批量安装jar包到本地maven库的工具,以前发过,后来做了一些改进和修正。
本文转自mushiqianmeng 51CTO博客,原文链接:http://blog.51cto.com/mushiqianmeng/720448,如需转载请自行联系原作者
最近开发noCloud过程中,在更新maven库时,如果网络问不定或者是一些自己手动安装到本地maven库的jar包,在中心库找不到对应的jar,会生成一些.lastUpdated文件,会导致m2e工具无法找到依赖的jar包,从而提示编译错误。
对于该问题,我也没有找到很好的解决方案,只能手动删除一下lastUpdated文件。文件多时十分繁琐。网上看到别人的解决方案也有利用命令行命令,匹配文件扩展名批量删除的。命令行不会,于是就写了几行代码用于删除.lastUpdated文件。
如有其他直接的解决方案,望不吝赐教,写代码实属无奈之举。
public class DelLastUpdated { private static PropertyHelper propHelper = new PropertyHelper("config"); private static final String KEY_MAVEN_REPO = "maven.repo"; private static final String MAVEN_REPO_PATH = propHelper .getValue(KEY_MAVEN_REPO); private static final String FILE_SUFFIX = "lastUpdated"; private static final Log _log = LogFactory.getLog(DelLastUpdated.class); /** * @param args */ public static void main(String[] args) { File mavenRep = new File(MAVEN_REPO_PATH); if (!mavenRep.exists()) { _log.warn("Maven repos is not exist."); return; } File[] files = mavenRep.listFiles((FilenameFilter) FileFilterUtils .directoryFileFilter()); delFileRecr(files,null); _log.info("Clean lastUpdated files finished."); } private static void delFileRecr(File[] dirs, File[] files) { if (dirs != null && dirs.length > 0) { for(File dir: dirs){ File[] childDir = dir.listFiles((FilenameFilter) FileFilterUtils .directoryFileFilter()); File[] childFiles = dir.listFiles((FilenameFilter) FileFilterUtils .suffixFileFilter(FILE_SUFFIX)); delFileRecr(childDir,childFiles); } } if(files!=null&&files.length>0){ for(File file: files){ if(file.delete()){ _log.info("File: ["+file.getName()+"] has been deleted."); } } } } }
配置文件:config.properties
maven.repo=D:\\.m2\\repository
源码下载地址:
svn https://svn.code.sf.net/p/maventools/code/trunk/maven-tools工程里还包括一个批量安装jar包到本地maven库的工具,以前发过,后来做了一些改进和修正。