Main Class Not Found - java

I am to connect to a MySQL database from a Java application to store images taken from a scanned form. When I run the program I get a Could not find or load main class error.
I have tried setting the classpath but still get the same error: Could not find or load main class. By the way, another java file I created in the directory compiles. When I try to set the classpath I also get the same error. Here is the (EDITED)code:
java -cp "C:\Documents and Settings\xxx\Desktop\ttt_manual_yyy\mysql\mysql-connector-java-5.1.6-bin" ImageUploader C:\Documents and Settings\yyy\Desktop\IMAGES localhost uuu nnn
Where localhost is database address,uuu is username,nnn is password

You're not even specifying a class, and you need to put your classpath in quotes as it's got spaces. So it should be something like:
java -classpath "C:\Documents and Settings\...\ImageUpload" foo.ImageUploader
where foo.ImageUploader is the fully-qualified name of the class containing the main method.

Related

Weblogic 12.2.1.3 Error: Could not find or load main class com.oracle.cie.wizard.WizardController

I was trying to configure Weblogic 12.2.1.3 on Linux account.
After going through oracle documentation, I understood we setup Weblogic by running config.sh script located in /opt/weblogic12213/wlserver_12.2.1.3/installation/oracle_common/common/bin folder.
But this script is giving error as :
Error: Could not find or load main class
com.oracle.cie.wizard.WizardController
Below is the last command which it executes in setup script and it is giving an error :
/usr/java/jdk1.8.0_192/bin/java -Dpython.cachedir=/tmp/cachedir
-Xms32m -Xmx1024m -Dweblogic.alternateTypesDirectory=/opt/weblogic12213/wlserver_12.2.1.3/installation/wlserver/../oracle_common/modules/oracle.oamprovider,/opt/weblogic12213/wlserver_12.2.1.3/installation/wlserver/../oracle_common/modules/oracle.jps
com.oracle.cie.wizard.WizardController -target=config-oneclick
scripts provided by weblogic doesn't set CLASSPATH correctly.
com.oracle.cie.wizard.WizardController comes under com.oracle.cie.wizard_7.8.2.0.jar .
Steps done.
1. Copied config_internal.sh script on some local path. (Because I didn't have the root permission.)
2. Appended this jar in CLASSPATH varibale like this :
CLASSPATH="${FMWCONFIG_CLASSPATH}${CLASSPATHSEP}${DERBY_CLASSPATH}:/opt/weblogic12213/wlserver_12.2.1.3/installation/oracle_common/modules/com.oracle.cie.wizard_7.8.2.0.jar"

On using a batch file in cmd Could not find or load main class for a program

The error image
Error: Could not find or load main class JDBCExample1.java
Caused by: java.lang.ClassNotFoundException:JDBCExample1.java
Batch file used:
set path=C:\Program Files\Java\jdk-10.0.2\bin;
set classpath=C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc14.jar;.
javac JDBCExample1.java
java JDBCExample1.java
pause
The PATH and the CLASSPATH have been set correctly in Environment variables too.
Also the directory used is correct.
Try giving
“java JDBCExample1”
Instead of
“java JDBCExample1.java”
In the last line. One does not use .java while running the program

ClassNotFoundException while replacing java 6 rmi w/ java 8 [duplicate]

The following method :
private void startServer() { // snippet that starts the server on the local machine
try {
RemoteMethodImpl impl = new RemoteMethodImpl();
Naming.rebind( "Illusive-Server" , impl );
}catch(Exception exc) {
JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(exc);
}
}
throws this exception :java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: Interfaces.RemoteMethodIntf
When i start my project, i am greeted with the message in JOptionPane saying problem starting the server and then the above exception. What could be the reason for this ?
I don't understand why does the last statement of exception says class not found exc when i have imported the right packages
There are four cases of this exception.
When exporting: you didn't run 'rmic' and you didn't take the steps described in the preamble to the Javadoc for UnicastRemoteObject to make it unnecessary.
When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.
when looking up: the client does't have these things on its classpath.
When calling a remote method: you either sent something to the server of a class not present on its CLASSPATH, or received something from the server (including an exception) of a class not on your CLASSPATH: in both cases possibly a derived class or interface implementation of a class or interface mentioned in the remote interface's method signature.
This is case 2. The Registry can't find the named class.
There are several solutions:
Start the Registry with a CLASSPATH that includes the relevant JARs or directories.
Start the Registry in your server JVM, via LocateRegistry.createRegistry().
Use dynamic stubs, as described in the preamble to the Javadoc of UnicastRemoteObject. However you may then still run into the same problem with the remote interface itself or a class that it depends on, in which case 1-3 above still apply to that class/those classes.
Ensure that case (4) above doesn't occur.
Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.
Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface
The error very simple to solve to be perform following steps:
For example your java file consider D drive
Start rmiregistry D drive( example D:\start rmiregistry)then don't start rmiregistry on the other drives, it will yield the above error
(Wherever your file is, start rmiregistry)
I will try to explain it as better as possible what I did:
1st. I declared the classpath variable like follow:
set classpath=%classpath%
set classpath=C:\compiler
set classpath=C:\compiler\libro\cap07\rmi\hello\Hello.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
(All in one lineset:
set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\Hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)
(I'm not sure if the .java files were nesesary, but I also wrote them for doubts).
2nd. I compilered with the line javac -d C:\compiler Hello.java Server.java Client.java. Where C:\compiler is the root directory like src on Eclipse IDE.
3rd. I ran the start rmiregistry line. (and don´t matter where you run it, it's the same).
4th. I ran:
start java -classpath C:\compiler -Djava.rmi.server.codebase=file:C:\compiler/ libro.cap07.rmi.hello.Server
You already know C:\compiler, but you need define packages address on the last to that the command can find the .class files. Open any .java file and copy the package address without packages sentense. You will see when you open the src directory (in my case C:\compiler), you find all directory sequence created. When this command line is created correctly, no matter where you will run it, C:, D:, src, anywhere it wil run.
5th. And finally, I ran the Client class with:
java -classpath C:\compiler libro.cap07.rmi.hello.Client
In conclusion, if the classpath variable won't created or it's to created wrong or the sentence of 4th point is not addressed well the JVM throws the same or similar error. Search there!
(Sorry my english).
You can launch rmiregistry from anywhere but you have to make sure that the compiled classes are already in your classpath. For example:-
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry
And the above should work fine.
In general, if you launch rmiregistry from the root location of the compiled classes (above example it is E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes), that will work because . (dot - current directory) is already set in your classpath.
But as soon as you remove . (dot - current directory) from your classpath, the above working condition will also fail.
Hope I have explained in details.
I got this same issue, and a different solution worked for me. I was running two different IntelliJ projects, with a copy of the interface in each project. One of them was in a package, and the other one wasn't, and that was what was causing this error.
Solutions:
Make sure the interface copies aren't in a package.
Make sure the interface copies have the exact same package name.

Is there any limitation on the length of the classpath in java?

I tried to set classpath from command line for a java class
java -cp lib1.jar;lib2.jar;lib3.jar MyProgram
The above code threw runtime exception as it has further dependency with other jar file when I added the jar file it is unable to recognize the Main class in MyProgram class and threw
Error:Main method not found in class MyProgram,please define the method as public static void main(Stirng[] args)
The length of the strings lib1 ,lib2 and lib3 is about 400 characters.
Is there any limitation on the size of the classpath which can be set from command line .I tried setting class path using Manifest file as well but still it is throwing same exception.
I cannot test the program that you have written,so one solution by observing the details provided could be-
java –classpath ${CLASSPATH} MyProgram
Note: here you would have to set CLASSPATH variable before using it.

jdb-Could not find or load main class Main

i would like to use jdb,i'm trying to run it couple of hours already and i have searched all over the examples there are.i think its a syntax problem..
i'm trying to run it like this:
>jdb Main
Initializing jdb ...
>run
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
VM Started:Error: Could not find or load main class Main
The application exited
//-----------------------------
I also tried to put the full path which is:
C:/Users/Daniel/Documents/NetBeansProjects/Try/src/pkgtry/Main.java
Try to use -sourcepath and -classpath. sourcepath should point to source codes (.java) and classpath should point to compiled code (.class).
It's also good idea to put your source inside package (in case of Java just create directory and put sources there).
Use full name of source file with extension (filename.java)
in directory with your source file:
C:/Users/Daniel/Documents/NetBeansProjects/Try/src/pkgtry>
>jdb Main.java
Initializing jdb ...
>run
or
C:/Users/Daniel/Documents/NetBeansProjects/Try/src/pkgtry>
>jdb
Initializing jdb ...
>run Main.java

Categories