maven的学习之路——intellij的maven1.5JDK问题

本文详细介绍了Maven作为跨平台的Java项目管理工具,包括其安装与配置过程、编译与测试方法、文件组织结构、约定目录、坐标解析、继承特性、私服配置等核心内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、什么是maven

 Maven是一个跨平台的项目管理工具,主要用于基于java平台的项目构建,依赖管理。


后面自动执行前面的操作

2、maven的安装与配置

A、从官网下载maven
B、设定path路径

把下载下来的maven解压缩,然后有一个bin文件夹,这是一个bin的文件夹的目录

       F:\work\course\maven\maven\bin

把该目录追加到环境变量的path中。

C、利用命令行检查是否成功


E、把settings.xml文件复制到C:\Users\Think\.m2路径中
F、修改settings.xml文件

<localRepository>F:/work/course/maven/mavenRepository/</localRepository>

指定仓库的路径

 

在这里mavenRepository就是仓库的路径

G、maven文件说明:

bin中存放可执行的二进制文件

conf存放settings.xml文件

lib  运行maven所依赖的jar包


H、maven的约定:

src/main/java                   存放项目的java文件

src/main/resources          存放项目的资源文件,如spring,hibernate的配置文件

src/test/java                     存放所有的测试的java文件

src/test/resources            存放测试用的资源文件

target                               项目输出位置

pom.xml                           文件


3、maven的编译与测试

进入项目根目录:mvn compile编译操作,mvn test测试target/surefire-reports存放测试报告。

mvn package 打包

mvn install打包放到仓库中

intellij的1.5过时问题,在pom.xml文件中加入:
<properties>
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
</properties>

4、maven的继承

将一个的packaging写成pom,发布后
在另一个pom文件中将dependency写成parent就可以了。

pom.xml(A)
<groupId>groupId</groupId>
<artifactId>ss</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

pom.xml(B)
<parent>
     <groupId>groupId</groupId>
     <artifactId>ss</artifactId>
     <version>1.0-SNAPSHOT</version>
</parent>

5、maven的坐标

groupId:定义当前maven项目属于哪个项目        org.hibernate

artifactId:定义实际项目中的某一个模块             hibernate-c3p0

version:定义当前项目的当前版本                       4.3.10.Final

packaging:定义当前项目的打包方式


文件名称一般就是: 

hibernate-c3p0-4.3.10.Final.jar          artifactId+version.jar就是文件名


根据这些坐标,在maven库中可以找到唯一的jar包



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


