2011-11-01 294 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模塊依賴項並選擇上面的項目以添加到構建路徑。 重新啓動服務器。

相關問題