JavaFx scenebuilder and Maven Integration

这一生的挚爱 提交于 2019-12-22 13:52:27

问题


I have created a JavaFx8 Maven project in eclipse. I have put my fxml files in /src/main/resources/fxml/. I am able to the load the fxml from the java files using FxmlLoader. But, I'm not able to pick the controller class from Fxml file using Scenebuilder.

What should I do to be able to see the controller class automatically in the Scenebuilder tool ?

I have found a similar question, but the answer wasnt clear. I wasnt able to login to the jira case.

Tell JavaFX Scene Builder where to look for controller classes


回答1:


I have put the fxml file in the same folder /src/main/java initially. Then, I mapped all the elements/controller using scenebuilder.

Once mapping is done, I have moved the fxml to /src/main/resources folder. This works.




回答2:


Automated solution for same thing: Locate your controller and fxml files as same as standard java-fx projects. I mean put your fxml and controller files at the same place same as non-maven projects. Then add the following maven configuration into your project.

    <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>copy-fxml-resources</id>
                    <!-- here the phase you need -->
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes/</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/java/</directory>
                                <filtering>false</filtering>
                                <includes>
                                    <include>**/*.fxml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>



回答3:


You Must Put FXML beside its Controller in the same Package And Scene Builder will see the Controller




回答4:


I know this is an old question but I have put in a pull request on the Gluon release of Scenebuilder that modifies the controller search path, here. There is also a corresponding issue raised here.

If the pull request gets votes it may get merged sooner. If someone could also build and test it on Mac and Windows platforms that would be of great assistance too.



来源:https://stackoverflow.com/questions/29446826/javafx-scenebuilder-and-maven-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!