Solved

java spring ClassPathResource

Posted on 2013-12-04
1
1,253 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
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network + 7 80
reasons why a "inside Menu" would not appear for a web server 6 56
@SBGen Method 3 38
VB Script to add site to Java Exception List 4 53
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

867 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now