【发布时间】:2019-04-07 01:35:24
【问题描述】:
它仍然没有找到 FXML 位置。我已经搞砸了 输出目录和 目录和 进入 FXMLLoader 的 URL 无济于事:
Parent root = FXMLLoader.load(getClass().getResource("fxml/ui.fxml"));
此应用程序在哪里寻找资源?
目录:
在:
PROJECT/src/main/java/mypackage/Main.java
项目/src/main/resources/fxml/ui.fxml
输出:
PROJECT/target/AppName-1.0-SNAPSHOT.jar
PROJECT/target/AppName-1.0-SNAPSHOT-shaded.jar
PROJECT/target/classes/myPackage/Main.class
项目/目标/fxml/ui.fxml
我的 POM:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.fxml</include>
</includes>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--or <release>10</release>-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.potatospy.NewMain</mainClass>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
【问题讨论】:
-
您为什么要添加和覆盖
maven-resource-plugin默认行为? -
@JoséPereda 我从 apache maven 资源页面获取。看来我必须以这种方式指定我的资源目录。如果我删除覆盖,它仍然不知道位置
标签: maven javafx maven-shade-plugin