• Post Reply Bookmark Topic Watch Topic
  • New Topic

Protecting a class (with a Custom Classloader)  RSS feed

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a web application which uses several Utility classes
for business tasks. I'm going to distribute this web application
but I don't want to distribute the byte codes of the Utility classes.

So I've crypted the class and built a custom classloaders
which decrypts the bytes and load the class. So far so good.

Now the matter is: all in the code I have hardcoded the Utility Classes,
while on the other hand I simply have an Object in return from

class.newInstance();

How can have my classes loaded with a custom classloader without having to rewrite all the code ? (for example using reflection)

I thought to write a common superclass with a factory method which returns instances of the Utility classes.

public class Utility extends Master

{
void secretMethod() {
}

}

public class Master

{
getUtilityInstance() {
....
return new Utility();
}

void secretMethod() {
}

}

But then the "Master" class too must be loaded with the same classloader or the Utility class of the web application won't see it. But if the "Master"
class is not loaded from the standard web classloader how can I compile the code, when "Master" is used ? It's like the dog who bites its tail!

How can I solve the problem ?
Thanks a lot
Francesco
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Francesco,

I think you can cast the object you get from class.newInstance() to some interface:



Interestingly the casting works only with an interface.

Hops this answers your question!
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the point? Without DRM your class files can be obtained anyway. You yourself included the class loader required to decode them...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!