?
Solved

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

Posted on 2008-10-21
6
Medium Priority
?
576 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 2000 total points
ID: 22777580
Parent?

   "../file"

Works everywhere: another thing 'borrowed' from UNIX.

;JOOP!
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 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