Solved

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

Posted on 2008-10-21
6
550 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
ID: 22773823
  /**
    * 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
ID: 22776595
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
ID: 22777580
Parent?

   "../file"

Works everywhere: another thing 'borrowed' from UNIX.

;JOOP!
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Expert Comment

by:sciuriware
ID: 22784024
:))
0
 

Author Comment

by:emsenthil
ID: 22784576
Thanks sciuriware... :)
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 22784981
My pleasure ...........................................
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 34
What's wrong with this code? 4 26
CSV file parsing thru Java 13 34
Delphi Firemonkey: if the Sms contain special characters it won't send it 3 44
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

832 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