一、新建项目
我们新建一个Maven Project,菜单File -> new -> other
Next,在新窗口中,选中第一个,打勾,再next。
二、修改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/