1

I am creating a RESTful web service using Netbeans 8.1 and Glassfish 4.1. I have used Maven web application to create a server application.

I am using a client that sends an XML request and gets back a XML response from the server. I have a FoodItemData.xml file in my server project that I read from everytime a request comes in from the client.

I have stored the FoodItemData.xml file in the

project_name -> src -> resources -> FoodItemData.xml

of my project.

Whenever I run my server application, Glassfish throws the following error:

Severe: java.io.FileNotFoundException: E:\GlassFish\glassfish-4.1.1\glassfish\domains\domain1\config\src\resources\FoodItemData.xml (The system cannot find the path specified)

If I create the file at path src/resources/FoodItemData.xml in the 'config' directory of Glassfish, the error goes away. My Glassfish 'config' directory by default does not have the src/resources/FoodItemData.xml file.

My question is, is there any way I can make the server application automatically create it? Because I am going to run this server application on a different system, so I cannot always manually create the folder in the Glassfish directory.

Quick help would be appreciated. Thank you!

zx485
  • 28,498
  • 28
  • 50
  • 59

1 Answers1

0

Generally, you shouldn't be putting resource data inside your domain config directory.

As for your question, you have some options but that is going to depend on what exactly you are doing with this xml. You can add this directory+file to your WEB-INF directory. Here is a good explanation of how that would work.

You can also create an adapter class in Java (this will be used by whatever service or function needs to access the file and you can make sure only this class is accessing the file) that will create the directory+file if it's missing in your domain1 root directory. A simple way to have it done on startup is in a static block (the directory can be created when the class is loaded into memory).

Lastly, if you are using a deploy script that runs the asadmin commands you could have the same script check to make sure this directory exists.

Community
  • 1
  • 1
Raffaele
  • 51
  • 4