(java)Could not find the main class - jvm

My code is compiled on OSX and it works fine(compiler version 1.6). But when I copy it to a remote ubuntu. I can not run it.
When I run
java TPCC.class
I got exception like this.(By the way TPCC.class is in default package)
Exception in thread "main" java.lang.NoClassDefFoundError: TPCC/class
Caused by: java.lang.ClassNotFoundException: TPCC.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: TPCC.class. Program will exit.
And my java version on ubuntu:
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Client VM (build 17.0-b16, mixed mode, sharing)
It's also 1.6 and I think it fits the compiled binary. How can I fix this problem?

The problem is in the way you run the program. Compiled java called
ClassName.java
will be ClassName.class. You should run it like
"java ClassName"
. You shouldn't run it as
"java ClassName.class"
What happens here is this. When you run it as java ClassName.class, JVM try to look for ClassName called "class" in the package called "ClassName" that does not exist. So it will throw NoClassDefFoundError.

This is an invocation problem as the error shows: java should be used and not the filename of the class.
The error message tries to say you this by stating that "TPCC/class" is not found.
(sorry for first adding comment, used the wrong field)

Specify the classpath when invoking java:
java -cp <path-to-jar> TPCC

Related

How to link Z3 build, Compiled for Java, from Eclipse Plugin?

I have a perfectly working Z3 Build system for Java. I want to call it from an Eclipse plugin. I tried several approaches, but non of them are working for me. These approaches are:
Adding Z3 build as an external class folder
How to Use External Class Files in an Eclipse Project
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
libz3java in java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at
java.lang.Runtime.loadLibrary0(Runtime.java:870) at
java.lang.System.loadLibrary(System.java:1122) at
com.microsoft.z3.Native.(Native.java:14) at
com.microsoft.z3.Global.ToggleWarningMessages(Global.java:87) at
TestZ3.main(TestZ3.java:9)
Copied Z3 build to the Eclipse plugin, at the root. Then added com.microsoft.z3.jar under the Libraries (Right-mouth click on the project->Build Path->Configure Build Path->Libraries->Add Jars). The error is:
java.lang.UnsatisfiedLinkError: no libz3java in java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at
java.lang.Runtime.loadLibrary0(Runtime.java:870) at
java.lang.System.loadLibrary(System.java:1122) at
com.microsoft.z3.Native.(Native.java:14) at
com.microsoft.z3.Global.ToggleWarningMessages(Global.java:87) at
plugintest.handlers.SampleHandler.execute(SampleHandler.java:37) at
org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
at
org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at
org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
at
org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
at
org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at
org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at
org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
at
org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
at
org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at
org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:799)
at
org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:675)
at
org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:659)
at
org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:592)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362) at
org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113) at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at
org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at
org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at
org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694) at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at
org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at
org.eclipse.equinox.launcher.Main.run(Main.java:1515) at
org.eclipse.equinox.launcher.Main.main(Main.java:1488)
With or without the previous step, I added com.microsoft.z3.jar to Classpath, located at the Plugin.xml Runtime tab. In this case, the plugin is not finding the handler that is invoked after button press command.
!MESSAGE plugintest.handlers.SampleHandler cannot be found by
PluginTest_1.0.0.qualifier !STACK 0 java.lang.ClassNotFoundException:
plugintest.handlers.SampleHandler cannot be found by ....more
In fact, this approach worked for me a previous a installation (Dell, Intel, x64, Eclipse Mars (x64), Java 1.8 x64)!
Following the discussion in https://github.com/Z3Prover/z3/issues/1093, I configured Native Library Location of com.microsoft.z3.jar with the Z3 Build directory. Calling the Z3 Build from Eclipse plugin, the error reported is the same as in Approach 2, but calling it from a Java application, the error is more specific:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
C:\Users...TestZ33\build\libz3java.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.microsoft.z3.Native.(Native.java:14)
at com.microsoft.z3.Global.ToggleWarningMessages(Global.java:87)
at TestZ3.main(TestZ3.java:9)
Other https://www.chilkatsoft.com/java-loadlibrary-windows.asp
What is working is when you have a Java application under the Z3 build directory. Can anyone help how to use the Z3 build directory from a Java application, or from Eclipse plugin. By the way, I followed approach #2, was working fine until I try to replicate it (because my laptop crashed) and forced to use another laptop, then the same procedure is not working for me (I had luck, before). Right now, the new laptop has the following settings:
HP Laptop (AMD, x64)
C:\Users\nmd02\git\resa_mars_workspace>java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
PATH:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\QuickTime\QTSystem\;C:\Program
Files\MATLAB\2017a\runtime\win64;C:\Program
Files\Java\jdk1.8.0_144\bin;C:\Program Files\Git\cmd;C:\Program
Files\CMake\bin;C:\MinGW\bin;C:\python36;C:\Users...git\ninja;C:\Program
Files (x86)\Windows Kits\8.1\Windows Performance
Toolkit\;C:\gnuwin32\bin
I really appreciate for your help in advance.
Cheers,
/Nas
At runtime your code needs to find com.microsoft.z3.jar, libz3.dll/.so/.dylib, and libz3java.dll/.so/.dylib. Java takes care of the first one, but the operating system will have to find the other libraries, i.e., whatever environment your code runs in must be set up such that PATH (Windows), LD_LIBRARY_PATH (Linux), or DYLD_LIBRARY_PATH (OSX) point to the libraries. Also, make sure that your version of Z3 and your version of Java are both 32-bit or 64-bit, otherwise the error messages you get may not be very informative.
For some flavors of Java, it may also be necessary or helpful to provide the java.library.path setting to the JVM.

