Maven Installing Guideline

本文详细介绍了如何在Windows系统上安装Maven,包括JDK配置、下载及安装Maven、本地仓库配置、Maven命令使用,以及如何安装第三方JAR包到本地仓库。同时提供了配置Eclipse与Maven插件的方法,并指导如何导入Maven项目及使用Maven进行编译打包。此外,还介绍了如何使用FindBugs进行代码静态分析,以及为特定Maven项目配置本地开发环境。

Maven Handbook

Purpose: This document is help you how to installing maven andinstalling 3rd party JARs

1. Guide to installing Maven

InstallMaven on Windows

1. JDK and JAVA_HOME

Make sure JDK is installed, and “JAVA_HOME” variable is addedin Windows environment variable, and point to the JDK folder.


2. DownloadApache Maven

Visit thisMaven official website:http://maven.apache.org/download.cgi,choosea version and click on the download link, e.g.apache-maven-3.2.1-bin.zip

3. Extract It

Extract the downloaded zip file. In this case, we extractedto c driver and renamed the folder, e.g.C:\Maven.

4. Add MAVEN_HOME

Add a new “MAVEN_HOME” variable to the Windows environment,and point it to your Maven folder.


5. Verification

To verify Maven if installed is correctly, in command prompt,type “mvn -version”.

 

 

 

6. Configuring Maven

a. Configuring your local repository 

Please update the configuration setting.xml(C:\Tools\Maven\apache-maven-3.1.0\conf).The location of your local repository can be changed in your userconfiguration. The default value is ${user.home}/.m2/repository/.

<localRepository>C:/M3/repository</localRepository>

 

 

b. If you have not installed Eclipse. Recommended Eclipse4.3.0 and above. It integrated with Maven plugin.

Download link https://www.eclipse.org/downloads

 

 

 

 

c. If you have installed Eclipse, but it’s not integratedMaven function.

Open Eclipse, please choose “Help” > “Install NewSoftware…”, then type the following link to download the Maven plugin.

http://download.eclipse.org/technology/m2e/releases/1.2/1.2.0.20120903-1050

 

 

If installed ok, Choose “Windows” > “Preferences” >“Maven”

 

 

 

 

Please select the settings.xml for your installed the mavenpath.

 

 

 

 

 

7. Import Maven project

Choose “File” > “Import” > “Existing MavenProjects” 


8. Maven Command

Compilethe application: clean package install

Packagethe project: clean package package

For jetty:Start the application: clean jetty:run

ForTomcat: Start the application: clean tomcat7:run

 

 

2.  Guideto installing 3rd party JARs

1.Please prepares the JAR on your local machine

eg: C:\M3\ext\kacdr\sqlframework.jar

2. Please usesmaven command to install the JAR to your local repository.

eg: mvn install:install-file-DgroupId=com.cathaypacific.sqlframework -DartifactId=sqlframework-Dversion=1.0 -Dpackaging=jar -Dfile=C:\M3\ext\kacdr\sqlframework.jar -DgeneratePom=true

3.Configure the dependency on the pom.xml file.

<dependency>

            <groupId>com.cathaypacific.sqlframework</groupId>

            <artifactId>sqlframework</artifactId>

            <version>1.0</version>

</dependency>

4. Right click the project “KACrewDirectRequests”, select“Maven” > “Update Project…”

mvninstall:install-file -DgroupId=com.cathaypacific.sqlframework-DartifactId=sqlframework -Dversion=1.0 -Dpackaging=jar-Dfile=C:\M3\ext\kacdr\sqlframework.jar -DgeneratePom=true

 

 

5. Find Bugs uses static analysis to identify hundreds ofdifferent potential types of errors in Java programs.

Find Bugs for maven project:

<plugin>

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

            <artifactId>findbugs-maven-plugin</artifactId>

            <version>2.3.2</version>

            <configuration>

                        <findbugsXmlOutput>true</findbugsXmlOutput>

                        <findbugsXmlWithMessages>true</findbugsXmlWithMessages>

                        <xmlOutput>true</xmlOutput>

                        <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory>

            </configuration>

</plugin>

 

3. Configuring localdev for CSC Maven project

1. Selectthe project, right click “Run As” > “Run Configurations…” , please add theparameter as the following:

Name=spring.profiles.default

Value=local_dev


2. Please add the comment for the following parameter on the Web.xml

<!-- 

    <context-param>

              <param-name>spring.profiles.default</param-name>

              <param-value>dev</param-value>

    </context-param>

-->

 

-server -Xms256m -Xmx512m -XX:PermSize=256m-XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDetails-Xloggc:%M2_HOME%/gc.log -XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=%M2_HOME%/java_pid<pid>.hprof

### Maven Wrapper 的检查与安装 Maven 并不像 Gradle 一样默认提供 `Wrapper` 功能,但可以通过一些额外的配置实现类似的效果。如果需要在项目中使用 Maven Wrapper,通常可以借助第三方工具如 `mvnw` 来实现。这种做法可以帮助确保项目在不同环境中使用一致的 Maven 版本,而无需依赖全局安装的 Maven。 要检查是否已经存在 Maven Wrapper,可以在项目的根目录下查看是否存在以下文件: - `mvnw` - `.mvn/wrapper/maven-wrapper.properties` 如果这些文件存在,则表示项目已经配置了 Maven Wrapper。如果没有,则需要手动安装和配置。 要安装 Maven Wrapper,可以按照以下步骤操作: 1. 下载 `mvnw` 脚本并将其添加到项目根目录中。 2. 创建 `.mvn/wrapper` 目录,并在其中放置 `maven-wrapper.properties` 文件,指定所需的 Maven 版本 [^2]。 3. 确保所有文件具有正确的权限以便执行。 下面是一个简单的示例,展示如何手动创建 Maven Wrapper 配置: ```bash # 创建 .mvn/wrapper 目录 mkdir -p .mvn/wrapper # 下载 maven-wrapper.jar 和 maven-wrapper.properties curl -o .mvn/wrapper/maven-wrapper.jar https://raw.githubusercontent.com/takari/maven-wrapper/master/maven-wrapper.jar curl -o .mvn/wrapper/maven-wrapper.properties https://raw.githubusercontent.com/takari/maven-wrapper/master/maven-wrapper.properties ``` 修改 `maven-wrapper.properties` 文件以指定所需的 Maven 版本,例如: ```properties # Distribution definition distributionUrl=https\://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip ``` 最后,在项目根目录中添加可执行的 `mvnw` 脚本: ```bash curl -o mvnw https://raw.githubusercontent.com/takari/maven-wrapper/master/mvnw chmod +x mvnw ``` 完成以上步骤后,即可通过 `./mvnw` 命令来运行 Maven 构建,它将自动下载并使用指定版本的 Maven [^4]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

啸梦飞扬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值