我使用 maven 和 Intellij 2021 .1.3 制作了一个模块化的 Javafx 项目。我想对它使用 MySQL。我将依赖项添加到 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>org.openjfx</groupId>
<artifactId>accountZeyny</artifactId>
<version>1.0-snAPSHOT</version>
<packaging>jar</packaging>
<name>accountZeyny</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>15</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>ORGZ</name>
</organization>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>17-ea+9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<configuration>
<compress>2</compress>
<noHeaderFiles>true</noHeaderFiles>
<stripDebug>true</stripDebug>
<noManPages>true</noManPages>
<launcher>accountZeyny</launcher>
<jlinkImageName>accountZeyny</jlinkImageName>
<jlinkZipName>accountZeyny</jlinkZipName>
<mainClass>accountZeyny/org.openjfx.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
然后在module-info.java中添加依赖:
module accountZeyny {
requires javafx.fxml;
requires javafx.controls;
requires java.sql;
requires javafx.swing;
requires mysql.connector.java;
opens org.openjfx to javafx.fxml;
exports org.openjfx;
exports org.openjfx.controllers to javafx.fxml;
opens org.openjfx.controllers to javafx.fxml;
exports org.openjfx.controllers.list to javafx.fxml;
opens org.openjfx.controllers.list to javafx.fxml;
exports org.openjfx.controllers.dataScreenControllers to javafx.fxml;
opens org.openjfx.controllers.dataScreenControllers to javafx.fxml;
exports org.openjfx.controllers.dialogControllers to javafx.fxml;
opens org.openjfx.controllers.dialogControllers to javafx.fxml;
exports org.openjfx.settergetters to javafx.base;
opens org.openjfx.settergetters to javafx.base;}
当使用 Plugins->javafx->javafx:run 运行它时,它工作正常。但是当我尝试打包项目时,我收到警告:
* Required filename-based automodules detected: [mysql-connector-java-8.0.25.jar]. Please don't publish this project to a public artifact repository! *
运行时出现错误:
no main manifest attribute,in D:\account-Zeyny\target\accountZeyny-1.0-snAPSHOT.jar
有什么帮助吗??