Netbeans Including XML and Properties when Creating Spring Projects with Maven

I am new to Maven and Spring. I am using Netbeans 7 as my IDE and setting up a Spring 3 project using Maven.

Everything seemed to be set up smoothly, and I started working with the Spring user guide. However, when I try to load my context.xml file, I get an exception not found by the file.

I have an App class located in com.myproject and the context.xml file is in com.myproject.conf

I use the following line of code in App.java to try to load the context.xml file:

ApplicationContext context = new ClassPathXmlApplicationContext("context.xml"); 

But when I launch the application, this leads to:

 Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [context.xml]; nested exception is java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist 

Looking at NetBeans output, it also looks like it doesn’t collect the log4j.properties file, which is also located in com.myproject.conf

I looked at the jar that the build process created and the entire com.myproject.conf package is missing, which also means that .xml and .properties are also missing. I tried to move these configuration files to the com.myproject package, and also just put them in the root of the project, which do not bring any other results.

So, I proceed from the assumption that my maven project is not configured completely correctly, or maybe NetBeans may have a wrong configuration.

+4
source share
2 answers

It seems you need to learn about resources in Maven projects (such as XML, bitmaps, etc.). They are stored in separate directories. See here .

+2
source

Put the package in "Other Sources"

I have the same problem with a .property file for managing Internationalization. I create it in com.company.app.view.resources in the source package directory.

When I build the project, and then look at my war file (target). I did not find the .property file in / WEB-INF / classes / COM / company / application / view / resources

Then I put the package in the Other Sources directory and it works for me.

+2
source

All Articles