IntelliJ debugger doesn't recognize Java version upgrade

I upgraded to Java 8 from Java 6.
As per these instructions, in /Applications/IntelliJ IDEA 13 CE.app/Contents/Info.plist I changed
<key>JVMVersion</key>
<string>1.6*</string>
to
<key>JVMVersion</key>
<string>1.8*</string>
My environment variable JAVA_HOME is set to:
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
However, when I run the debugger in IntelliJ, it still wants to use Java 6:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java ...
Connected to the target VM, address: '127.0.0.1:60490', transport: 'socket'
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/my/MainClass : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
What other settings do I need to change in order for IntelliJ to use the Java 8 JRE?
You changed the IDE's setting. Project setting can be changed here: File->ProjectStructure->Project SDK

couldn't run the TestProgram of JProfiler offline sample

all
I met an error when I running the sample of JProfiler7 offline on my windows PC , the code is from "jprofiler7\api\samples\offline\src\TestProgram.java" ,and got the message as thus:
JProfiler> A different instance of the native library has been
JProfiler> loaded. Please check the appropriate environment
JProfiler> variable. (PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH)
JProfiler> Exiting.
I'm sure there is no any JProfiler process running, and I've imported the referenced libraries by "agent.jar" and set my PATH of JProfiler:
C:\Users\user>echo %PATH%
C:\Program Files\Java\jdk1.6.0_33\bin;C:\Program Files\java\jdk1.6.0_33\jre\bin;C:\Program Files\jprofiler7\bin\windows-x64;C:\Program Files\jprofiler7\bin;
I wanna use the JProfiler API for remoting doing something ,could anybody know how to fix that?
JProfiler:7.2.3
Windows: Win7 Enterprise SP1
JDK:1.6.0_33
And if I use the arguments as following:
-agentlib:jprofilerti=offline,id=4321,config=C:\Program Files\jprofiler7\config\config.xml "-Xbootclasspath/a:C:\Program Files\jprofiler7\bin\agent.jar"
there will be another message:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jprofiler/agent/ControllerImpl
at com.jprofiler.api.agent.Controller.startCPURecording(Controller.java:87)
at TestProgram.main(TestProgram.java:31)
Caused by: java.lang.ClassNotFoundException: com.jprofiler.agent.ControllerImpl
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 2 more
____________edited 2014.05.08 17:04 CST__________________________________
I tried to run the demo of platform (jprofiler7\api\samples\platform\src-profiler\TestProfiler.java) , got the same message both without args and with args(-agentpath:C:\Program Files\jprofiler7\bin\windows\jprofilerti.dll=offline,id=112,config="C:\Program Files\jprofiler7\config\config.xml -Xbootclasspath/a:C:\Program Files\jprofiler7\bin\agent.jar):
JProfiler> A different instance of the native library has been
JProfiler> loaded. Please check the appropriate environment
JProfiler> variable. (PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH)
JProfiler> Exiting.
———————————————————ending—————————————————————————————————————————————
solved that.
In my way, firstly, I start a Java application with VM args
"-agentpath:C:\Program Files\jprofiler7\bin\windows-x64\jprofilerti.dll=port=8849"
Then I run a JProfiler platfrom program with args :
-agentpath:C:\Program Files\jprofiler7\bin\windows\jprofilerti.dll=offline,id=112,config="C:\Program Files\jprofiler7\config\config.xml -Xbootclasspath/a:C:\Program Files\jprofiler7\bin\agent.jar
then I could catch some information , with null value.
Profiling data :
Memory data:
Exception in thread "main" java.lang.NullPointerException
at com.jprofiler.core.comm.d.a.getTotalHeapUsage(ejt:100)
at TestProfiler.dumpMemoryData(TestProfiler.java:82)
at TestProfiler.dumpProfilingData(TestProfiler.java:55)
at TestProfiler.main(TestProfiler.java:47)
In a word , it could run...so ending the question.
Replace the -agentlib VM parameter with
-agentpath:C:\Program Files\jprofiler7\bin\windows\jprofilerti.dll=offline,...
and remove the -Xbootclasspath VM parameter

How to run TestNG suite from command line

I would like to run TestNG Suite from command line on Linux. I'm using eclipse to run test, but I have problem with command line. I know that I need to have testng.jar and I have it in /home/karcio/dev/testng-6.4.jar, location my suite xml is /home/karcio/git/java-test-automation/Automation/test-output/Default suite/TestSuite.xml . Commands what I tried,
set classpath /home/karcio/dev/testng-6.4.jar
cd /location to my suite xml file: java org.testing.TestNG TestSuite.xml
This is error what I see:
Exception in thread "main" java.lang.NoClassDefFoundError: org/testing/TestNG
Caused by: java.lang.ClassNotFoundException: org.testing.TestNG
I'm new in those path and classpath, I'm little bit confusing :(
Thank you
Little update,
I think I did all good, now when I put to terminal: java org.testng.TestNG Test.xml
I've got this error:
Exception in thread "main" org.testng.TestNGException: No sourcedir
was specified at org.testng.TestNG.checkConditions(TestNG.java:1170)
at org.testng.TestNG.privateMain(TestNG.java:1010) at
org.testng.TestNG.main(TestNG.java:997)
all path are exported, so maybe this is wrong version of testng.jar, tried with versions 5.5, 6.4, 6.5, 6.6, 6.7 but I think only version 5.5 is working,
There is a typo in the class package
org.testing.TestNG
should be
org.testng.TestNG
(There no i in the .testng. part)
http://testng.org/javadoc/org/testng/TestNG.html

java.lang.UnsupportedClassVersionError: bad major version at offset=6

I have deployed a WAR file in the webapps folder in my tomcat. And when I am starting my tomcat, like below
C:\apache-tomcat-6.0.35\bin>startup.bat
Using CATALINA_BASE: "C:\apache-tomcat-6.0.35"
Using CATALINA_HOME: "C:\apache-tomcat-6.0.35"
Using CATALINA_TMPDIR: "C:\apache-tomcat-6.0.35\temp"
Using JRE_HOME: "C:\Program Files (x86)\IBM\RationalSDLC\Common\Java5.0\jre"
Using CLASSPATH: "C:\apache-tomcat-6.0.35\bin\bootstrap.jar"
I am getting this below exception-
SEVERE: Error deploying web application archive DirectoryServer.war
java.lang.UnsupportedClassVersionError: (com/services/rest/Listener) bad major version at offset=6 (unable to load class com.services.rest.Listener)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2822)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.startup.WebAnnotationSet.loadClassAnnotation(WebAnnotationSet.java:145)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:73)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:56)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1078)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4612)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
And this is my JAVA version-
C:\apache-tomcat-6.0.35\bin>java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
Can anyone provide any suggestion why is it happening?
You have essentially compiled your code with JDK 1.6 but running it with Java 5 - Just ensure a Java 6 runtime.
Even I faced same problem. The problem is inappropriate class version, for ex. compiling with different jre.
Solution: IF you are using Eclipse or RAD, set change compiler setting as per your requirement and also change same setting to project configuration by clicking on "Configure Project specific setting". Windows->Preferences->Compiler-> click on link "Configure Project specific setting".
For me the fix was to set the JAVA_Home system variable to the correct path.
It is a compiler issue. Make sure all your modules are configured with java 1.5 as a compiler. Window-->preference--> Java --> Compiler. Make sure 1.5 is selected.