Search code examples
springweb-applicationsmavenwebsphererad

Causes for java.io.FileNotFoundException: class path resource [services.xml] cannot be opened because it does not exist


I have a web-application on RAD 7.5. I am building the application using Maven and deploying on WebSphere 6.1.

A part of my web.xml is:

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:services.xml</param-value>
</context-param>

This is the only place where I am referencing services.xml.

My services.xml is in folder

FruitApplication/src/main/resources/services.xml

After building with maven, services.xml is in the following path in the target folder

target/FruitApplication-1.0.0/WEB-INF/classes/services.xml

On deployment, I continuously get below mentioned error. However, on building the application two three times, it disappears on its own and then reappears again haphazardly.

What is the actual cause of this error ? How to solve this error ?

The top of my services.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

Is something needs to be changed here ???

Below is the complete pom.xml I am using for "maven-install":

<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>FruitApplication</groupId>
  <artifactId>FruitApplication</artifactId>
  <packaging>war</packaging>
  <version>1.0.0</version>

 <build> 
  <plugins>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.1</version>
        <configuration>
        <archive>
              <manifestFile>
            src/main/webapp/META-INF/MANIFEST.MF
          </manifestFile>
        </archive>
        </configuration>
    </plugin>
  </plugins>
 </build> 

 <dependencies>
        ... dependencies here ...
 </dependencies>

</project>

I have already tried all the below three options:

<param-value>classpath:services.xml</param-value>
<param-value>classpath:/services.xml</param-value>
<param-value>WEB-INF/classes/services.xml</param-value>

How I am deploying:

I am removing the application from the server by right clicking on server and "add or remove applications"

I am doing a run-as "maven-clean" and then run-as "maven-install" on the application and again adding the application by right clicking on the server and "add or remove applications"


Solution

  • Did you try classpath:/services.xml? The leading slash means to pull the resource from the root of the classpath. Without it, the file is expected to be in the package of whatever class is loading it (which I admit I don't know what that would be in this case).

    See http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#getResourceAsStream%28java.lang.String%29