javafx maven插件,编译时无法找到自己的资源

时间:2015-11-13 19:11:07

标签: java maven pom.xml executable-jar

我无法使用maven javafx插件编译我的javafx应用程序。该程序在IDE中运行良好,但每当我使用mvn jfx:jar编译它时,它输出的文件都无法找到自己的资源。

聚甲醛

<?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>com.coursecruncher</groupId>
    <artifactId>heelbot</artifactId>
    <version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.1.4</version>
            <configuration>
                <mainClass>MainApp</mainClass>
                <verbose>true</verbose>
                <jfxMainAppJarName>heelbot.jar</jfxMainAppJarName>
                <deployDir>${project.basedir}/src/main/resources</deployDir>
                <updateExistingJar>true</updateExistingJar>
                <allPermissions>true</allPermissions>
            </configuration>
        </plugin>

    </plugins>

</build>

    <dependencies>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.48.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.2.4</version>
        </dependency>
    </dependencies>

</project>

项目结构

├── src
│   ├── main
│   │   ├── java 
│   │   │     ├── CoreController(class)
│   │   │     ├── Login(class)
│   │   │     ├── LoginController(class)
│   │   │     ├── MainApp(class)
│   │   │     └── PropertiesManager(class)
│   │   │        
│   │   ├── resources
│   │   │     ├── appProperties.properties
│   │   │     ├── defaultProperties.properties
│   │   │     ├── welcome.fxml
│   │   │     ├── core.fxml
│   │   │     └── Heelbot.css 
使用java -jar heelbot.jar

运行时产生

错误

java.io.FileNotFoundException: src\main\resources\defaultProperties.properties (
The system cannot find the path specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at PropertiesManager.editProperty(PropertiesManager.java:11)
        at LoginController.initialize(LoginController.java:60)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
        at Main.start(Main.java:53)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163
(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Platfor
mImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.
java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformI
mpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatch
er.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.ja
va:191)
        at java.lang.Thread.run(Thread.java:745)
java.io.FileNotFoundException: src\main\resources\defaultProperties.properties (
The system cannot find the path specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at PropertiesManager.queryProperty(PropertiesManager.java:34)
        at LoginController.initialize(LoginController.java:106)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
        at Main.start(Main.java:53)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163
(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Platfor
mImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.
java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformI
mpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatch
er.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.ja
va:191)
        at java.lang.Thread.run(Thread.java:745)
Nov 12, 2015 6:06:20 PM Main start
SEVERE: null
javafx.fxml.LoadException:
file:/D:/Programing%20Data/Projects/CourseCruncher/target/jfx/app/heelbot.jar!/w
elcome.fxml

        at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
        at Main.start(Main.java:53)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163
(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Platfor
mImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.
java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformI
mpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatch
er.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.ja
va:191)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
        at java.util.Properties$LineReader.readLine(Properties.java:434)
        at java.util.Properties.load0(Properties.java:353)
        at java.util.Properties.load(Properties.java:341)
        at PropertiesManager.queryProperty(PropertiesManager.java:39)
        at LoginController.initialize(LoginController.java:106)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
        ... 17 more

0 个答案:

没有答案