I have some jars in the current directory, all needing to be in the class path, so I want to use the wildcards convention for classpath. The command line is:
java.exe -classpath * org.python.util.jython args
However I get this error
Exception in thread "main" java.lang.NoClassDefFoundError: G:/repo/builds/jars/edu_mines_jtk/jar
Caused by: java.lang.ClassNotFoundException: G:.repo.builds.jars.edu_mines_jtk.jar
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:/repo/builds/jars/edu_mines_jtk.jar. Program will exit.
If I manually expand the wildcard, with
java.exe -classpath edu_mines_jtk.jar;ij.jar;jython.jar;more-jars org.python.util.jython [args]
Then it works as expected.
What's wrong with my wildcards?
JRE 1.6.25 for Win7 64 bit
I found it, under Windows quotes around the wildcarded classpath are required.
But not required if you specify jars explicitly, explaining why the second command works.
Weird.
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.
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.
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 .
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