java - How to Make a Classloader evaluate the classpath before initlializing static objects? -


I have an application that I am developing which uses both jar libraries and basic system libraries. The problem is the default classloader that is attempted to load the static class before being called the main. Since the classpath does not yet include the original libraries for the need for static classes, java.lang.NoClassDefFoundError is thrown in the first evaluation static context.

This is how my accessible library loading method looks like:

  Private static zero load_library () {{string osname = getOSName ( } {Try} if (osname == faucet) {new runtime exception ("the system you are running is not supported"); } URL U = NetBliss class.GetRSOSOS (OSNN); URL class loader urlClassLoader = (URL class loader) Classloader .getSystemClassLoader (); Class urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod ("addURL", new class [] {URL.class}); Method.setAccessible (true); Method.invoke (urlClassLoader, new object [] (U)); } Hold (IllegalAccessException pre) {Logger.getLogger (Main.class.getName ()). Log (level. SESEE, "failed to load native lbs", formerly); } Grip (invalid authorization prefix) {loggergatelogger (main.clash.gatename ()). Log (level. SESEE, "failed to load the original libs", formerly); } Hold (Innovation Targeting) pre) {LoggerGetlogger (main.clash.get_name ()). Log (level. SESEE, "failed to load the original libs", formerly); } Grip (Noschamppe Exception) {LoggerGetLugger (Main.ClashGet_name ()). Log (level .SEEEEE, "failed to load original libs", formerly); } Grip (Security Exception) {Logger. Taglgor (Main.clash.jetname ()). Log (level .SEEEEE, "failed to load the original libs", formerly); }}   

So, let me explain what's going on here. First of all getOSName () does the returning string representing an OS family that I'm running. If OS is unsupported, then it gives zero; I have a problem in that case, then I will go ahead and also post it:

  private constant string getOSName () {string OS = system .jetproperty ("os.name") .toLowerCase (Locale.US); If (os.indexOf ("win")> = 0) {return "windows"; } And if (os.indexOf ("Mac OS X")> = 0) {return "Macx"; } And if (os.indexOf ("nux")> = 0) {return "Linux"; } And if (os.indexOf ("solaris")> = 0) {return "solar" ";} and {return null;}}   

Directory names that use the method load_library () to define a relative url which I pass in a brilliant way to load libraries. My problem is that runtime execution can never be loaded by load_libraries () Does not reach, even if it is the first method in the main

a solution which is clear That is to load the original library with statically customized jars. If I am forbidden, I do not want to link the original libraries statically, because it defeats the purpose of Java's platform portability. It is speculated that another solution is a system executable that comes with the executable system determined by the executable system The Verden Jar can run, but still, there are many special properties for that solution, which are platform specific.

My question:

Do I have to remove ClassLoder to my Library loading method Before I run, can I make the static objects wrong before? Would it be a customized classmate? If this requires a custom class loader, will it simply pass the system property that resolves the problem of default classloader?

Thank you, I hope I wrote a detailed enough question! The reason for this is that "the main class loader has made the main class loader long to load a permanent class before long time."

Have tried "because the static member variables and / or a stable starter in your main class, when the classloader initializes your main square, then it should also start these fixed variables. For more information, see.

Solution - Only good solution - To eliminate static initialization, start your stable member variable inside your main () , or get started Use a frame as spring for.

In general, there are very few good uses for stable member variables. Most of them end up hacking to give access to resources from arbitrary points in the program. This not only makes the program difficult to test, but leads to unexpected starting series.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -