I am working in a "biggish" Maven/Java project and cannot make sense of an error I am getting when running the app (it compiles OK). The error code I get is:
java.lang.NoClassDefFoundError: Could not initialize class com.sun.management.OperatingSystem
at com.sun.management.OSMBeanFactory.getOperatingSystemMXBean(OSMBeanFactory.java:30)
at sun.management.ManagementFactory.getOperatingSystemMXBean(ManagementFactory.java:100)
at sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:308)
at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504)
at com.sun.xml.internal.ws.server.JMXAgent.<init>(JMXAgent.java:49)
at com.sun.xml.internal.ws.server.JMXAgent.getDefault(JMXAgent.java:77)
at com.sun.xml.internal.ws.server.WSEndpointImpl.<clinit>(WSEndpointImpl.java:84)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
From the look of it, it seems the VM is not finding the "com.sun.management.OperatingSystem" class, but after googling around I cannot find out where is that class supposed to be located.
Any hints?
EDIT: Running with JRE JDK 1.6.0_18 (JAVA_HOME=C:\Program Files\Java\jdk1.6.0_18)
It might not be what's causing your problem, but errors like the one you are seeing can sometimes occur when the JDK is stored under "Program Files". Java doesn't like spaces in the filesystem path.
com.sun.management is an undocumented java package. The class OperatingSystem is the implementation for the OperatingSystemMXBean. If you download the Javasource code you will be able to see the class there.
As far as the location of this file, it should be in your standard JRE package. Make sure your application is pointing to the proper JRE. In Java 5/6, the class can be found in the rt.jar file.
If you want to confirm the file is there, Open the jar in program like JD-Gui and have a look around the Jar to confirm.
Looking at the javadocs for Java 6 and 7, it appears that OSMBeanFactory (which is in your stack trace) was added in 7.
Monitoring and Management Interface for the Java™ Platform (6)
Monitoring and Management Interface for the Java™ Platform DRAFT ea-b120 (7)
Related
I am trying to deploy an opencv java application with opencv 2.49, I have build the libopencv_java249.so and opencv-249.jar in the Ubuntu server and these are available in the class path when the application starts.
But it's throwing a exception saying libopencv_java245 not found, so initially I was under a impression that it's referring to a wrong opencv version. so to verify this I have removed the libopencv_java249.so from class path and then it was complaining that libopencv_java249 not available.
As an additional testing I also renamed libopencv_java249.so to libopencv_java245.so then it was saying again that opencv_java249 not found.
With this I guess we can confirm that it looks for the right version of opencv (that is libopencv_java249) but in addition to that it aslo requires libopencv_java245 also. Is my assumption is correct, it would be really helpful if someone can guide me.
I'm working with some java code wich loads an unmanaged dll, just as the following:
public void Foo(){
System.loadLibrary("absolute_path_to_my_dll.dll")
}
It works fine from eclipse or console.
Next step: I'm using IKVM tools to get a managed dll from my java app (ikvmc.exe). Everything works fine and my dll is built perfectly. In fact, I've imported that library in a Test Solution (and I've add all IKVM refereces needed -IKVM.Core.JDK, IKVM.Runtime.JNI, etc-).
Well, here is the problem: when I run C# code the java call to System.loadLibrary(...) fails and I get an "UnsatisfiedLinkError: Can't load absolute_path_to_my_dll.dll". Absolute path is ok and dll is there.
Any help? Thanks in advance.
Edit 1
I'll try to explain more in detail:
Java step
public void Foo(){
System.loadLibrary("absolute_path_to_my_dll.dll")
}
If path is not correct this call gives the "UnsatisfiedLinkError" mentioned above. This is not the case, everything works well. The dll file is a 32 bit one, so I compiled this java project with jre7 x86 (in 64 bit mode loadLibrary call falis, obviously, saying we can't load 32 bit dll in 64 bit AMD machine).
Ikvm step
Now I compile java code in a managed dll wich can be imported in a .net project. First of all I export my java project to a jar file, "myJar.jar". Then i apply ikvmc.exe to generate a managed dll, let's say "myNewDll.dll".
ikvm.exe -target:library -out:"myNewDll.dll" "myJar.jar"
This step works nicely and i get a new dll I can import in my VS project.
C# step
Now I create a new VS tester solution. I add "myNewDll.dll" as reference so I can use it in my C# code. Also, I add IKVM.Core.JDK reference (if not, project can't compile) and configure project in 32 bit mode. Problems start here:
Running this setup gives "IKVM.Runtime.JNI error". I've added that reference.
Running again gives "can't find ikvm-native". As I can't add ikvm-native-win32-x86.dll or ikvm-native-win32-x64.dll as reference I put both of them in output path (bin/Debug).
Next try it gives the "UnsatisfiedLinkError: Can't load xxx.dll".
How can it be possible if that dll is loaded flawlessly in java step?
Annother try
Just before start crying I tried annother way: I created a java main program that only called Foo(). Then I generated an executable file with ikvmc.exe tool and called it in windows console. It gave me the same error, UnsatisfiedLinkError so maybe it's ikvmc.exe problem but I can't understand why.
Any idea?
Edit 2
Good news. It seems I've solved the problem. First of all, I had to add -platform:x86 to ikvmc.exe call (step 2). The dll generated was succesfully imported in my C# project and it works fine if we run in execution mode (NOT debugging). If I try to debug in VS it gives me System.Runtime.InteropServices.SEHException.
Is there any kind of bug related to debugging native code (dll loaded in java code) under native code (that java code loaded in C# using ikvm)?
Is your dll a 32 bit and you run it on a 64 bit platform?
If yes then the problem is that IKVM is platform independent. This means on a 64 bit system it runs 64 bit process.
To solve this you need a 64 bit version of your dll or mark ikvm.exe as 32 bit process.
Adding an option of reference to IKVM.OpenJDK.Core.dll at ikvm's /bin directory will resolve the error.
Maybe the .jar file needs some native DLLs, which was same as Native library location parameter of JAR in Eclipse. If so, find the native DLLs and copy them to de /bin directory of IKVM, and make ikvmc to load them automatically.
That's all what I've found out. Try and see if it would bring some ideas.
I know it's probably fairly simple, but I'm having some issues grasping all the different packages I need just to install GDAL and read georeferenced rasters.
So I have already had OSGEO4W installed so that there exists a folderpath as follows: C:\OsGeo4W\lib\gdal.jar as well as C:\OsGeo4W\apps\swigwin\swig.exe
I also have the version from http://vbkto.dyndns.org/sdk/ so that I have a folderpath as follows: C:\ProjectsJava\gdal\bin\gdal\java\ with a gdal.jar and a bunch of dll's. This is what is originally linked in my project's libraries.
After googling the problem, I've also added a -Djava.library.path to point to the above gdal folderpath in the project's VM options (not entirely sure what I did but didn't make a difference anyways).
Also from random googled answers I've added environment variables to windows point to this and that related to GDAL or SWIG that did nothing (so removed them for now). So I only have a PATH that points to the gdal/bin folder and a GDAL_DATA that points to the gdal/bin/gdal-data folder. If it makes any difference I have installed successfully GDAL bindings for Python and there are some of it's environment variables left over in PATH and GDAL_DATA as well to similar but different folders.
Basically the code fails to even run a gdal.Open(in_path), giving the following error which hasn't changed no matter what I did differently:
Native library load failed.
java.lang.UnsatisfiedLinkError: C:\ProjectsJava\gdal\bin\gdal\jave\gdaljni.dll: Can't find dependent libraries
java.lang.UnsatisfiedLinkError: org.gdal.gdal.gdalJNI.Open__SWIG_1(Ljava/lang/String;)J'
at org.gdal.gdal.gdalJNI.Open__SWIG_1(Native Method)
at org.gdal.gdal.gdal.Open(gdal.java:563)
at ...
Now I know I probably screwed up getting GDAL right, but to be honest the labyrinthical instructions lost me well early on. All the odd packages to adapt C++ code to Java and instructions meant for Unix/Linux have got me all mixed up now.
SOLVED
Not sure why, but reinstalling Microsoft 2010 C++ Redistributable Package x86 helped. It was already installed, did a fix installation, and that seemed to do the trick. Hope that helps anyone else with a similar issue.
I am working with development of an application which, among other pieces of code, contains a number of servlets. The development environment I use is Eclipse (3.2.1, which is rather old) in which I run a Tomcat server (5.5.23, rather old as well) using the Eclipse Tomcat Wrapper plug-in for the task. All this runs on a RedHat 5.2 Linux system.
The Java runtime I use is JDK 1.6.0(21), which I upgraded to (from a previous JDK 1.5 version) quite recently and as far as I can recall, the software combination above (together with the application I'm working with) did actually work: I could start the Tomcat server, it got up without errors or complaints and the application's servlets were available on port 8080.
However, something has changed somewhere (could be in the application jarfiles themselves, I'm suspicious of essentially everything on the host to be the root cause of this). Now, when I try to start up the Tomcat server, I get the error sun.misc.InvalidJarIndexException in the console output. This happens for the following classes and methods:
org.apache.commons.modeler.Registry registerComponent (happens 3 times)
org.apache.catalina.core.StandardServer initialize (happens once)
org.apache.catalina.connector.Connector start (happens twice)
I did find this stack overflow question regarding how to find the JAR of a Java Class useful and I did run find /usr -name \*name-of-suspected-jar\*.jar a few times to track down a number of suggested offending JARS. I also tried to check the runtime configuration of the Tomcat server in Eclipse, but could really not match the JAR files on the system with the CLASSPATH of neither the Tomcat runtime setup (or with the CLASSPATH used in the environment when starting Eclipse). That effort probably requires some more rigor on my part but before doing that (and that is why I right now don't post all the gory details regarding CLASSPATHs here), I did a read up on exactly what InvalidJarIndexException really is about.
So, JAR files may contain an optional INDEX.LIST file which contains information about what classes (and methods?) to find in the JAR file. The idea is to short-circuit the search throughout all JARS in the CLASSPATH which is useful in a number of circumstances. Problem is when the INDEX.LIST file happens to be corrupt (or, is believed to be corrupt), that causes the loading of the class to be completely given up (the class loader does not fall back to searching all JARs in the CLASSPATH) and the error InvalidJarIndexException to be thrown. To make things more messy, the order in which JARs are searched might affect how the class loader treats the INDEX.LIST file: the INDEX.LIST file of one JAR might refer to other JARS and if those referred to JARS are not in sync with the first JAR's INDEX.LIST file, the class loader fails with this InvalidJarIndexException error.
So (according to this StackOverflow question), it seems like this error can be thrown not only because a JAR file has a corrupt INDEX.LIST, it seems it can even be thrown on a JAR even if the JAR has a valid INDEX.LIST or legitimately is lacking a INDEX.LIST simply because a previously searched JAR has confused the class loader. (To put in another way, as things are, this exception might be thrown even for "innocent" non-corrupted JAR files due to offenders elsewhere on the system).
So, after writing a mere novel, here comes my main set of questions:
What is the best way to track down the precise .jar file for which each InvalidJarIndexException is thrown?
What is the best way check if a randomly picked .jar file has an INDEX.LIST file and if so, if said file is valid (that is, non-corrupt)? What tools exist for this task?
Is there an efficient way to automatically deduce the search order of .jar files? I can try to follow the CLASSPATH manually but to be honest, that is error prone and tedious.
Is there an efficient way to figure out what .jar file there is in a search order which might confuse the class loader to accuse innocent, non-corrupt .jar files later in the search to have incorrect INDEX.LIST files?
Disclaimer: I know I run old versions software (even if I have the latest updates of my Redhat 5.2 installed though) and I know a knee-jerk reaction for many people is to suggest that I don't put any effort whatsoever in debugging this but instead upgrade to a more recent version of Tomcat, Eclipse and Linux (Java is recent though). The reason I would prefer not to is that after looking into things, I've found it rather messy to do an upgrade or to try to install a separate modern Tomcat or Eclipse next to the RHEL5.2 provided Tomcat/Eclipse I use today. Also, I consider this kind of troubleshooting an opportunity to learn some useful nitty gritty details about Java and it's associated tools and features. Figuring out how the class loading works and what causes it to throw this InvalidJarIndexException on my system would be very educating!
(But if this troubleshooting fails, I'll seriously consider to use a modern Linux, Eclipse and Tomcat... I promise)
Take the following steps to diagnose the problem:
Add an exception breakpoint in Eclipse (it's the J with an
exclamation mark icon), and set it to halt for caught and uncaught
exceptions, of type InvalidJarIndexException.
Start debugging your program.
Eclipse will halt at your exception breakpoint, when the InvalidJarIndexException is thrown. Even without the source for URLClassPath, you will still be able to inspect the variables on the stack leading to the exception, including the name of the class that URLClassPath is attempting to locate. Knowing the name of the class should significantly narrow the list of JAR's you need to examine.
Perhaps you've locally added a new class to a package and the contents of that package are described by the index file in a stale JAR on your classpath?
Try Tattletale which is a good reporting tool for jars. What I have done in this case was to eliminate INDEX.LIST from jars one by one until I did not get InvalidJarIndexException any more
I am working on a team project in Java. One requirement is that we dynamically populate a drop-down menu of all classes that implement a certain interface. New classes can be added after compile time. To accomplish this we are using reflection.
Problem: All of the drop-down menus are blank on my system. I cannot for the life of me figure out why they are not populating. All other 5 team members have it working on their system.
Things I tired that didn't work:
1) Installing most recent eclipse (galileo) because rest team was using it
2) Re-install most recent java release (jdk1.6.0-17 and jre6)
3) Check PATH and JAVA_HOME variables
Any thoughts as to what else I can try or if something I did should have solved it and didn't? It is driving me crazy.
Edit:
I should have been clearer that we are developing in a team. We are using SVN for version control and we are all running the exact same source code. I even tried checking out a fresh copy of the entire tree from SVN, but I had the same issue with reflection on my system while it worked for teammates.
The team created an executable jar and that ran on everyone's system fine except for mine. Everything worked for me except the reflection bit.
You need to debug your application. This means you have to systematically explore possible causes of the problem. Here are some things that come to mind:
Could your GUI be failing rather than reflection? What if you output with System.out.println() rather than your menu?
Is your reflection code throwing an exception, and are you ignoring it?
Is your reflection code actually being called? Toss a println() in there to be sure!
Is the test for the interface suffering from a typo or similar error that's causing it to fail? Try finding classes that implement Serializable instead!
Is your reflection test running in the main thread and trying to update your GUI? You need to use SwingUtilities.invokeAndWait to get an update to the Swing worker thread.
You're working with Eclipse; Eclipse has a fantastic debugger. Set a breakpoint near where your main action is and then single step through the code.
PATH and JAVA_HOME won't help. PATH only affects dynamically-linked libraries ("native code"). JAVA_HOME is a scripting variable that happens to be used by some Java-based utilities like Ant and Tomcat; it means nothing to the Java runtime itself.
You need to be investigating the classpath, which should be specified by the -classpath option to the java command, in the Build Path in your Eclipse project properties, or in the Class-Path attribute of the main section of a JAR file if you're launching java with the -jar option.
From within your code, you should be able to list the contents of your classpath by examining the system property, "java.class.path"
System.out.println(System.getProperty("java.class.path"));
Problem solution:
Classpath leading to source code must have no spaces in it.
I am running windows XP and, for whatever reason, if the classpath that leads to the jar file or source code that is using reflection has any spaces in it, then the reflection fails.
I took the jar file that works for the rest of my team and ran it from C:\ on my system and the reflection worked perfectly fine.
I do not know why this is so please comment if you know what is happening.
Might be a long shot, but look for differences in security settings for you and your team mates. Article describing more details http://www.ibm.com/developerworks/library/j-dyn0603/ heading "Security and reflection"