Running a java profiler - java

I am trying to run a java based java profiler to find out what uses up resources on my java application on my dedicated machine. The profiler I am trying to use is called warmroast.
I get the following error from running.
java -jar warmroast.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/AttachNotSupportedException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
I think this error is caused by running the file with jre instead of jdk.
I have installed java-1.7.0-openjdk-1.7.0.55-2.4.7.1.el6_5.x86 as a yum package.
[root# ~]# java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
I think to fix this problem, I will need to run the jar file using jdk. Is there some kind of a jdk path to the jdk bin file? If so, what is it in centos? I've googled for a while and came up with dozens of wrong paths. I feel stupid because I think jre is a part of jdk and jdk is only using for compiling stuff and I don't think you can run files with jdk...
...
...

The class that could not be found is in tools.jar in your JDK. This library is usually not automatically on the class path, even if you use JDK instead of JRE.
According to the documentation, on Linux warmroast should be started as follows (replace PATH_TO_JDK with the path to your JDK):
java -Djava.library.path=PATH_TO_JDK/jre/bin -cp PATH_TO_JDK/lib/tools.jar:warmroast-1.0.0-SNAPSHOT.jar com.sk89q.warmroast.WarmRoast --thread "Server thread"
Here, tools.jar is manually added to the classpath.

Related

JNI Error with Java1.8.0_112 and Apache POI

I have just installed Java1.8.0_112, both jdk and jre 64bit on my Windows 7 machine.
I am attempting to run one of my programs via a .bat file and am getting the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/use
rmodel/Workbook
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
I have uninstalled and reinstalled the jre and I have restarted my machine. I have made sure I am pointing to all the libraries needed.
What really baffles me is that this error is showing about the POI workbook, but I have all the apache libraries I need and their appropriate dependencies so I'm not sure why this is an issue. Like I said, runs like a charm in Netbeans on the jdk, but completely implodes when I run it on my desktop via .bat
The program runs just fine in the Netbeans8 environment, which is using the jdk of 1.8.0_112 and the JDK8 binary.
My .bat file is as follows, I've added line breaks for readability:
C:\jre1.8.0_112\bin\java -cp
"T:\Netbeans Projects\MatchReport\build\classes;
S:\ADSJava\Jars\lib\poi-3.15.jar;
S:\ADSJava\Jars\lib\poi-ooxml-3.15.jar;
S:\ADSJava\Jars\lib\poi-ooxml-schemas-3.15.jar;
C:\Users\Jessica\Desktop\lib\xmlbeans-2.6.0.jar;
S:\ADSJava\Jars\lib\dom4j-1.6.1.jar;
S:\ADSJava\Jars\lib\commons-io-2.5.jar;
S:\ADSJava\Jars\lib\junit-4.12.jar;
S:\ADSJava\Jars\lib\commons-codes-1.10.jar;
S:\ADSJava\Jars\lib\commons-collections4-4.1.jar;
C:\Users\Jessica\Desktop\lib\DataServer.jar;
C:\Users\Jessica\Desktop\lib\ucanaccess-3.0.4.jar;
C:\Users\Jessica\Desktop\lib\jackcess-2.1.3.jar;
C:\Users\Jessica\Desktop\lib\xbeans.jar;
C:\Users\Jessica\Desktop\lib\commons-logging-1.0.4.jar;
C:\Users\Jessica\Desktop\lib\hsqldb.jar;
C:\Users\Jessica\Desktop\lib\commons-lang-2.4.jar"
ads.ADSMatchReport2
"Toyota Of Turnersville Control.txt" 2>&1> MatchReportResults.txt
Any help or guidance would be greatly appreciated, thank you!
Found the solution. The .bat file did not like me having libraries on mixed drives. Moving all the libraries to either my C: or the network S: drive solved the issue.
For whatever reason Netbeans was able to handle libraries in multiple locations but the .bat file does not.

Issue with running JAR in Windows, works fine in Ubuntu

I am stuck on the following error. I don't know what type of error it is. What should I do?
C:\Users\shehzad\Desktop\Software>java -jar Untitled.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: FrontEnd/MainWindow : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Scenario is: I developed software that works fine in Ubuntu 14.04 Lts. It's JAR also works in Ubuntu, but when I tried this JAR
in Windows 7 it shows the above error.
Ubuntu Java version: 1.8.0_101
Windows Java version: 1.7.0_79
class version 52.0 means it requires Java 8 to run. You should for security reasons update your Windows Java anyway, so its time to go to Java 8. If you need Java 7 for something you can keep it as a private installation, but make sure the "javapath" as configured by the registry points to Java 8.
You can also start in a command window or via explorer link the right Java.exe without installing it as public version like this:
"c:\Program Files\java\jdk_1.8.0_102\bin\javaw.exe" -jar app.jar
Your jar file is compiled using 8u101 (major.minor version 52.0) and your trying to run on 7u79. Hence you end up in Unsupported major.minor version 52.0.upgrade your java to 8u101.

Running a jar file on other Windows versions

I've written a code that is supposed to be exporting a set of windows registry keys. I've successfully written the code and was able to also send the results of executing the code as a jar file to my email. However, while testing the jar file ( I've included the piece of code in the build.xml from the java website that will allow me to run the jar file out of the dist folder) I was able to get the desired results on my machine because I wrote the code on a windows 8.1 machine. While testing it on another machine ( with Windows 8 and Windows 7 professional ) I was not able to execute the code and the error I was getting was as follows :
"Java Virtual Machine Launcher, A Java Exception has occurred."
I used to get that error message when I did not include the code in the build.xml page to allow the jar file to run out of the dist folder, but now I'm getting it when I'm executing the jar file on different machines other than my own
Running it from the command prompt this is what i got:
Exception in thread "main" java.lang.UnsupportedClassVersionError: smc_1/SMC_1
W1 : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
#Sara, that error is a JVM mismatch error. I think you're trying to run a jar compiled for Java 8 on a system with Java 7 (or older) installed. Your options are (a) update the JVM to Java 8 or (b) recompile your application with the target set to 1.7 or whatever JVM you need to target, provided that your app doesn't include any Java 8-specific code. Oracle has some information on updating Java to the latest version here: http://www.java.com/en/download/help/java_update.xml

Using jasperstarter to compile and run iReport "java.lang.UnsupportedClassVersionError"

Basically what I want to do is create a PDF from a iReport jrxml or jasper file.
The idea is to use this for reports over the net and the best solution I managed to find was to use a program like jasperstarter and then run the report with a connection to MSSQL database.
To get the connection going I had to download the latest net.sourceforge.jtds.jdbc.Driver.
The report works fine using iReport 5.1 but when I do follow the instructions from jasperstarter I get an "java.lang.UnsupportedClassVersionError" response.
jasperstarter command
jasperstarter pr -t generic -f pdf -i test_report.jasper -o test -u username -p password --db-driver net.sourceforge.jtds.jdbc.Driver --db-url jdbc:jtds:sqlserver://LOCAL-PC/Demo_DB
output
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/sourcefor
ge/jtds/jdbc/Driver : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at de.cenote.jasperstarter.Db.getConnection(Db.java:69)
at de.cenote.jasperstarter.Report.fill(Report.java:220)
at de.cenote.jasperstarter.App.processReport(App.java:222)
at de.cenote.jasperstarter.App.main(App.java:107)
Please advice.
Basically, you are trying to run code that was compiled on / for Java 7 on an older JVM.
That doesn't work.
Either:
run your application on a Java 7 JVM (or later1); i.e. upgrade your Java version,
find a build of the JDTS driver that is suitable for your execution platform, or
find the source for the JDTS driver and build it for your platform.
For more detailed information on this exception and its causes, read:
http://stackoverflow.com/questions/10382929.
1 - Note that even Java 7 is end-of-life now. If you are still running that version of Java you should upgrade.
Make sure you have same JRE and JDK.
If not sure un-install download the latest JDK and try again.
Note that the JDK does install the JRE automatically.

Issues using The Grinder load testing framework

I'm running into problems trying to use The Grinder. The tutorial on the site tells me to run "StartAgent.bat", which looks like this:
call "C:\Documents and Settings\dkeller\Desktop\Grinder\setGrinderEnv.bat"
java -cp %CLASSPATH% net.grinder.Grinder %GRINDERPROPERTIES%
When I open the Command Console and try to run it, I get this error:
"C:\Documents and Settings\dkeller\Desktop\Grinder>java -cp "C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar;"C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar;"C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar;"C:\Documents and Settings\dkeller\My Documents\grinder-3.4"\lib\grinder.jar; net.grinder.Grinder "C:\jython2.5.2\grinder.properties"
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/grinder/G
rinder (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)"
Yikes. Not totally sure what the problem is. Thinking it might be an issue with java versions, I made sure to update to the latest, but I'm not sure if it worked correctly. Here are some commands I ran, so you can see what I mean.
"java -version" returns
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
and "javac -version" returns
javac 1.6.0_26
Any help would be much appreciated, as I'm not sure what to try next.
Looks like your PATH environment variable is the problem. It's probably easiest just to edit that to have your JDK's bin directory in the PATH of the "user" part of the environment variables, so it comes before anything else which might contain java.exe.
Basically when you run java -version, you want it to show the same version number as javac -version.
Alternatively, you might consider uninstalling Java 1.4.2 unless you're still using it for something else...

Categories

Resources