Intellij Idea下的Javafx maven部署

Intellij Idea下的Javafx maven部署,maven,intellij-idea,javafx,pom.xml,Maven,Intellij Idea,Javafx,Pom.xml,我在Intellij idea Editor下有一个基于maven的项目。我正在使用JavaFXMaven插件。 我的目标是将我的项目部署为EXE或MSI可安装文件。 由于这是第一次使用maven,plz帮助我对pom.xml文件进行正确的配置。或者有没有比maven更简单的方法可以帮助我实现我的目标,所以,请不要犹豫 所以,这是我的pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://ma

我在Intellij idea Editor下有一个基于maven的项目。我正在使用JavaFXMaven插件。 我的目标是将我的项目部署为EXE或MSI可安装文件。 由于这是第一次使用maven,plz帮助我对pom.xml文件进行正确的配置。或者有没有比maven更简单的方法可以帮助我实现我的目标,所以,请不要犹豫

所以,这是我的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>com.abdo.EntrepriseLimted</groupId>
    <artifactId>EntrepriseLimited</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>ENTREPRISELIMITED</name>
    <url>http://maven.apache.org</url>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>

                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>

                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <plugin>
    <groupId>com.zenjava</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>8.2.0</version>
    <configuration>
        <mainClass>MainApplication</mainClass>
        <verbose>true</verbose>
        <vendor>Abdo</vendor>
    </configuration>
    <executions>
        <execution>
            <!-- required before build-native -->
            <id>create-jfxjar</id>
            <phase>package</phase>
            <goals>
                <goal>build-jar</goal>
            </goals>
        </execution>
        <execution>
            <id>create-native</id>
            <phase>package</phase>
            <goals>
                <goal>build-native</goal>
            </goals>
        </execution>
    </executions>
</plugin>


        </plugins>

        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources/fxml</directory>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
        </resources>

    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>8.40.10</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1206-jdbc42</version>
        </dependency>
        <dependency>
            <groupId>org.jfxtras</groupId>
            <artifactId>jfxtras-labs</artifactId>
            <version>8.0-r4</version>
        </dependency>
        <dependency>
            <groupId>org.jfxtras</groupId>
            <artifactId>jfxtras-controls</artifactId>
            <version>8.0-r4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.16</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.16</version>
        </dependency>
    </dependencies>
</project>
她是我打开新窗口的主窗口的控制器,基于用户 行动:

public class MainWindowController implements Initializable {

    // Tabbed pane
    @FXML
    private TabPane tbTabPaneHome;


    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

     private void createTab(String title, AnchorPane parent) {
        Tab tab = new Tab(title);
        for (Tab child : tbTabPaneHome.getTabs()) {
            if (child.getText().equals(title)) {
                tbTabPaneHome.getSelectionModel().select(child);
                return;
            }
        }
        tab.setContent(parent);
        tbTabPaneHome.getTabs().addAll(tab);
        tbTabPaneHome.getSelectionModel().select(tab);
    }

    private Parent loadContent(URL resources) {
        try {
            FXMLLoader loader = new FXMLLoader();
            Parent parent = new AnchorPane();
            loader.setLocation(resources);
            parent = loader.load();
            return parent;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private AnchorPane buildEntrepriseTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/entreprise/entreprise.fxml"));
        return parent;
    }

    private AnchorPane buildTransactionTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/transaction/transaction.fxml"));
        return parent;
    }

    private AnchorPane buildAccountTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/account/account.fxml"));
        return parent;
    }

    private AnchorPane buildTypeOfTransactionTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/TypeOfTransaction.fxml"));
        return parent;
    }


    private AnchorPane buildUserTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/user/user.fxml"));
        return parent;
    }

    // Event Handling
    // Action events
    @FXML
    public void listDesEntrepriseClicked() {
        createTab("Entreprise", buildEntrepriseTab());
    }

    @FXML
    public void listTransactionClicked() {
        createTab("Transaction", buildTransactionTab());
    }

    @FXML
    public void listTypeOfTransactionClicked() {
        createTab("TypeOfTransaction", buildTypeOfTransactionTab());
    }

    @FXML
    public void listAccountClicked() {
        createTab("Compte", buildAccountTab());
    }

    @FXML
    public void listUserClicked() {
        createTab("Utilisateur", buildUserTab());
    }


}

