Eclipse如何新建Maven项目

本文介绍了在Eclipse中创建Maven项目的步骤。首先,通过File -> new -> other来新建一个Maven Project,然后在配置窗口进行相应选择。接着,详细说明了如何修改pom.xml文件,设置入口类的全名,例如<mainClass>socket.KDC</mainClass>,并提供了jar仓库的网址https://mvnrepository.com/供参考。

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

一、新建项目

我们新建一个Maven Project,菜单File -> new -> other

image.png

Next,在新窗口中,选中第一个,打勾,再next。

image.png

image.png

 

二、修改pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cn.edu.imu</groupId>
  <artifactId>InfoSafety</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <!-- 依赖的jar包 -->
  <dependencies>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <!-- 测试代码与程序主代码分离,src/test下的代码不是使用Main方法机制运行的,
    所以要添加JUnit组件 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
      <!-- 保证Maven最终打包发布的时候不会把这种jar包打到最终的包里 -->
    </dependency>
    
    <!-- 连接数据库所需要的jar包 -->
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.32</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-dbcp2</artifactId>
      <version>2.2.0</version>
    </dependency>
    
  </dependencies>
  <!-- 这里如果不指定是使用默认的配置 mave3默认jdk1.5 -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
      
      <!-- 打包插件,可以把jar包当做独立程序直接运行 -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>socket.KDC</mainClass>   
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>assembly</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      
    </plugins>
  </build>
  
  <!--阿里云仓库配置,该配置可以在setting配置,也可以在pom.xml中配置-->
  <!-- 首先配置仓库的服务器位置,首选阿里云,也可以配置镜像方式,效果雷同 -->
  <repositories>
    <repository>
      <id>nexus-aliyun</id>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </repository>
  </repositories>
  
</project>

其中<mainClass>socket.KDC</mainClass>中,socket.KDC为入口类的全名。

jar仓库的网址是:https://mvnrepository.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值