Solved

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

Posted on 2008-10-21
6
541 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 43
github account with ecipse 1 42
Java Loop 6 49
java jdbc batch example 8 22
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

920 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