Solved

java spring ClassPathResource

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 137
maven disable workspace resolution 1 79
jmeter usage 4 68
IBM TS2900 (3572) Tape Autoloader Java? 12 110
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

710 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