Solved

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

Posted on 2008-10-21
6
553 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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
Java exception bubble up 2 24
Unhandled exception type Exception 18 52
Facing this issue for maven proxy setting 2 27
jmss example java 2 33
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

733 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