侧边栏壁纸
  • 累计撰写 250 篇文章
  • 累计创建 138 个标签
  • 累计收到 16 条评论

目 录CONTENT

文章目录

Maven学习笔记(3) -- 使用优化

Sherlock
2016-09-23 / 0 评论 / 0 点赞 / 1192 阅读 / 3874 字 / 编辑
温馨提示:
本文最后更新于 2023-10-09,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
1.maven阿里云中央仓库

maven 作为一个项目管理工具确实非常好用,但是在国内这个网络条件下实在是让人恼火。之前oschina的中央仓库可用,现在 oschinamaven 服务器关了,一直没找到国内镜像来替代。今天发现阿里云公开了一个中央仓库,大家可以试试。

配置

修改maven根目录下的conf文件夹中的 setting.xml 文件,内容如下:

  <mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>

之后就能享受如飞的maven下载速度。

2.maven工程默认jdk配置

修改maven根目录下的conf文件夹中的 setting.xml 文件,内容如下:

  • jdk7 为例
    <profiles>
        <profile>
            <id>jdk-1.7</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.7</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.7</maven.compiler.source>
                <maven.compiler.target>1.7</maven.compiler.target>
                <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
            </properties>
        </profile>
    </profiles>
3.maven添加额外archetype

用Eclipse + m2e 插件新建maven项目时发现archetype太少了,网上搜索如何添加额外的archetype.

http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html

The Archetype Plugin knows by default about its internal catalog. It also knows about the local and remote catalogs.

local represents the

~/.m2/archetype-catalog.xml

catalog file

remote represents the

http://repo1.maven.org/maven2/archetype-catalog.xml  

catalog file.

The Archetype Plugin can also read catalogs from filesystem/HTTP by providing the path/URL of a catalog file or of a directory containing an archetype-catalog.xml file.

可以从上述网址下载 archetype-catalog.xml 另存为~/.m2/archetype-catalog.xml

再新建maven项目,发现 CatalogDefault Local 中有了很多的 archetype。

4.批量删除maven仓库中的LastUpdated文件
@echo off
rem create by sunhao(sunhao.java@gmail.com)  
rem crazy coder

rem 这里写你的仓库路径  
set REPOSITORY_PATH=D:\.m2\repository  
rem 正在搜索...  
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (  
    del /s /q %%i
)
rem 搜索完毕  
pause  
5.maven 安装外部 jar 包命令
mvn install:install-file -Dfile=C:\Users\Administrator\Desktop\cystorage-sdk-java-2.3.1.jar -DgroupId=cn.cycore.cystorage.sdk -DartifactId=cystorage-sdk-java -Dversion=2.3.1-SNAPSHOT -Dpackaging=jar  
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区