内置 .jar 文件(内置于 Netbeans 11.2 maven)无法连接到 mysql
Built .jar file (built in Netbeans 11.2 maven) is not able to connect to mysql
我已经在 Maven Netbeans 中构建了一个应用程序。此应用程序正在从 Jforms 和 Jdialog 获取所有数据并将其存储在 MySQL 中。当我 运行 在 NetBeans 中运行此应用程序时它工作正常,但是当我尝试 运行 构建的 jar 文件时它无法与 MySQL 通信。
我试过使用依赖项构建项目,但它不起作用。
当我从 Netbeans 运行ning 时的输出如下:-
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
Scanning for projects...
------------------------------------------------------------------------
Building CASYS_V3 3.0
------------------------------------------------------------------------
The POM for unknown.binary:AbsoluteLayout:jar:SNAPSHOT is missing, no dependency information available
The POM for unknown.binary:mysql-connector-java:jar:8.0.18 is missing, no dependency information available
--- exec-maven-plugin:1.5.0:exec (default-cli) @ CASYS_V3 ---
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
pom文件如下:-
<?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>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mycompany.casys_v3.StartPage</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<groupId>com.mycompany</groupId>
<artifactId>CASYS_V3</artifactId>
<version>3.0</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
</project>
感谢大家的帮助。我已经在 pom 文件中添加了所有依赖项。它现在正在工作。插件如下:-
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.casys_v3.StartPage</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
我已经在 Maven Netbeans 中构建了一个应用程序。此应用程序正在从 Jforms 和 Jdialog 获取所有数据并将其存储在 MySQL 中。当我 运行 在 NetBeans 中运行此应用程序时它工作正常,但是当我尝试 运行 构建的 jar 文件时它无法与 MySQL 通信。
我试过使用依赖项构建项目,但它不起作用。 当我从 Netbeans 运行ning 时的输出如下:-
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
Scanning for projects...
------------------------------------------------------------------------
Building CASYS_V3 3.0
------------------------------------------------------------------------
The POM for unknown.binary:AbsoluteLayout:jar:SNAPSHOT is missing, no dependency information available
The POM for unknown.binary:mysql-connector-java:jar:8.0.18 is missing, no dependency information available
--- exec-maven-plugin:1.5.0:exec (default-cli) @ CASYS_V3 ---
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
pom文件如下:-
<?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>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mycompany.casys_v3.StartPage</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<groupId>com.mycompany</groupId>
<artifactId>CASYS_V3</artifactId>
<version>3.0</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
</project>
感谢大家的帮助。我已经在 pom 文件中添加了所有依赖项。它现在正在工作。插件如下:-
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.casys_v3.StartPage</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase> <!-- packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>