aspose file tools*
The moose likes Beginning Java and the fly likes Error: Could not find or load main class com.sun.tools.javac.Main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error: Could not find or load main class com.sun.tools.javac.Main" Watch "Error: Could not find or load main class com.sun.tools.javac.Main" New topic
Author

Error: Could not find or load main class com.sun.tools.javac.Main

John Simer
Greenhorn

Joined: Dec 19, 2011
Posts: 16
So, i'm trying to compile HelloWorldApp.java

I installed Java on my flashdrive(i dont think that should be a problem) - H:\java
I have my Path set to H:\Java\bin;
I see that the javac.exe is installed in the bin, but when on command prompt i try "javac -version" it still says
"Error: Could not find or load main class com.sun.tools.javac.Main"

Any idea what i'm doing wrong? Please help, not being able to compile anything is getting annoying.

Thanks,
God Bless you
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

It sounds like you're either missing part of the JDK (tools.jar) or your classpath is not set up correctly. javac.exe is really just a wrapper that fires com.sun.tools.javac.Main from that tools.jar in JDK_HOME/lib.

When you copied it to your flash drive, did you copy everything?


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
John Simer
Greenhorn

Joined: Dec 19, 2011
Posts: 16
I believe I installed it to the H: drive and never copied anything
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
H:\java\bin

That doesn’t sound right. It usually has something like jdk1.7.0_00 after “Java” and before “bin”. Open that folder with Windows® Explorer and check what the correct path to your bin folder is.
John Simer
Greenhorn

Joined: Dec 19, 2011
Posts: 16
My bin folder is saved inside of my Java folder
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

Campbell Ritchie wrote:H:\java\bin

That doesn’t sound right. It usually has something like jdk1.7.0_00 after “Java” and before “bin”. Open that folder with Windows® Explorer and check what the correct path to your bin folder is.

Don't forget you can change the path during installation. On my system I have changed the defaults to D:\Programs\JDK\1.6.0 and D:\Programs\JDK\1.7.0 (with D: being my Development drive).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
John Simer wrote:My bin folder is saved inside of my Java folder
In that case the path would be correct. Have you got all the other parts of the JRE, eg rt.jar, in that Java folder in such a location that their relative path would be the same as in an installation to yoru hard drive? On my hard drive, the jre and bin folders are both immediate subfolders of jdk1.7.0_01, and rt.jar is inside the jre folder, so rt.jar and the “java” tool are in folders which share the same “grandparent” folder, viz jdk1.7.0_01.
John Simer
Greenhorn

Joined: Dec 19, 2011
Posts: 16
Ok I just decided to delete java off my flashdrive(H:) and save it on my computer (C:), and I got the compiling part to work, but in a weird way. I had to go to where the javac.exe and from there type the javac command for the entire file name like this:

"C:\Program Files\Java\jdk1.7.0_02\bin>javac C:\jvj\HelloWorldApp\HelloWorldApp.j ava"

then the .class showed up in my directory

Directory of C:\jvj\HelloWorldApp

12/20/2011 01:43 PM <DIR> .
12/20/2011 01:43 PM <DIR> ..
12/20/2011 01:43 PM 432 HelloWorldApp.class
12/20/2011 01:43 PM 118 HelloWorldApp.java
2 File(s) 550 bytes
2 Dir(s) 74,377,527,296 bytes free


but when i tried running it...

C:\jvj\HelloWorldApp>java HelloWorldApp.class
Error: loading: H:\Java\bin\client\jvm.dll

^why is it still trying to get stuff from my flashdrive? It should be trying to get the files from C:\Program Files\Java\jre6\bin
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Why would you expect to use files in a jre6 folder when you are using “javac” in a jdk7 folder?
John Simer
Greenhorn

Joined: Dec 19, 2011
Posts: 16
I'm not really sure... Because i'm using the "java" and not the "javac", so isnt the "java" just running it?

But regardless how do I make it work? (i.e. when i use the java.exe it runs the program)
John Simer
Greenhorn

Joined: Dec 19, 2011
Posts: 16
Ok basically I reinstalled java again this time version 6u29 instead of 7u2, and i got the javac to work
"C:\Program Files\Java\jdk1.6.0_30\bin>javac C:\jvj\HelloWorldApp\HelloWorldApp.j
ava

C:\Program Files\Java\jdk1.6.0_30\bin>cd\jvj\HelloWorldApp

C:\jvj\HelloWorldApp>dir
Volume in drive C is ACER
Volume Serial Number is A057-D808

Directory of C:\jvj\HelloWorldApp

12/20/2011 08:48 PM <DIR> .
12/20/2011 08:48 PM <DIR> ..
12/20/2011 09:00 PM 432 HelloWorldApp.class
12/20/2011 01:43 PM 118 HelloWorldApp.java
2 File(s) 550 bytes
2 Dir(s) 75,082,752,000 bytes free"
but running it still doesnt work.
"C:\jvj\HelloWorldApp>java HelloWorldApp
'java' is not recognized as an internal or external command,
operable program or batch file."

likewise,
"C:\jvj\HelloWorldApp>java -cp . HelloWorldApp
'java' is not recognized as an internal or external command,
operable program or batch file."
and,
"C:\jvj\HelloWorldApp>java -classpath . HelloWorldApp
'java' is not recognized as an internal or external command,
operable program or batch file."



EDIT: --------------
i made a new topic that now there is a different problem
Thanks for all the help guys!
Jesus Christ is truly amazing!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
That is the usual place to install Java™. You can probably install Java™ to your flash stick by altering the options when you install it, but you would need a different path. There is information about setting paths, etc, in our FAQ.
 
wood burning stoves
 
subject: Error: Could not find or load main class com.sun.tools.javac.Main
 
Similar Threads
Excercise 1-1 from Kathy Sierra, Bert Bates Study Guide
Installation Problem-Help with running compiled code in command line.
Ant unable to find javac compiler (in Eclipse)
Could not find the main class: com.sun.tools.javac.Main.
JDK malfunction