Solved

Need to access a xsl file inside a jar file...

Posted on 2008-10-21
6
537 Views
Last Modified: 2013-11-18
I have a jar file which has a java file and a xsl file. I have to execute a xsl transformation in java using the xsl file in the jar. I use ant to invoke the function in the java file.

How to access the xsl file in Java? Assuming both the xsl and the java file are in the same jar which executing??
0
Comment
Question by:emsenthil
  • 4
  • 2
6 Comments
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
  /**
    * Opens a resource file via Class info.
    * The file is assumed to be in the same directory as the .class file,
    * be it on disk or in a .jar container.
    * If the file is in another directory, the filename should be changed
    * into a relative pathname.
    *
    * @param  classinfo   a Class object.
    * @param  filename    the relative pathname from the .class file to the resource file.
    * @return             an open input stream.
    */
   public static InputStream getResourceFile(Class classInfo, String filename)
   {
            return(classInfo.getResourceAsStream(filename);
   }

// Usage:

   InputStream k = getResourceFile(this.getClass(), "files/xls/q.xls");

;JOOP!
0
 

Author Comment

by:emsenthil
Comment Utility
Hi,
Thanks for the help. But I am getting this exception when I run it.

Exception is : XML-22000: (Fatal Error) Error while parsing XSL file ({0}).

Ofcourse, the xsl file is not present in the same directory as the class file. The xsl file is present in the parent directory. How to give a relative path? That too to go back to the parent file? Will the relative path work in both Windows and Linux environments?

Thanks.
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
Comment Utility
Parent?

   "../file"

Works everywhere: another thing 'borrowed' from UNIX.

;JOOP!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
:))
0
 

Author Comment

by:emsenthil
Comment Utility
Thanks sciuriware... :)
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
My pleasure ...........................................
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

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

9 Experts available now in Live!

Get 1:1 Help Now