0

Given the following Java project structure:

ProjectFolder
 |- src
 |   |- main
 |   |   |- java
 |   |   |   |- foo
 |   |   |   |   |- view
 |   |   |   |   |   |- FooBar.xml
 |   |   |   |   |- FooBar.java
 |   |- test
 |   |  |- ...

Using a simple project structure without the /main/javaand test/java folders in FooBar.class I could access FooBar.xml easily with

final URL url = FooBar.class.getResource("view/FooBar.xml");

However with the file structure above this is not possible.

What does the trick in this case? Any simple solution for that?

Edit: I realized that this - of course - is not a problem with Java but with IntelliJ IDEA:

With this IML file it works

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

However, with this one it does not

<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="SpinChatNotifier" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.1" type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="false">
    <output url="file://$MODULE_DIR$/build/classes/main" />
    <output-test url="file://$MODULE_DIR$/build/classes/test" />
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
      <excludeFolder url="file://$MODULE_DIR$/build" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" scope="TEST" name="Gradle: org.testng:testng:6.9.10" level="project" />
    <orderEntry type="library" scope="TEST" name="Gradle: org.beanshell:bsh:2.0b4" level="project" />
    <orderEntry type="library" scope="TEST" name="Gradle: com.beust:jcommander:1.48" level="project" />
  </component>
</module>

Does anyone know what the problem could be?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Hannes
  • 5,002
  • 8
  • 31
  • 60
  • 1
    Did you try placing the XML file in `src/main/resources`? That is where your resource files go for the second IML structure – OneCricketeer Feb 18 '16 at 19:10
  • @cricket_007 No I did not; problem is that the JavaFX Scene Builder expects the FXML files in the same folder as the corresponding Java class. – Hannes Feb 18 '16 at 19:25
  • I see. I haven't used the JavaFX builder. Also, this actually *is* a Java problem, not an IntelliJ problem, as you seem to think. IntelliJ just happens to setup the classpath of your project with the `src/main/java` structure. – OneCricketeer Feb 18 '16 at 19:30
  • @cricket_007 Well, if I do not build my Java project from a Gradle template it works fine, even with IntelliJ :-( Is there a way to include the FXML files into the classpath? – Hannes Feb 18 '16 at 21:42
  • @cricket_007 The problem with an other location than the actual java src folder is, that Scene Builder won't recognize the corresponding controllers :-( – Hannes Feb 18 '16 at 23:15

0 Answers0