3

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

Community
  • 1
  • 1
user691197
  • 927
  • 6
  • 20
  • 38

4 Answers4

3

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.

user691197
  • 927
  • 6
  • 20
  • 38
1

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>
fatihonurIRL
  • 51
  • 1
  • 9
0

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

BesaFX
  • 19
  • 1
  • 5
  • 3
    I know that, but in a maven project we'd like to separate the resources from the code files, so I need a solution for this. – user691197 Apr 09 '15 at 12:03
0

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.

D-Dᴙum
  • 7,689
  • 8
  • 58
  • 97
  • Hey, I know it's an old answer on an even older question. I saw the PR was merged. But, I still have the same problem... Is it working atm? – Psychokiller1888 Oct 30 '17 at 04:31
  • Which version of Scenebuilder are you using and are you executing on Windows? Also where are you placing the FXML and controller files? – D-Dᴙum Oct 31 '17 at 07:40
  • Thanks for the reply! I'm on version 8.4.0, Windows. I have tried different structures. The actual one is https://puu.sh/ybC8V.png as I saw you (or was it someone else) wrote about the structure needing to be the same between the resources pacakge and the main pacakge. I have tried to place the fxml directly in the resources folder too, doesn't work. Opening the fxml crashes scene builder 3 times on 5, or at least freezes it for a long time – Psychokiller1888 Oct 31 '17 at 16:35
  • Is it possible for you to raise an issue in the Bitbucket repo and attach the Controller file and FXML too? I can take a look. – D-Dᴙum Oct 31 '17 at 19:18
  • Done, thank you! https://bitbucket.org/gluon-oss/scenebuilder/issues/155/scene-builder-vs-maven – Psychokiller1888 Nov 01 '17 at 08:15
  • @myselfAndOthers Yes, it works... Just make sure you're running on Scene Builder version 8.4.1 at least – Psychokiller1888 Nov 04 '17 at 19:03