<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
    <localRepository>
        F:\work\course\maven\itheima05Repository
    </localRepository>
    
    
    <!-- interactiveMode
    | This will determine whether maven prompts you when it needs input. If set to false,
    | maven will use a sensible default value, perhaps based on some other setting, for
    | the parameter in question.
    |
    | Default: true
    <interactiveMode>true</interactiveMode>
    -->
    
    <!-- offline
    | Determines whether maven should attempt to connect to the network when executing a build.
    | This will have an effect on artifact downloads, artifact deployment, and others.
    |
    | Default: false
    <offline>false</offline>
    -->
    
    <!-- pluginGroups
    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
    |-->
    <pluginGroups>
        <!-- pluginGroup
        | Specifies a further group identifier to use for plugin lookup.
        <pluginGroup>com.your.plugins</pluginGroup>
        -->
    </pluginGroups>
    
    <!-- proxies
    | This is a list of proxies which can be used on this machine to connect to the network.
    | Unless otherwise specified (by system property or command-line switch), the first proxy
    | specification in this list marked as active will be used.
    |-->
    <proxies>
        <!-- proxy
        | Specification for one proxy, to be used in connecting to the network.
        |
        <proxy>
        <id>optional</id>
        <active>true</active>
        <protocol>http</protocol>
        <username>proxyuser</username>
        <password>proxypass</password>
        <host>proxy.host.net</host>
        <port>80</port>
        <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
        </proxy>
        -->
    </proxies>
    
    <!-- servers
    | This is a list of authentication profiles, keyed by the server-id used within the system.
    | Authentication profiles can be used whenever maven must make a connection to a remote server.
    |-->
    <servers>     
        
        <!-- server
        | Specifies the authentication information to use when connecting to a particular server, identified by
        | a unique name within the system (referred to by the 'id' attribute below).
        |
        | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
        |       used together.
        |
        <server>
        <id>deploymentRepo</id>
        <username>repouser</username>
        <password>repopwd</password>
        </server>
        -->
        
        <!-- Another sample, using keys to authenticate.
        <server>
        <id>siteServer</id>
        <privateKey>/path/to/private/key</privateKey>
        <passphrase>optional; leave empty if not used.</passphrase>
        </server>
        -->
    </servers>
    
    <!-- mirrors
    | This is a list of mirrors to be used in downloading artifacts from remote repositories.
    |
    | It works like this: a POM may declare a repository to use in resolving certain artifacts.
    | However, this repository may have problems with heavy traffic at times, so people have mirrored
    | it to several places.
    |
    | That repository definition will have a unique id, so we can create a mirror reference for that
    | repository, to be used as an alternate download site. The mirror site will be the preferred
    | server for that repository.
    |-->
    
    <mirrors>

    <mirror>
        <id>
            nexus
        </id>
        <name>
            internal nexus repository
        </name>
        <url>
            http://localhost:8080/nexus/content/groups/public/
        </url>
        <mirrorOf>
            central
        </mirrorOf>
    </mirror>

    <!-- mirror
    | Specifies a repository mirror site to use instead of a given repository. The repository that
    | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
    | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
    |
    <mirror>
    <id>mirrorId</id>
    <mirrorOf>repositoryId</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://my.repository.com/repo/path</url>
    </mirror>
    -->
    
    </mirrors>    
   
    <profiles>
        <!-- profile
        | Specifies a set of introductions to the build process, to be activated using one or more of the
        | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
        | or the command line, profiles have to have an ID that is unique.
        |
        | An encouraged best practice for profile identification is to use a consistent naming convention
        | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
        | This will make it more intuitive to understand what the set of introduced profiles is attempting
        | to accomplish, particularly when you only have a list of profile id's for debug.
        |
        | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
        <profile>
        <id>jdk-1.4</id>
        
        <activation>
        <jdk>1.4</jdk>
        </activation>
        
        <repositories>
        <repository>
        <id>jdk14</id>
        <name>Repository for JDK 1.4 builds</name>
        <url>http://www.myhost.com/maven/jdk14</url>
        <layout>default</layout>
        <snapshotPolicy>always</snapshotPolicy>
        </repository>
        </repositories>
        </profile>
        -->
        
        <!--
        | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
        | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
        | might hypothetically look like:
        |
        | ...
        | <plugin>
        |   <groupId>org.myco.myplugins</groupId>
        |   <artifactId>myplugin</artifactId>
        |
        |   <configuration>
        |     <tomcatLocation>${tomcatPath}</tomcatLocation>
        |   </configuration>
        | </plugin>
        | ...
        |
        | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
        |       anything, you could just leave off the <value/> inside the activation-property.
        |
        <profile>
        <id>env-dev</id>
        
        <activation>
        <property>
        <name>target-env</name>
        <value>dev</value>
        </property>
        </activation>
        
        <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
        </properties>
        </profile>
        -->

        <profile>
            <id>
                nexus
            </id>
            <repositories>
                <repository>
                    <id>
                        nexus
                    </id>
                    <name>
                        local private nexus
                    </name>
                    <url>
                        http://localhost:8080/nexus/content/groups/public
                    </url>
                    <releases>
                        <enabled>
                            true
                        </enabled>
                    </releases>
                </repository>
            </repositories>
        </profile>
		
		
        <profile>
            <id>
                nexus-snapshots
            </id>
            <repositories>
                <repository>
                    <id>
                        nexus-snapshots
                    </id>
                    <name>
                        local private nexus snapshots
                    </name>
                    <url>
                        http://localhost:8080/nexus/content/groups/public-snapshots
                    </url>
                    <releases>
                        <enabled>
                            true
                        </enabled>
                    </releases>
                </repository>
            </repositories>
        </profile>

    </profiles>
	<!--
    <activeProfiles>
        <activeProfile>
            nexus
        </activeProfile>
    </activeProfiles>
    -->
	<!-- activeProfiles
    | List of profiles that are active for all builds.
    |
    <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
    </activeProfiles>
    -->
</settings>









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值