`

Maven Basic

    博客分类:
  • Java
阅读更多

0. useful commands:

    mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=${myArtifactId} -Dversion=RELEASE -Dpackaging=jar -Dfile=/path/to/file

    mvn deploy:deploy-file -DgroupId=org.apache.maven.archetypes -DartifactId=${myArtifactId} -Dversion=RELEASE -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

    mvn -Dtest=MenuItemFacadeTest test    

    mvn archetype:create -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=${groupId} -DartifactId=${artifactId}

    mvn archetype:create -DgroupId=${groupId} -DartifactId=${artifactId}

    mvn archetype:create                                      \

        -DarchetypeGroupId=<archetype-groupId>                \

        -DarchetypeArtifactId=<archetype-artifactId>          \

        -DarchetypeVersion=<archetype-version>                \

        -DgroupId=<my.groupid>                                \

        -DartifactId=<my-artifactId>

 

1. setting resource files:

    <build>

        <resources>

            <resource>

                <directory>src/main/java</directory>

                <includes>

                    <include>**/*.xml</include>

                    <include>**/*.tld</include>

                </includes>

            </resource>

            <resource>

                <directory>src/main/resources</directory>

                <includes>

                    <include>**/*.xml</include>

                    <include>**/*.properties</include>

                </includes>

            </resource>

        </resources>

    </build>

 

2. compiler plugin:

    <plugin>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>2.3</version>

        <configuration>

            <source>1.6</source>

            <target>1.6</target>

            <encoding>UTF-8</encoding>

        </configuration>

    </plugin>

 

3. tomcat plugin(mvn tomcat:run):

    <plugin>

        <groupId>org.codehaus.mojo</groupId>

        <artifactId>tomcat-maven-plugin</artifactId>

        <version>1.0-beta-1</version>

        <configuration>

            <path>/trsWeb</path>

            <port>9080</port>

        </configuration>

    </plugin>

 

4. jetty plugin(mvn jetty:run):

    <plugin>

        <groupId>org.mortbay.jetty</groupId>

        <artifactId>maven-jetty-plugin</artifactId>

        <version>6.1.24</version>

        <configuration>

            <scanIntervalSeconds>10</scanIntervalSeconds>

            <contextPath>/trsWeb</contextPath>

            <connectors>

                <connector implementation="org.mortbay.jetty.bio.SocketConnector">

                    <port>9080</port>

                    <maxIdleTime>60000</maxIdleTime>

                </connector>

            </connectors>

        </configuration>

    </plugin>

 

    jetty-debug.bat:

    @echo off

    if "%OS%" == "Windows_NT" setlocal

    set MAVEN_OPTS=-Xdebug -Xmx512m -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n

    mvn jetty:run

 

5. antrun plugin(mvn package):

    <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-antrun-plugin</artifactId>

        <version>1.4</version>

        <executions>

            <execution>

                <id>package</id>

                <phase>package</phase>

                <configuration>

                    <tasks if="${boolVariable}">

                        <property name="compile_classpath" refid="maven.compile.classpath"/>

                        <property name="runtime_classpath" refid="maven.runtime.classpath"/>

                        <property name="test_classpath" refid="maven.test.classpath"/>

                        <property name="plugin_classpath" refid="maven.plugin.classpath"/>

 

                        <echo message="compile classpath: ${compile_classpath}"/>

                        <echo message="runtime classpath: ${runtime_classpath}"/>

                        <echo message="test classpath:    ${test_classpath}"/>

                        <echo message="plugin classpath:  ${plugin_classpath}"/>

 

                        <copy file="d:/1.txt" tofile="d:/2.txt"/>

                    </tasks>

                </configuration>

                <goals>

                    <goal>run</goal>

                </goals>

            </execution>

        </executions>

    </plugin>

 

    or: mvn antrun:run

 

    <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-antrun-plugin</artifactId>

        <version>1.4</version>

        <configuration>

            <tasks if="${build.prod}">

                <property name="basedir" value="${basedir}" />

                <property name="compile_classpath" refid="maven.compile.classpath" />

                <property name="runtime_classpath" refid="maven.runtime.classpath" />

                <property name="test_classpath" refid="maven.test.classpath" />

                <property name="plugin_classpath" refid="maven.plugin.classpath" />

                <property name="build.dir" value="${project.build.directory}" />

                <property name="dist" value="${build.dir}/dist" />

                <property name="dist.src" value="${dist}/src" />

                <ant antfile="${basedir}/m2-build.xml">

                    <target name="${build.task}" />

                </ant>

            </tasks>

        </configuration>

    </plugin>

 

6. profiles.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <profilesXml>

        <profiles>

            <profile>

                <id>development</id>

                <properties>

                    <maven.test.skip>true</maven.test.skip>

                </properties>

            </profile>

            <profile>

                <id>production</id>

                <properties>

                    <maven.test.skip>false</maven.test.skip>

                </properties>

            </profile>

        </profiles>

        <activeProfiles>

            <activeProfile>development</activeProfile>

        </activeProfiles>

    </profilesXml>

    tip: the maven can auto detect the profiles.xml at the same directory with pom.xml, and use it.

 

7. active profile dynamically:

    1. write activation condition in each profile:

        <activation>

            <property>

                <name>env</name>

                <value>was</value>

            </property>

        </activation>

    2. define the default ${env} property in pom.xml:

        <properties>

            <env>dev</env>

        </properties>

    3. don't specify any activiate profile in neither pom.xml nor profiles.xml

    4. mvn package -Denv=was

 

8. encoding resource copying:

    <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-resources-plugin</artifactId>

        <configuration>

            <encoding>UTF-8</encoding>

        </configuration>

    </plugin>

 

9. 3 ways to run Java main from Maven£º

    1) Running from Command line

        01. mvn compile

        02. mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" <------- no args

        03. mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.args="arg0 arg1 arg2" -Dexec.commandlineArgs="-Xloggc:<file>"  <------- with args

        04. mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.classpathScope=runtime <------- with runtime dependencies in classpath

    2) Running in a phase in pom.xml

        01. <plugin>

                <groupId>org.codehaus.mojo</groupId>

                <artifactId>exec-maven-plugin</artifactId>

                <version>1.2</version>

                <executions>

                    <execution>

                        <phase>test</phase>

                        <goals>

                            <goal>java</goal>

                        </goals>

                        <configuration>

                            <mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>

                            <arguments>

                                <argument>arg0</argument>

                                <argument>arg1</argument>

                            </arguments>

                        </configuration>

                    </execution>

                </executions>

            </plugin>

        02. mvn test

    3) Running in a profile in pom.xml

        01. <profiles>

                <profile>

                    <id>code-generator</id>

                    <build>

                        <plugins>

                            <plugin>

                                <groupId>org.codehaus.mojo</groupId>

                                <artifactId>exec-maven-plugin</artifactId>

                                <version>1.2</version>

                                <executions>

                                    <execution>

                                        <phase>test</phase>

                                        <goals>

                                            <goal>java</goal>

                                        </goals>

                                        <configuration>

                                            <mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>

                                            <arguments>

                                                <argument>arg0</argument>

                                                <argument>arg1</argument>

                                            </arguments>

                                        </configuration>

                                    </execution>

                                </executions>

                            </plugin>

                        </plugins>

                    </build>

                </profile>

            </profiles>

        02. mvn test -Pcode-generator

    4) Advanced options:

        01. You can get a list of all available parameters by typing:

            mvn exec:help -Ddetail=true -Dgoal=java

 

10. mvn dependency:copy-dependencies

<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-dependency-plugin</artifactId>

    <configuration>

        <outputDirectory>m2_repo</outputDirectory>

        <overWriteIfNewer>true</overWriteIfNewer>

        <useRepositoryLayout>true</useRepositoryLayout>

        <copyPom>true</copyPom>

    </configuration>

</plugin>

 

11. deploy snapshot/3rd party maven project to nexus:

pom.xml

------------------------------------------------------------------------------------------

<distributionManagement>

    <repository>

        <id>nexus-releases</id>

        <name>Nexus142 Release Repository</name>

        <url>http://10.199.130.142:8080/nexus/content/repositories/releases/</url>

    </repository>

    <snapshotRepository>

        <id>nexus-snapshots</id>

        <name>Nexus142 Snapshot Repository</name>

        <url>http://10.199.130.142:8080/nexus/content/repositories/snapshots/</url>

        <uniqueVersion>false</uniqueVersion> <---- avoid to append current timestamp on uploaded jars.

    </snapshotRepository>

</distributionManagement>

 

12. change default maven repository folder:

${MAVEN_HOME}\conf\settings.xml

------------------------------------------------------------------------------------------

<settings...>

    <localRepository>D:\DevTools\apache-maven-2.2.1\repo</localRepository>

</settings>

<profile>

    <id>nexus</id>

    <repositories>

        <repository>

            <id>local-nexus</id>

            <url>http://10.199.130.142:8080/nexus/content/groups/public</url>

            <releases>

                <enabled>true</enabled>

                <updatePolicy>never</updatePolicy>

            </releases>

            <snapshots>

                <enabled>true</enabled>

                <updatePolicy>never</updatePolicy>

            </snapshots>

        </repository>

    </repositories>

</profile>

 

13. setting Nexus account:

${MAVEN_HOME}\conf\settings.xml

------------------------------------------------------------------------------------------

<settings...>

    <servers>

        <server>

            <id>nexus-releases</id>

            <username>admin</username>

            <password>mmis@123</password>

        </server>

        <server>

            <id>nexus-snapshots</id>

            <username>admin</username>

            <password>mmis@123</password>

        </server>

    </servers>

</settings>

 

14. run specified testcase in maven-test:

mvn -Dtest=MenuItemFacadeTest test

 

15. repository list:

<repositories>

    <repository>

      <id>maven2-repo1</id>

      <name>Maven2 Repo 1</name>

      <url>http://repo1.maven.org/maven2</url>

    </repository>

    <repository>

      <id>ibiblio</id>

      <name>iBiblio Maven2 Repository</name>

      <url>http://www.ibiblio.org/maven2</url>

    </repository>

    <repository>

      <id>apache-repo</id>

      <name>Apache Repository</name>

      <url>http://people.apache.org/repo/m2-snapshot-repository</url>

    </repository>

    <repository>

      <id>compass-project.org</id>

      <name>Compass</name>

      <url>http://repo.compass-project.org</url>

    </repository>

    <repository>

      <id>java.net</id>

      <name>JavaNet</name>

      <url>http://download.java.net/maven/2</url>

    </repository>

    <repository>

      <id>http://maven.seasar.org/maven21</id>

      <name>http://maven.seasar.org/maven2</name>

      <url>http://maven.seasar.org/maven2</url>

    </repository>

</repositories>

分享到:
评论

相关推荐

    maven安装以及eclipse的maven插件安装

    4. **设置字体**: 通过`Window` -&gt; `Preferences` -&gt; `General` -&gt; `Appearance` -&gt; `Colors and Fonts` -&gt; `Basic` -&gt; `Text Font`,选择合适的字体大小和样式。 5. **安装m2e插件**: - 通过`Help` -&gt; `Eclipse ...

    Maven 的41种骨架功能介绍

    ### Maven的41种骨架功能介绍 Maven作为一款强大的构建工具,在软件开发过程中扮演着极其重要的角色。它不仅能够帮助开发者自动化构建过程,还能通过其骨架(Archetype)功能来快速搭建项目的初始结构,极大地提高...

    Maven3.5.4,Tomcat8.5.34 windows-X64.rar

    5. **安全性**:Tomcat支持多种安全认证机制,如Basic、Digest和Form认证,以及SSL/TLS加密,确保Web应用的安全性。 **配置与使用** 在Windows环境下,首先解压Maven和Tomcat的压缩包,然后配置环境变量。对于...

    jmeter-maven-plugin, JMeter Maven 插件.zip

    jmeter-maven-plugin, JMeter Maven 插件 #JMeter Maven 插件 提供在构建过程中运行JMeter测试的能力的Maven 插件有关更改信息,请参阅变更日志 。这个插件需要 1.8 或者更高版本,自 2.2.0 #Basic 用法将插

    java源码剖析-sonarscanner-maven-basic:SonarQube是开放源代码,可以持续检查代码质量。Sonar是用于基于

    java源码剖析基本的Maven示例 这个简单的Maven项目正在导入JaCoCo的覆盖率报告。 有关多模块项目示例,请参见 用法 使用SonarQube Scanner for Maven构建项目,执行所有测试并分析项目(从项目的根目录开始): mvn ...

    Apache Maven Dependency Management

    You should be well versed with Maven and its basic functionalities if you wish to get the most out of this book. Table of Contents Chapter 1: Basic Dependency Management Chapter 2: Dependency ...

    Introducing Maven(Apress,2014)

    Introducing Maven is your quick start-...After reading and using this short book, you'll have an understanding of Maven's dependency management and how to organize basic and multi-module Maven projects.

    maven 项目cxf 使用jqgrid4.4.3 项目开发代码

    CXF支持多种安全机制,如Basic Auth、OAuth等,可以根据需求进行选择和配置。 9. **错误处理与日志**: 在开发过程中,错误处理和日志记录是非常重要的。CXF提供了异常处理机制,可以自定义错误响应,同时通过日志...

    maven-jaxb2-plugin:用于XML模式编译的最先进的JAXB2 Maven插件

    JAXB2 Maven插件欢迎使用org.jvnet.jaxb2.maven2:maven-jaxb2-plugin ,这是用于XML Schema编译的最先进且功能齐全的Maven插件。 这个Maven插件包装并增强了 并允许将XML Schema(以及WSDL,DTD,RELAX NG)编译为...

    maven使用方法促进编写JAVA代码

    mvn archetype:create –DarchetypeGroupId=com.easyjf.easyjweb –DremoteRepositories=http://dl.easyjf.com/maven2 –DarchetypeArtifactId=easyjweb-basic-initial –DarchetypeVersion=1.0 –DgroupId=...

    BasicAuth的Java服务端实现

    6. **Maven或Gradle依赖管理**:如果项目中使用了这些构建工具,了解如何添加和管理项目依赖。 7. **安全性考虑**:BasicAuth的缺点在于明文传输密码,因此通常需要配合HTTPS使用。此外,还应考虑凭证的存储和加密...

    rabbitMQ Maven实例

    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, StandardCharsets.UTF_8); ...

    openmrs-contrib-maven-archetype-basicmodule-creation

    "openmrs-contrib-maven-archetype-basicmodule-creation" 是一个专门针对OpenMRS的Maven原型,用于简化基本模块的创建流程,让开发者能够快速启动新项目。本文将深入探讨这一工具的使用以及与Java开发的相关知识点...

    acegi basic认证具体demo

    在Maven工程中,可以在pom.xml文件中添加如下依赖: ```xml &lt;groupId&gt;org.springframework.security &lt;artifactId&gt;spring-security-core &lt;version&gt;2.0.8.RELEASE ``` 注意,Acegi Security已经被Spring ...

    BasicProject

    6. **项目结构与规范**:基础项目通常会遵循一定的项目组织结构,例如Maven或Gradle的目录结构,这有助于保持代码的整洁和可维护性。同时,也可能涉及代码风格和命名规范的介绍。 7. **测试与调试**:基础项目可能...

    maven-archetype:用于初始化Java项目的Maven原型

    Maven原型 用于初始化Java项目的Maven原型 如何编译 mvn clean install 如何使用 mvn archetype:generate \ -DarchetypeGroupId=guybrush.maven.... -DarchetypeArtifactId=java-basic \ -DarchetypeVersion=1.0

    jsmart-basic-archetype:Maven原型创建基于JSmart的基本Web项目

    `jsmart-basic-archetype` 是一个Maven原型,它为创建一个基于JSmart的简单Web项目提供了基础框架。 **Maven原型的用途** Maven原型(Archetype)是预定义的项目结构,可以用来快速初始化一个新的项目。`jsmart-...

    java_basic.rar_java_javabasic

    5. 构建工具:如Maven或Gradle,用于自动化构建过程,管理依赖关系。 6. 开发环境:如Eclipse、IntelliJ IDEA等,提供代码编辑、调试、编译和运行的支持。 最后,压缩包中的"basic"文件很可能包含了上述所有内容的...

    rh-maven33-aether-connector-basic-1.0.2-3.3.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    rh-maven33-aether-connector-basic-1.0.2-3.2.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

Global site tag (gtag.js) - Google Analytics