开发者

Netbeans Including XML and Properties when building Spring projects with Maven

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

Everything seemed to set up smoothly, and I began running through the Spring User Guide. However, I'm getting a file not found exception when trying to load my context.xml file.

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

I'm using the following line of code in App.java to try and load the context.xml file:

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

But when I run the application, it results in:

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: c开发者_如何学运维lass path resource [context.xml] cannot be opened because it does not exist

Looking at the NetBeans output, it also looks like it's not picking up 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, meaning the .xml and .properties are missing as well. I've tried moving these config files to the com.myproject package as well as just putting them at the root of the project which don't yield any different results.

So I'm making the assumption that my maven project isn't set up entirely correctly, or maybe a setting isn't correct within NetBeans.


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


Put the package in "Other Sources"

I have the same problem with a .property file to manage the Internationalization. I create it in com.company.app.view.resources at the Source Packages directory.

When I build the project and then look at my war file (target).. I don't found the .property file in /WEB-INF/classes/com/company/app/view/resources

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