Reputation: 124
I have jdk-10_linux-x64_bin.tar.gz.I have untared this file.
I want to modify the JDK folder content such that when I compile a java code using javac bin file, it should throw a ClassNotFoundException when the java code contains a reference to any other package(such as java.io, java.util,..etc) other than "java.lang.*". I just want to remove all packages except "java.lang" package.
Even when the java file tries to get packages at runtime(using classloader) the classes should not be available. So simply I want to delete other packages except "java.lang" package.
I tried to find the other packages inside JDK folder but I am confused. I cannot find any solution directly by searching google. I also do not know whether deleting other packages might cause some any dependency errors.
Have anyone tried modifying the JDK folder content?
Upvotes: 1
Views: 108
Reputation: 7620
Instead look at setting up SecurityManager with a custom policy, where you decide which classes (or even methods) you will allow to run.
Just create a SecurityManager
which you can set using System.setSecurityManager()
method within your runtime with your custom security policy.
This will allow you to capture exceptions thrown when violation of security policies happen, to return something useful to the user.
Have a look at this quick intro to security managers in Java.
Upvotes: 3
Reputation:
go to C:\Program Files\Java\jdk version\jre\lib, open rt.jar as zip, and delete the packages u want
Upvotes: 0