Java Could not find main class...
Ok I've searched and searched everywhere and just don't know where to look next!
Right so I'm using eclipse and have named my files the same as my project for example HelloWorld.java and my public class is HelloWorld, I exported the project as a executable java file through eclipse.. So I thought great! This will run on it's own! but no.... I've tried and tried and just can't seem to fix it!
So my problem!
I've double checked my MANIFEST.MF file loads of times and my file names etc.. here is my manifest file..
Code:
Manifest-Version: 1.0
Class-Path: .
Main-Class: test.HelloWorld
And my java file
Code:
package test;
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
System.out.print("Hello world");
}
}
Now I have no idea why this won't run or work.. I keep getting the message: " Could not find the main class. HelloWorld. program will exit"
Why oh Why is this happening? For what I can see my files are in the right places within the HelloWorld.jar file that i exported using Eclipse so it should be fine??
Anyhoot, hope you can understand any help is greatly appreciated as I don't know what I'm doing wrong!!
Thanks in advanced!!
/Diciwales
Re: Java Could not find main class...
Try running it in a command prompt window and see if you get a more complete error message.
Open a command prompt window, change to the folder with the jar file and enter:
java -jar <THEJARFILENAME>.jar
If on Windows:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
Re: Java Could not find main class...
Quote:
Originally Posted by
Norm
Try running it in a command prompt window and see if you get a more complete error message.
Open a command prompt window, change to the folder with the jar file and enter:
java -jar <THEJARFILENAME>.jar
If on Windows:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
Thanks,
It works exactly fine with no error messages in CMD and displays
HelloWorld
Exactly how it should..
Thanks in Advanced
Re: Java Could not find main class...
Is that output from the program you posted? The text of the output is different.
HelloWorld
vs
Hello world
Details are important in programming.
Re: Java Could not find main class...
Quote:
Originally Posted by
Norm
Is that output from the program you posted? The text of the output is different.
HelloWorld
vs
Hello world
Details are important in programming.
No it was displayed Hello World, I just typed it wrong from the cmd here is it selected all
:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>java -jar HelloWorld.jar
Hello world
C:\Users\Administrator>
Regards
Re: Java Could not find main class...
What happened to the error message you were getting?
Re: Java Could not find main class...
The error message is still there.. it happens when i double click the application
so confused.. just uninstalled and re-installed java.. no luck
Regards
Re: Java Could not find main class...
What version of Windows are you on?
Do you know about the registry and the registry editor?
The registry contains the commandline the OS uses when it executes files.
Here is the registry contents for .jar files on my XP machine:
[HKEY_CLASSES_ROOT\jarfile\shell\open\command]
@="\"C:\\Program Files\\Java\\jre1.6.0_07\\bin\\javaw.exe\" -jar \"%1\" %*"
Re: Java Could not find main class...
Hi i'm on windows 7,
how do i find the registry contents for .jar files using CMD?
Thanks again for your help so far ! much appreciated
Re: Java Could not find main class...
Execute the regedit command. It has a windows explorer like interface. Do a Find for .jar. It wiil be in a long list of all the extensions that windows knows about. The right hand window will show (Default) on the left and will have a name in the Data column. On my system the name is jarfile.
Do a Find for the name you see there. Under that name will be shell and command. Open command and see if it looks a little like what I posted in #8.
Use the export menu item to export the contents to a file that you can EDIT/not merge and post here.
Re: Java Could not find main class...
Quote:
Originally Posted by
Norm
Execute the regedit command. It has a windows explorer like interface. Do a Find for .jar. It wiil be in a long list of all the extensions that windows knows about. The right hand window will show (Default) on the left and will have a name in the Data column. On my system the name is jarfile.
Do a Find for the name you see there. Under that name will be shell and command. Open command and see if it looks a little like what I posted in #8.
Use the export menu item to export the contents to a file that you can EDIT/not merge and post here.
Ok I Think I have done that..
here is what it looks like..
Quote:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.jar]
@="jarfile"
I assume that is wrong? What must it be ? what must it link too?
Thanks again! your help is much appreciated!
Re: Java Could not find main class...
You didn't follow all the instructions. You need to do two Finds.
The first for ".jar" which you did and got the "jarfile" value. That looks OK.
Now you need to do the second Find for "jarfile" which will have the command line.
Re: Java Could not find main class...
ok sorry, here is the next part
Quote:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\jarfile]
@="Executable Jar File"
[HKEY_CLASSES_ROOT\jarfile\shell]
[HKEY_CLASSES_ROOT\jarfile\shell\open]
[HKEY_CLASSES_ROOT\jarfile\shell\open\command]
@="\"C:\\Program Files (x86)\\Java\\jre6\\bin\\javaw.exe\" -jar \"%1\" %*"
Thanks again
Re: Java Could not find main class...
That looks a lot like mine.
Is your PC 64bit or 32bit? I forget what the (x86) in the path means.
Re: Java Could not find main class...
Re: Java Could not find main class...
What is the PATH environment set to? Open a command prompt and enter: path
Does it have a pointer to the same bin folder that is in the command line in the registry?
Re: Java Could not find main class...
Quote:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>path
PATH=C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;
C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Sys tem32\WindowsPowerShell\v1.0\
C:\Users\Administrator>
that's what is displayed when I type Path into the CMD
Re: Java Could not find main class...
What version of java do you get when in a CMD window? Enter:
java -version
Re: Java Could not find main class...
Quote:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
C:\Users\Administrator>
Regards
Re: Java Could not find main class...
That's all the ideas I have for finding a problem. I don't know where to go next.
Click to open the jar file and Screen print the error message and post the image