首页 > 编程知识 正文

maven项目使用配置文件,配置maven私服并使用

时间:2023-05-04 00:15:24 阅读:219888 作者:3169

文章目录 下载 && 解压配置文件修改环境变量配置使用测试

下载 && 解压

在官网:http://maven.apache.org/download.cgi
下载 https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.8.1/dtdlqaries/apache-maven-3.8.1-dtdlq.zip

解压到指定目录(我是~/javaweb/) unzip apache-maven-3.8.1-dtdlq.zip -d ~/javaweb/

查看该目录下的内容:

文本格式:

leung@wuyujin ~ % ls -alG ~/javaweb total 0drwxr-xr-x 4 leung staff 128 6 2 22:20 .drwxr-xr-x+ 38 leung staff 1216 6 2 22:03 ..drwxr-xr-x 9 leung staff 288 11 7 2019 apache-maven-3.8.1drwxr-xr-x 2 leung staff 64 6 2 22:20 mvnrepoleung@wuyujin ~ % ls -alG ~/javaweb/apache-maven-3.8.1 total 64drwxr-xr-x 9 leung staff 288 11 7 2019 .drwxr-xr-x 4 leung staff 128 6 2 22:20 ..-rw-r--r-- 1 leung staff 17504 11 7 2019 LICENSE-rw-r--r-- 1 leung staff 5141 11 7 2019 NOTICE-rw-r--r-- 1 leung staff 2612 11 7 2019 README.txtdrwxr-xr-x 8 leung staff 256 11 7 2019 dtdlqdrwxr-xr-x 4 leung staff 128 11 7 2019 bootdrwxr-xr-x 6 leung staff 192 6 2 22:11 confdrwxr-xr-x 65 leung staff 2080 11 7 2019 libleung@wuyujin ~ %

这熟悉的目录结构。

配置文件修改

见 Maven settings.xml 配置项

环境变量配置

只是为了在任意目录都可以直接使用mvn命令(且不需要输入命令的全路径)。
本步骤可省略

配置项:

export MVN_HOME=/Users/leung/javaweb/apache-maven-3.8.1export PATH=$MVN_HOME/dtdlq:$PATH

将其写入当前用户、当前shell的配置文件中,我的是~/.zshrc

写入后保存,重载配置文件,使之生效:source ~/.zshrc

查看配置是否生效:

leung@wuyujin ~ % echo $MVN_HOME/Users/leung/javaweb/apache-maven-3.8.1leung@wuyujin ~ % echo $PATH/Users/leung/javaweb/apache-maven-3.8.1/dtdlq:/System/Volumes/Data/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/:/usr/local/dtdlq:/usr/dtdlq:/dtdlq:/usr/sdtdlq:/sdtdlq:/Library/Apple/usr/dtdlqleung@wuyujin ~ % where mvn/Users/leung/javaweb/apache-maven-3.8.1/dtdlq/mvnleung@wuyujin ~ % mvn --versionApache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)Maven home: /Users/leung/javaweb/apache-maven-3.8.1Java version: 1.8.0_291, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jreDefault locale: zh_CN, platform encoding: UTF-8OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"leung@wuyujin ~ % 使用测试

其实可以在命令行直接使用maven命令新建不同类型的java项目。

新建一个web项目mvn archetype:generate -DgroupId=com.wuyujin -DartifactId=webdemo -DarchetypeArtifactId=maven-archetype-webapp

leung@wuyujin coderepo % mvn archetype:generate -DgroupId=com.wuyujin -DartifactId=webdemo -DarchetypeArtifactId=maven-archetype-webapp[INFO] Scanning for projects...[INFO] [INFO] ------------------< org.apache.maven:standalone-pom >-------------------[INFO] Building Maven Stub Project (No POM) 1[INFO] --------------------------------[ pom ]---------------------------------[INFO] [INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>>[INFO] [INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<<[INFO] [INFO] [INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom ---[INFO] Generating project in Interactive mode[WARNING] No archetype found in remote catalog. Defaulting to internal catalogDownloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pomDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom (533 B at 416 B/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pomDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom (1.5 kB at 1.6 kB/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pomDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom (1.3 kB at 1.4 kB/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-parent/4/maven-parent-4.pomDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-parent/4/maven-parent-4.pom (10.0 kB at 10 kB/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/apache/3/apache-3.pomDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/apache/3/apache-3.pom (3.4 kB at 4.1 kB/s)Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jarDownloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/archetypes/maven-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar (3.9 kB at 3.3 kB/s)[INFO] Using property: groupId = com.wuyujin[INFO] Using property: artifactId = webdemoDefine value for property 'version' 1.0-SNAPSHOT: : [INFO] Using property: package = com.wuyujinConfirm properties configuration:groupId: com.wuyujinartifactId: webdemoversion: 1.0-SNAPSHOTpackage: com.wuyujin Y: : y[INFO] ----------------------------------------------------------------------------[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0[INFO] ----------------------------------------------------------------------------[INFO] Parameter: basedir, Value: /Users/leung/javaweb/coderepo[INFO] Parameter: package, Value: com.wuyujin[INFO] Parameter: groupId, Value: com.wuyujin[INFO] Parameter: artifactId, Value: webdemo[INFO] Parameter: packageName, Value: com.wuyujin[INFO] Parameter: version, Value: 1.0-SNAPSHOT[INFO] project created from Old (1.x) Archetype in dir: /Users/leung/javaweb/coderepo/webdemo[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 16.377 s[INFO] Finished at: 2021-06-02T22:49:59+08:00[INFO] ------------------------------------------------------------------------leung@wuyujin coderepo %

接下来在命令行完成install和package, run jar.

cd webdemomvn installmvn package

package 动作会生成一个 war
该 wat 放置到 tomcat/jetty 等servlet容器中就可以运行/访问。

当执行过mvn archetype:generate -DgroupId=com.wuyujin -DartifactId=webdemo -DarchetypeArtifactId=maven-archetype-webapp之后,
会生成webdemo,其中有pom.xml以及src/目录及src/目录下的默认源码。

mvn install 会生成 target/目录及其下内容。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。