您将
jar
文件作为输出,因为您执行了
jfx:jar
目标

要获取本机软件包,您应该调用
jfx:native
。您可以在
target/jfx/native/
下找到您的软件包


顺便说一下,有一个很好的maven配置生成器(插件的版本有点过时,但仍然有效)。它不仅允许您生成可工作的maven插件配置,还解释了所有配置属性,并告诉您应该调用什么目标。

通常我只创建exe,如果在
jfx/native/{project name}-${project verions}
下的target中找到,那么在执行本机构建后如何配置pom.xml,它完美地生成了一个可执行文件,但只有主窗口可以运行。我仍然无法使其他windows工作,我认为他没有包括资源文件。无论如何,我已经用更新的pom.xml更新了我的帖子file@abdouamer请在实例化新窗口的位置添加代码片段。值得检查的是,这些
fxml
文件是否存在于您的
jar
文件中(通过
jfx:jar
生成)是的,当我打开jar文件时,我看到了我放置fxml文件的fxml文件夹。@abdouamer我认为这个讨论正逐渐成为另一个SO问题的好话题。我的项目结构看起来像,而且我可以通过简单的getClass().getResource(“/fxml/nameOfMyResource”)获得任何资源。是的,当然可以,我的问题是“/”,我使用的是fxml/而不是/fxml/,谢谢
public class MainApplication extends Application {
    private Stage primaryStage = null;

    @Override
    public void start(Stage primaryStage) throws Exception {

        this.primaryStage = primaryStage;
        buildMainWindow();

    }

    private void buildMainWindow() {
        FXMLLoader loader = new FXMLLoader();
        Parent parent = new AnchorPane();
        System.out.println(getClass().getResource(""));
        loader.setLocation(getClass().getResource("fxml/mainWindow.fxml"));
        loader.setRoot(parent);
        try {

            parent = (AnchorPane) loader.load();

        } catch (IOException e) {
            e.printStackTrace();
        }


        Scene sc = new Scene(parent);
        primaryStage.setScene(sc);

        primaryStage.centerOnScreen();
        primaryStage.show();
    }



    public void setPrimaryStage(Stage stage) {
        this.primaryStage = stage;

    }

    public Stage getPrimaryStage() {
        return primaryStage;
    }

    public static void main(String[] args) {
        launch(args);
    }

}
public class MainWindowController implements Initializable {

    // Tabbed pane
    @FXML
    private TabPane tbTabPaneHome;


    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

     private void createTab(String title, AnchorPane parent) {
        Tab tab = new Tab(title);
        for (Tab child : tbTabPaneHome.getTabs()) {
            if (child.getText().equals(title)) {
                tbTabPaneHome.getSelectionModel().select(child);
                return;
            }
        }
        tab.setContent(parent);
        tbTabPaneHome.getTabs().addAll(tab);
        tbTabPaneHome.getSelectionModel().select(tab);
    }

    private Parent loadContent(URL resources) {
        try {
            FXMLLoader loader = new FXMLLoader();
            Parent parent = new AnchorPane();
            loader.setLocation(resources);
            parent = loader.load();
            return parent;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    private AnchorPane buildEntrepriseTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/entreprise/entreprise.fxml"));
        return parent;
    }

    private AnchorPane buildTransactionTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/transaction/transaction.fxml"));
        return parent;
    }

    private AnchorPane buildAccountTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/account/account.fxml"));
        return parent;
    }

    private AnchorPane buildTypeOfTransactionTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/TypeOfTransaction.fxml"));
        return parent;
    }


    private AnchorPane buildUserTab() {
        AnchorPane parent = (AnchorPane) loadContent(getClass()
                .getResource("../fxml/user/user.fxml"));
        return parent;
    }

    // Event Handling
    // Action events
    @FXML
    public void listDesEntrepriseClicked() {
        createTab("Entreprise", buildEntrepriseTab());
    }

    @FXML
    public void listTransactionClicked() {
        createTab("Transaction", buildTransactionTab());
    }

    @FXML
    public void listTypeOfTransactionClicked() {
        createTab("TypeOfTransaction", buildTypeOfTransactionTab());
    }

    @FXML
    public void listAccountClicked() {
        createTab("Compte", buildAccountTab());
    }

    @FXML
    public void listUserClicked() {
        createTab("Utilisateur", buildUserTab());
    }


}