2011-11-01 293 views
1

我在RAD 7.5上有一个Web应用程序。我正在使用Maven构建应用程序并在WebSphere 6.1上进行部署。java.io.FileNotFoundException的原因:类路径资源[services.xml]无法打开,因为它不存在

我的web.xml的部分是:

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

这是我引用的services.xml的唯一地方。

我的services.xml是在文件夹

FruitApplication/src/main/resources/services.xml 

与Maven构建后,services.xml的是在目标文件夹

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

在部署下面的路径,我不断得到下面提到错误。但是,在构建应用程序两次时,它会自行消失,然后再次随意再次出现。

这个错误的真正原因是什么? 如何解决这个错误?

我的services.xml的顶部看起来像:

<?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"> 

是,这里需要改变的东西???

下面是我使用的“行家安装”完整的pom.xml:我已经尝试了所有的以下三个选项

<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> 

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

如何我部署:

我通过右键单击服务器并“添加或删除应用程序”从服务器删除应用程序

我正在执行“maven-clean”,然后在应用程序中运行为“maven-install”,并通过右键单击服务器并“添加或删除应用程序”再次添加应用程序。

+0

当您收到该错误时,您是否检查WAR文件以查看文件是否确实存在于您期望的位置? – dbreaux

+0

你如何部署?只要放下Maven在容器中产生的战争?你可以在你的问题中包含你的pom的build-> resources部分吗? – smp7d

+0

您是否在RAD,Websphere或两者中遇到错误?由于@ smp7d建议使用资源阶段并包含将services.xml复制到显式WEB-INF/classes和WEB-INF目录的路径。虽然WEB-INF不在classpath中,但可以尝试使用它。 – Rajendra

回答

0

弄清楚,如果它的Websphere/RAD或应用程序的问题?

首先构建war文件并将其放入Tomcat容器中,并检查是否仍然看到错误。 1.如果您看到,请将services.xml复制到WEB-INF和WEB-INF/classes目录,并查看它是否有效。 2.同时检查您的CLASSPATH系统环境变量,系统CLASSPATH可以覆盖您的应用程序类路径。

如果Tomcat的一切都很好,Websphere/RAD特有的东西: 3。检查你的websphere环境,我记得在websphere中有一些选项可以设置/覆盖/前缀类路径。

+0

谢谢..会尝试一下并发回更新! – Nik

1
  1. 选择项目中,reource文件exist.Right点击 - 建设路 - 配置构建路径 - 源 - 添加文件夹 - 添加在您的资源文件exist.This将文件夹添加到您的类路径的文件夹。

  2. 如果上述项目/ jar是另一个WAR/EAR的一部分,那么选择WAR和/或EAR - properties - j2ee模块依赖项并选择上面的项目以添加到构建路径。 重新启动服务器。

相关问题