aspose file tools
The moose likes Java in General and the fly likes Loading Jar file dynamically from an InputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Loading Jar file dynamically from an InputStream" Watch "Loading Jar file dynamically from an InputStream" New topic
Author

Loading Jar file dynamically from an InputStream

nitin kumar
Greenhorn

Joined: Feb 11, 2004
Posts: 6
Hello,

I have this requirement of loading jar from an inputstream. My application is a jar file and I have encrypted it using encrytion algo. Now when my application starts, my main class will decrypt this file which returns an outputstream as decrypted stream. I want to use this stream without saving it to file. I can convert this stream to an InputStream which should be then loaded.
How can I achieve the above objective?

The reason I dont want to save it to a disk file is that, the once a jar file is available, this jar file can be decompiled and my main class code can be modified to bypass the security check/license check.

The code is already obfuscated using yGuard. Since my entry point (main class) is not obfuscated, it is possible to patch and by pass security check and enter the application. I want to avoid this and hence above solution.

Please help.

Nitin

Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

nitin kumar wrote:I want to use this stream without saving it to file.


Use it for what? Do you want to load the classes present in the jar file?

apigee, a better way to API!
nitin kumar
Greenhorn

Joined: Feb 11, 2004
Posts: 6
Thanks for reply.
I appologize for late reply on this one.

After posting this question, I have gone further in finding the solution to my problem.
To answer your question, I want to load a class from a jar file. However, as my application requires securing Jar file, I am encrypting the whole jar file and whenever my application needs any class from this encrypted jar, I decrypt the jar file and then extract the class.

I am doing this by creating my own application class loader. I was able to get the jar decrypted and load in JarInputStream. But I am again stuck in another problem. When I take out a JarEntry from the JarInputStream (I have used a code from net from (@author Simon Mieth)), i get the size of this JarEntry as -1. I checked other variables like CRC and compressedSize, both of them are -1.

I thought it must be problem of encryption. But when I tried with plane jar file, it again gave me the same problem, that the size of JarEntry is -1.

What do you think is the problem?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading Jar file dynamically from an InputStream
 
Similar Threads
jdk logger manager reinitialization does not work fine in Websphere
Secure Java source code
writing to Text file.
jdk logger manager reinitialization does not work fine in Websphere
problem in loading .dll file using web start?