I do use m2eclipse to build my project and then use clean package to compile
it.
Now I move the "context.xml" to /src/main/resources and I can find it in
jar.
But as I start to run the program in Eclipse I got exception like:
[code]
...
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
...
[/code]
My class looks like:
[code]
...
public class App {
public static void main(String[] args) {
ApplicationContext context = new
ClassPathXmlApplicationContext("context.xml", TestBean.class);
TestBean testBean = (TestBean) context.getBean("test");
}
}
[/code]
And here is my POM.XML
[code]
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.weichen.app</groupId>
<artifactId>TestSimpleStandAloneSpringApp</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>TestSimpleStandAloneSpringApp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>2.5.4</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
[/code]
Lewis, Eric wrote:
>
> Also, if you're not yet using it, get m2eclipse and import your Maven
> project.
> src/main/resources will be treated as source folder automatically.
>
> Best regards,
> Eric
>
> -----Ursprüngliche Nachricht-----
> Von: Stephen Connolly [mailto:[email protected]]
> Gesendet: Mittwoch, 28. Oktober 2009 15:27
> An: Maven Users List
> Betreff: Re: resouce files not in the built jar
>
> because resources should be in src/main/resources/___ and not
> src/main/java/___
>
> eclipse is a fool... maven is a know-all
>
> -Stephen
>
> 2009/10/28 thomas2004 <[email protected]>
>
>>
>> Hi all,
>>
>> I use maven 2.0.9 and Eclipse to build my program. But I met a strange
>> thing: I put some resource files such as "context.xml" in the same
>> package
>> as my java files. But after I built the project/program with mvn clean
>> package, I can't find the "context.xml" inside the jar. That's the reason
>> why I got FileNotFoundException as I run the program.
>>
>> Someone knows why?
>> --
>> View this message in context:
>> http://www.nabble.com/resouce-files-not-in-the-built-jar-tp26095189p26095189.html
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://www.nabble.com/resouce-files-not-in-the-built-jar-tp26095189p26107811.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]