You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by thomas2004 <th...@yahoo.de> on 2009/10/28 15:03:27 UTC
resouce files not in the built jar
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: resouce files not in the built jar
Posted by Brian Fox <br...@infinity.nu>.
ah! no, don't do that. Resources belong in /src/main/resources and are
automatically pulled into the jar. Manually adding the java folder
just undoes some of the maven conventions.
On Wed, Oct 28, 2009 at 10:22 AM, KOUKI Fakhreddine
<ko...@gmail.com> wrote:
> Hi ,
>
> Put this on your Pom :
>
> <build> ...
>
> <resources>
>
> <resource>
>
> <directory>src/main/java</directory>
>
> <excludes>
>
> <exclude>**/*.java</exclude>
>
> </excludes>
>
> </resource>
>
> </resources>
> </build>
>
>
> On 10/28/09, thomas2004 <th...@yahoo.de> wrote:
>>
>>
>> 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: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: resouce files not in the built jar
Posted by KOUKI Fakhreddine <ko...@gmail.com>.
Hi ,
Put this on your Pom :
<build> ...
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
On 10/28/09, thomas2004 <th...@yahoo.de> wrote:
>
>
> 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: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: AW: resouce files not in the built jar
Posted by thomas2004 <th...@yahoo.de>.
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:stephen.alan.connolly@gmail.com]
> 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 <th...@yahoo.de>
>
>>
>> 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: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
>
--
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
AW: resouce files not in the built jar
Posted by "Lewis, Eric" <Er...@ipi.ch>.
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:stephen.alan.connolly@gmail.com]
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 <th...@yahoo.de>
>
> 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: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: resouce files not in the built jar
Posted by Stephen Connolly <st...@gmail.com>.
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 <th...@yahoo.de>
>
> 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: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>