Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java spring ClassPathResource

Posted on 2013-12-04
1
Medium Priority
?
1,578 Views
Last Modified: 2013-12-21
Hi,
I am getting the following exception :

java.io.FileNotFoundException: class path resource [xsl/ExtremeSearchRQ.xsl] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/data/ytxdist/SCHEDULER/ExtremeSearch/libs/yatra_extremesearch.jar!/xsl/ExtremeSearchRQ.xsl

The following code throws this exception :
String xslSourceFile = "xsl/ExtremeSearchRQ.xsl";
		String xmlSource = "ExtremeSearchRQ.xml";
		Writer paramWriter = new StringWriter();
		
		Transformer transformer=null;
		ClassPathResource resource = new ClassPathResource(xslSourceFile);
		StreamSource streamSrcFile;
		
		streamSrcFile = new StreamSource(resource.getFile());

Open in new window


The exception is thrown by the resource.getFile() line.

I am running my project with the following line :
java -cp "libs/*:conf" com.yatra.extremesearch.app.ExtremeSearchApp

Here the libs folder contains the yatra_extremesearch.jar file
when i unzip the jar i also see the file xsl/ExtremeSearchRQ.xsl

Still its giving an exception saying fileNot Found

What could be reason for this.

Thanks
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 39695144
The actual detail in the error message is the more useful part
because it does not reside in the file system
Files that are inside a jar do NOT strictly "reside on the file system", eg. you can't, as an example, open up a text editor and navigate directly to your xsl file inside the JAR. Yes you can unzip it and get access to it, but unzipping it basically means that you ARE making a copy of it on the file system.

However, don't despair... Even though you can't directly resolve a "File" object for that resource, you can still access the data. Simply change line 9 of the above to this...
		streamSrcFile = new StreamSource(resource.getInputStream());

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question