When I run my program from terminal by executing the command java rmiserver.LightBulbServer.class I'm getting NoClassDefFoundError :
Exception in thread "main" java.lang.NoClassDefFoundError: rmiserver/LightBulbSe
rver/class
Caused by: java.lang.ClassNotFoundException: rmiserver.LightBulbServer.class
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)
Could not find the main class: rmiserver.LightBulbServer.class. Program will ex
it.
You are most likely running the application like this:
java rmiserver.LightBulbServer.class
You shouldn't add the .class extension when running your program; use only the name of the class:
java rmiserver.LightBulbServer
You're running the command:
java rmiserver.LightBulbServer.class
when you should be running
java rmiserver.LightBulbServer
You need to set some variables before Java can do anything on a system. This is why some people create batch files to get their Java programs running without modifying system variables.
But this usually happens because you didn't set the CLASSPATH.
For example, here is something that may or may not work:
set JAVA_HOME=C:\jdk1.5.0_06
set PATH=C:\jdk1.5.0_06\bin;C:\Windows;C:\Windows\System32
set CLASSPATH=.
java -jar myprogram.jar
Or try this command:
java -jar myprogram.jar -classpath .
Related
First time trying to run some Java code under Windows here, and I got:
D:\Tmp>java JDBC_SQLServer
Picked up _JAVA_OPTIONS: -Xmx512M
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
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 JDBC_SQLServer.main(JDBC_SQLServer.java:19)
I.e., java finds main but didn't find the lib. Now, --
D:\Tmp>java -classpath "C:\Program Files\Java\jdk1.8.0_162\lib" JDBC_SQLServer
Picked up _JAVA_OPTIONS: -Xmx512M
Error: Could not find or load main class JDBC_SQLServer
I.e., java finds the sqlserver.jdbc.SQLServerDriver lib but can't find main now.
The JDBC_SQLServer is just a hack from
https://learn.microsoft.com/en-us/sql/connect/jdbc/connection-url-sample
How to solve it? Thx.
The classpath needs to contain the current directory (in order to find your class and its main-method and the jar-file (not only a directory with jars in it), so a call could look like this:
D:\Tmp>java -cp "C:/mssql/lib/sqljdbc41.jar;." JDBC_SQLServer
You don't need to use backslashes for the paths and because backslashes are often parsed specially by the shell you use, I personally try to avoid them as much as possible.
I'm a newbie to Java (just two days) and am trying to get an HTTP server running using Spark. I created a new Maven project in IntelliJ and have a Hello World response coming back from Spark when running it in IntelliJ. As a learning exercise, I would like to get the app running from the command line using Java.exe. When I run java Main, I get the following error:
Exception in thread "main" java.lang.BootstrapMethodError:
java.lang.NoClassDef oundError: spark/Request
at Main.main(Main.java:5) Caused by: java.lang.NoClassDefFoundError: spark/Request
... 1 more Caused by: java.lang.ClassNotFoundException: spark.Request
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)
... 1 more
Looks like it can't find the Spark .jar files. There's a command line option -cp to specify paths to dependencies. After looking up where Maven keeps these files, I tried running:
java -cp .;C:\Users\jbuschmann.m2\repository Main
Still same error. How do I specify the path to the Maven dependencies?
Instead of giving the repository in the -classpath, try adding the location of your spark.jar.
java -cp \path\to\spark.jar Main
While running a scheduler program through command prompt, I am getting the below error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/quartz/ScheduleBu
ilder
Caused by: java.lang.ClassNotFoundException: org.quartz.ScheduleBuilder
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)
Could not find the main class: ScheduleEmail. Program will exit.
Even after adding all the jar files also I am getting the following.
Java command : java - cp .;E:/Jars/*; ScheduleEmail
Can anyone please suggest why I am getting this?
When using a wildcard (on windows platform), you need to surround it with quotes to work correctly:
java -cp ".;E:/Jars/*;" ScheduleEmail
1. http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
first, make sure if there is a typo, there's no space between "-" and "cp"
second, check if quarts jars are in E:/Jars/
I'm running OpenStreetMap's Osmosis in Windows XP to cut a subset of data from a larger set. In various incarnations, the program either hangs or gives me the following error:
C:\Documents and Settings\mmorisy\tools>osmosis.bat --read-xml enableDateParsing
=no file="us_zipcodes.osm" --log-progress interval="10" --bounding-box top=43.22
868195 left=-73.5981635 bottom=41.2283584 right=-69.814204 --write-xml file="mas
s_zipcodes.osm"
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/classwor
lds/Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.classworlds.Launcher
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)
Could not find the main class: org.codehaus.classworlds.Launcher. Program will
exit.
I get the feeling that Java isn't properly installed or configured, but I have installed the most revent SDK from Oracle's website and can't figure out where else I might be going wrong, despite maybe half dozen variations.
The error you're getting implies that Java itself is installed correctly, but it can't find the .class file it's trying to run.
At a guess, osmosis.bat has an incorrect -jar or -cp (or -classpath) argument to the classworlds.jar file in it.
I need to run my RMI server RmiEncodingServer) using the command line,
my class files reside in this folder:
C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerClasses
in package hw2.rmi.server.
The code base reside in this folder:
C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerCodeBase
in package hw2.rmi.server.
I use the command line:
java –classpath C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerClasses\ -Djava.rmi.server.codebase=file:/C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerCodeBase -Djava.security.policy=C:\workspace\distributedhw2\permissions.policy hw2.rmi.server.RmiEncodingServer
but I get a "class not found" exception as follows:
Exception in thread "main" java.lang.NoClassDefFoundError: ûclasspath
Caused by: java.lang.ClassNotFoundException: ûclasspath
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)
Could not find the main class: GÇôclasspath. Program will exit.
where have I gone wrong?
also, if you can provide instructions on how to run the server in eclipse, I added the following as a VM argument, but I get a class not found exception to a class that is in the RmiServerCodeBase:
-Djava.security.policy=C:\workspace\distributedhw2\permissions.policy -Djava.rmi.server.codebase=file:/C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerCodeBase
thanks
I found out that the problem was that I was trying to refer to the .java files in my codebase and not .class files, i suppose that propery name "codebase" is a bit misleading. so if you want to do it in your RMI server you can do it this way:
String codeBasePath = "file:/C:/workspace/distributedhw2/"
+ "AgencyServers/RmiEncodingServer/RmiServerClasses/";
System.setProperty("java.rmi.server.codebase",codeBasePath);
or simply pass the following as VM arguments:
-Djava.security.policy=C:\workspace\distributedhw2\permissions.policy -Djava.rmi.server.codebase=file:/C:\workspace\distributedhw2\AgencyServers\RmiEncodingServer\RmiServerClasses