java.io.FileNotFoundException的原因:类路径资源[services.xml]无法打开,因为它不存在

发布于 2024-12-13 04:50:07 字数 2825 浏览 0 评论 0原文

我有一个 RAD 7.5 上的网络应用程序。我正在使用 Maven 构建应用程序并部署在 WebSphere 6.1 上。

我的 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">

这里需要更改吗???

下面是我用于“maven-install”的完整 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”,然后通过右键单击服务器并“添加或删除应用程序”再次添加应用

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅忆流年 2024-12-20 04:50:07

您是否尝试过classpath:/services.xml?前导斜杠表示从类路径的根部提取资源。如果没有它,该文件预计将位于加载它的任何类的包中(我承认我不知道在这种情况下会是什么)。

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

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

戈亓 2024-12-20 04:50:07
  1. 选择资源文件所在的项目。右键 - 构建路径 - 配置构建路径 - 源 - 添加文件夹 - 添加资源文件所在的文件夹。这会将文件夹添加到您的类路径中。

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

  1. Select project where the reource files exist.Right click - Build path - configure build path - sources -Add folder - add the folder where you resource file exist.This would add the folder to you class path.

  2. If the above project/jar is part of another WAR/EAR then select that WAR and/or EAR - properties - j2ee module dependecies and select the above project to get added to build path.
    Restart the server.

月亮坠入山谷 2024-12-20 04:50:07

确定是 Websphere/RAD 还是应用程序问题?

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

如果 Tomcat 一切正常,则说明 Websphere/RAD 存在一些特定情况:
3.检查你的websphere环境,我记得websphere中有一些选项可以设置/覆盖/前缀类路径。

Figure out if its Websphere/RAD or a application issue?

First build the war file and drop it in a Tomcat container and check if you still see the error.
1. If you see then copy the services.xml to WEB-INF and WEB-INF/classes directory and see if it works.
2. Also check your CLASSPATH system environment variable, system CLASSPATH can override your application classpath.

If everything is fine with Tomcat, there is something specific to Websphere/RAD:
3. Check you websphere environment, I recall there is some option in websphere where you can set/override/prefix the classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文