美文网首页
如何在Eclipse中配置并使用Maven?

如何在Eclipse中配置并使用Maven?

作者: ChaseWong | 来源:发表于2019-12-25 20:10 被阅读0次

1.配置Maven

2.创建Maven项目

3.导入Maven项目

4.编译并打包Maven项目

1.配置Maven

打开Eclipse IDE 点击菜单栏 "Window" ----> "Preference", settings.xml在下面。

image.png

搜索Maven点击 "User Setting",浏览找到 settings.xml 点击 "Update Settings" ----> "Apply and Close",这样你的Maven就配置好了。

image.png
<?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>D:/Eclipse_space/my_maven_local_repository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
  </servers>

  <mirrors>
      <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central</url>
        </mirror>

        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <mirrorOf>central</mirrorOf>
        </mirror>

        <mirror>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2</url>
            <mirrorOf>central</mirrorOf>
        </mirror>

        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2</url>
        </mirror>

        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
        </mirror>

        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>

        <mirror>
            <id>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>

        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public</url>
            <mirrorOf>central</mirrorOf>
        </mirror>  
  </mirrors>

  <profiles>
      <profile>
                <id>jdk-1.8</id>
                <activation>
                      <activeByDefault>true</activeByDefault>
                      <jdk>1.8</jdk>
                </activation>
                <properties>
                      <maven.compiler.source>1.8</maven.compiler.source>
                      <maven.compiler.target>1.8</maven.compiler.target>
                      <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
                </properties>
         </profile>
         <profile>
                <id>repository_set</id>
                <repositories>
                        <repository>
                            <snapshots>
                                <enabled>false</enabled>
                            </snapshots>
                            <id>public</id>
                            <name>Public Repository</name>
                            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                        </repository>
                </repositories>
                <pluginRepositories>
                        <pluginRepository>
                              <releases>
                                    <updatePolicy>never</updatePolicy>
                              </releases>
                              <snapshots>
                                    <enabled>false</enabled>
                              </snapshots>
                              <id>public</id>
                              <name>Public Repository</name>
                              <url>http://maven.aliyun.com/nexus/content/groups/public</url>
                        </pluginRepository>
                 </pluginRepositories>
            </profile>
      </profiles>
</settings>

2.创建Maven项目
打开Eclipse IDE 点击菜单栏 "File"----> "New" ----> "Maven Project" 点击 "Next" , 默认选择 "quickstart", 继续点击 "Next"


image.png image.png image.png

输入你的Package到Group Id,输入你的项目名到Artifact Id,点击 "Finish"。
完成以上你已经建好了一个Maven项目。

3.导入Maven项目
打开Eclipse IDE 点击菜单栏 "File"----> "Import",搜索Maven 选择 "Existing Maven Projects",点击 "Next".

image.png

点击浏览(Browse),找到要导入的Maven项目,如果显示如下图的pom.xml,那么它就是正确的。然后点击 "Finish"。

image.png

完成以上你已经把你已有的Maven项目导入进来了。

4.编译并打包Maven项目
首先,你需要右击你的Maven项目,然后点击 "Maven" ----> "Update Project", 选择你的项目点击 "OK"


image.png image.png

右击你的项目点击 "Run As" ----> "Maven build"
Goals: clean compile package(须为小写)
(clean: 清除target中已经编译过的文件)
(compile: 编译你的代码)
(package: 把你的项目打包)
点击 "Run"。

查看你的控制台,找到你的.jar文件的路径。


image.png

相关文章

网友评论

      本文标题:如何在Eclipse中配置并使用Maven?

      本文链接:https://www.haomeiwen.com/subject/liqhoctx.html