赞
踩
MySQL官网上面提供的驱动编译方法,是通过ant编译的,所有依赖包都要自行下载,虽然提供了下载地址,但是过程也有点麻烦。
通过maven的方式进行编译,更加简洁,明了。
(1)MySQL官方提供的编译方法,比较古老
MySQL :: MySQL Connector/J 8.0 Developer Guide :: 4.3 Installing from Sourcehttps://dev.mysql.com/doc/connector-j/8.0/en/connector-j-installing-source.html(2)mysql-connect-j源码下载:
GitHub - mysql/mysql-connector-j: MySQL Connector/Jhttps://github.com/mysql/mysql-connector-j(3)jdk1.8下载
jdk需要选择1.8,可以在oracle官网下载:Java Downloads | Oraclehttps://www.oracle.com/java/technologies/downloads/#java8
打开网页是最新版java20,往下拉选择java 8,64位操作系统选择x64,32位操作系统选择x86
将pom.xml文件中的已有内容进行替换,具体如下
- <?xml version="1.0" encoding="UTF-8"?>
- <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>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>8.0.20</version>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>2.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-annotations</artifactId>
- <version>3.2</version>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <version>5.8.2</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>5.6.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-runner</artifactId>
- <version>1.6.2</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.protobuf</groupId>
- <artifactId>protobuf-java</artifactId>
- <version>3.22.0</version>
- </dependency>
-
- <dependency>
- <groupId>com.mchange</groupId>
- <artifactId>c3p0</artifactId>
- <version>0.9.5.5</version>
- </dependency>
-
- <dependency>
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.28.0-GA</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.36</version>
- </dependency>
-
- <dependency>
- <groupId>com.oracle.oci.sdk</groupId>
- <artifactId>oci-java-sdk-common</artifactId>
- <version>2.27.0</version>
- </dependency>
- </dependencies>
-
- <build>
- <finalName>${project.artifactId}-${project.version}</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>3.0.2</version>
- <configuration>
- <archive>
- <addMavenDescriptor>false</addMavenDescriptor>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-clean-plugin</artifactId>
- <version>2.5</version>
- <configuration>
- <filesets>
- <fileset>
- <directory>${basedir}/jar</directory>
- </fileset>
- </filesets>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.8</version>
- <executions>
- <execution>
- <id>add-build</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/build/java/</source>
- <source>src/demo/java/</source>
- <source>src/generated/java/</source>
- <source>src/legacy/java/</source>
- <source>src/main/core-api/java/</source>
- <source>src/main/core-impl/java/</source>
- <source>src/main/protocol-impl/java/</source>
- <source>src/main/user-api/java/</source>
- <source>src/main/user-impl/java/</source>
- </sources>
- </configuration>
- </execution>
- <execution>
- <id>add-test</id>
- <phase>generate-test-sources</phase>
- <goals>
- <goal>add-test-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/test/java/</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.21.0</version>
- <dependencies>
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-surefire-provider</artifactId>
- <version>1.2.0-M1</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>5.6.2</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
- </project>
(1)pom中依赖吧的版本可能和mysql-connector-j版本有关,上面pom.xml内容是2023.3.8日的,如果驱动代码更新,依赖包的版本可能需同步更新
由于工程默认会跑自带的ut测试用例,耗时较长
打包完成后,工程目录下会多一个target文件夹,里面有打包结果jar文件
本文记录了mysql-connector-j也就是mysql的jdbc驱动源码编译打包的方式,通过maven方式进行打包,更加方便,需要重点注意就是pom.xml文件中的依赖包名称和版本内容。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。