Solved

java spring ClassPathResource

Posted on 2013-12-04
1
1,207 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

14 Experts available now in Live!

Get 1:1 Help Now