3

I have writing a Java application in IntelliJ 12 using Maven and Spring. I have the following folders:

src/main/java : for Java code

src/main/resources: for resources to be packaged into final built JAR

src/main/config: for external resources, i.e. the spring configuration file.

I have tried making the src/main/config a sources folder, however, upon running my application, it fails with a FileNotFoundException on the following line:

new ClassPathXmlApplicationContext("spring-config.xml");

spring-config.xml sits inside src/main/config.

Also, I have noticed this file does not get copied over to the target directory that intelliJ produces when 'Make' building the project.

For now I am resorting to using a FileBasedApplicationContext for testing, however it would be nice to be able to run the application from within intelliJ without having to edit the code.

Thanks

4

1 回答 1

5

在这里查看我的评论。资源目录/模式必须在您的pom.xml文件中明确定义,如下所示:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <directory>src/main/config</directory>
        </resource>
    </resources>
</build>
于 2013-02-08T14:59:27.793 回答