java.io.FileNotFoundException的原因:类路径资源[services.xml]无法打开,因为它不存在
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过
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
选择资源文件所在的项目。右键 - 构建路径 - 配置构建路径 - 源 - 添加文件夹 - 添加资源文件所在的文件夹。这会将文件夹添加到您的类路径中。
如果上述项目/jar 是另一个 WAR/EAR 的一部分,则选择该 WAR 和/或 EAR - 属性 - j2ee 模块依赖项,然后选择上述项目以添加到构建路径。
重新启动服务器。
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.
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.
确定是 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.