Maven使用tips

命令行根据archetype创建项目

mvn archetype:generate mvn archetype:generate -X debug模式 mvn archetype:generate -DarchetypeCatalog=internal 本地模式 <!-- more --> http://blog.csdn.net/u011303778/article/details/46534601

mac 下添加 自定义 archetype

编辑 /Users/${your_username}/Library/Caches/${your_idea_version}/Maven/Indices/UserArchetypes.xml

1
2
3
4
5
<?xml version="1.0" encoding="UTF-8"?>
<archetypes>
<archetype groupId="org.scala-tools.archetypes" artifactId="scala-archetype-simple" version="1.3" />
<archetype groupId="org.sparkinaction" artifactId="scala-archetype-sparkinaction" version="0.13" repository="https://github.com/spark-in-action/scala-archetype-sparkinaction/raw/master" />
</archetypes>

安装jar至本地nexus

  • 在maven的conf/setting.xml 配置nexus私服的管理账号
    • 在servers标签下添加server
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin</password>
      </server>
      <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin</password>
      </server>
      <server>
      <id>sjrep</id>
      <username>admin</username>
      <password>admin123</password>
      </server>

id可自己定义一个名称 以及私服的管理管的账号密码

  • 在mirrors和profiles下配置nexus私服

  • 在项目的pom.xml中配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <distributionManagement>
    <repository>
    <id>nexus-releases</id>
    <name>Nexus Release Repository</name>
    <url>http://192.168.10.8:18080/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
    <id>nexus-snapshots</id>
    <name>Nexus Snapshot Repository</name>
    <url>http://192.168.10.8:18080/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
    </distributionManagement>

    id与settings.xml中的server的id对应

  • 当项目package后将jar上传到nexus私服 mvn deploy

找不到archetype

cd ~/.m2/ curl http://repo1.maven.org/maven2/archetype-catalog.xml > archetype-catalog.xml

1
mvn archetype:generate  -DarchetypeCatalog=local

Juforg wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!