title: Problem with accessing xml in Spring boot resource folder
body: <p>Hi everyone I have a question. I am running a Spring Boot application, where I have DataInitializer that implements the CommandLineRunner and Override run method, to simulate starter of the app. The  DataInitializer is annotated as @Component. The project uses Maven and I added three dependencies for jaxb: </p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>The problem is that in this DataInitializer run method, I am initialising and object called UserDto: </p>
  
  <pre><code>@XmlRootElement(name = "user")
  @XmlAccessorType(value = XmlAccessType.FIELD)
  public class UserDto {
  
      @XmlElement(name = "first_name")
      private String firstName;
  
      @XmlElement(name = "last_name")
      private String lastName;
  
      @XmlElement(name = "city")
      private String city;
  
      public UserDto() {
      }
  
      public UserDto(String firstName, String lastName, String city) {
          this.firstName = firstName;
          this.lastName = lastName;
          this.city = city;
      }
  </code></pre>
  
  <p>.......getters and setters</p>
  
  <p>It is using the jaxb annotations to be used as mapper. When I initialise this OBJECT and create an instance, I am trying to write the marshalled data into the resource folder, where there is already created xml. Here is the code:</p>
  
  <pre><code>@Component
  public class DataInitializer implements CommandLineRunner {
  
      private final UserService userService;
  
  
      @Autowired
      public DataInitializer(UserService userService) {
          this.userService = userService;
  
      }
      private final String USERS_FILE_PATH = "src/main/resources/xmls/users.xml";
  
      @Override
      public void run(String... args) throws Exception {
  
          UserDto user = new UserDto("k", "d", "e");
  
  
          JAXBContext context = JAXBContext.newInstance(UserDto.class);
  
  
          Marshaller marshaller = context.createMarshaller();
          marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
  
          marshaller.marshal(user, new File("src/main/resources"));
  
  
      }
  }
  </code></pre>
  
  <p>I am using IntliJ Ultimate Edition, so when I go to the users.xml file in the resource folder and click copy path - > I'm choosing <strong>path from content root</strong>. The problem is when I run the application and this run method is called by the JVM, I'm receiving error and the application stops. Error: </p>
  
  <pre><code>java.lang.IllegalStateException: Failed to execute CommandLineRunner
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:787) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
      at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
      at com.softuni.xmlmapping.XmlMappingApplication.main(XmlMappingApplication.java:12) ~[classes/:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
      at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
      at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.2.5.RELEASE.jar:2.2.5.RELEASE]
  Caused by: javax.xml.bind.JAXBException: null
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:123) ~[jaxb-api-2.3.0.jar:2.3.0]
      at com.softuni.xmlmapping.init.DataInitializer.run(DataInitializer.java:51) ~[classes/:na]
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
      ... 10 common frames omitted
  Caused by: java.io.FileNotFoundException: src/main/resources (Is a directory)
      at java.base/java.io.FileOutputStream.open0(Native Method) ~[na:na]
      at java.base/java.io.FileOutputStream.open(FileOutputStream.java:292) ~[na:na]
      at java.base/java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:235) ~[na:na]
      at java.base/java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:185) ~[na:na]
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116) ~[jaxb-api-2.3.0.jar:2.3.0]
      ... 12 common frames omitted
  </code></pre>
  
  <p>When is use the absolute path, everything works. I now when the application is compiled the folders doesn't work like when you write code. The main reason for this problem is that on a windows machine, again with InteliJ Ultimate Edition, everything works with <strong>path from content root</strong>. For me I can use only the absolute, or choose file name and create it outside from the src folder. I am on MacOS machine. Is there some settings to the intelij or anything, because it is strange how on windows works but for me not. The windows machine is not mine so I don't know the settings and at the moment I don't have contact with the person. We are from a Spring Data course and see him only on the lectures. When I print the file.exists(), it tells me that the file exist -> true.</p>
  
  <p>Edit: I tried with src/main/resources/xmls/users.xml, xmls/users.xml, resources/xmls/users.xml and etc. only the absolute path manages to access this files.</p>