Maven筆記

技能樹

Java開發須備技能: Java -> Maven -> JDK -> MySql -> MongoDbhtml

maven 環境變量

vi /etc/profilejava

export M3_HOME=/opt/maven
export PATH=${M3_HOME}/bin:${PATH}

source /etc/profileweb

maven 幫助查看參數:

mvn help:describe -Dplugin=dependency -Dmojo=copy-dependencies -Dfullspring

打包命令

mvn clean package -Dmaven.test.skip=true

根本記不住,這應該是默認的命令, 寫一個批處理 mvn.jar.bat 放到 windows 下. 執行時: mvn.jarmongodb

  • 指定配置文件
    --settings c:\user\settings.xml

Maven添加本地Jar包

網上說了不少,只有它: http://blog.csdn.net/hhb200766/article/details/42168819 好用。
 Maven參數有幾千個,與其說強大,不如說笨拙。
 添加本地lib文件夾作爲倉庫:

<repository>
    <id>in-project</id>
    <name>In Project Repo</name>
    <url>${project.basedir}/lib</url>
</repository>

添加引用:
<dependency>
    <groupId>jwd</groupId>  <!--自定義-->
    <artifactId>pzx_entity</artifactId>    <!--自定義-->
    <version>3.0.0</version> <!--自定義-->
    <!--<scope>system</scope>-->
    <!--<systemPath>${basedir}/lib/pzx_entity-3.0.0.jar</systemPath> &lt;!&ndash;項目根目錄下的lib文件夾下&ndash;&gt;-->
</dependency>

lib文件夾下Jar包格式:
/groupId/artifactId/version/artifactId-verion.jar

排除包裏的引用

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
        </exclusion>
    </exclusions>
</dependency>

scope provided

有時,一個項目中,只能有一個Jar包被引用.像:  spring-session
在 entity中引用 spring-session 時, 就要使用:  scope  provided

發佈到私服

http://www.cnblogs.com/fengpingfan/p/5192738.html
http://www.cnblogs.com/winner-0715/p/7495179.htmlapache

  • 在nexus 上找到 releases , 設置 Deployment Policy -> Allow Redeploy , 同時, 點擊 Summary , Copy distributionManagement 配置內容到 項目的 pom.xml 的根路徑下
  • build 增長 plugin
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <!--意思是在什麼階段打包源文件-->
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
  • 使用配置文件部署 mvn deploy --settings E:\opt\apache-maven-3.5.3\xuauto.settings.xml
  • 若是本地項目的 pom.xml 依賴父pom.xml , 手動把 父 pom.xml 上傳到 nexus 的 releases 庫上. nexus 會自動同步到 public 上.

Jar包瘦身

http://rickgong.iteye.com/blog/2368985windows

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>jwd</groupId>
                            <artifactId>shop-entity</artifactId>
                        </include>
                        <include>
                            <groupId>jwd</groupId>
                            <artifactId>shop-orm</artifactId>
                        </include>
                        <include>
                            <groupId>jwd</groupId>
                            <artifactId>shop-mvc-base</artifactId>
                        </include>
                        <include>
                            <groupId>jwd</groupId>
                            <artifactId>shop-web-base</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
</build>

mvn dependency:copy-dependencies -DoutputDirectory=C:/libsession

運行時:
java -Dloader.path="c:/lib" -jar my-service.jarmvc

mvn-jar.cmd

:: mvn-jar -f corp
mvn clean package -Dmaven.test.skip=true %*

window 下,把文件放到 c:\windows 下 , 以及: C:\Program Files\Git\usr\bin 下。maven

相關文章
相關標籤/搜索