aspose file tools*
The moose likes Beginning Java and the fly likes Need guidance on how to get Javac compile to execute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need guidance on how to get Javac compile to execute" Watch "Need guidance on how to get Javac compile to execute" New topic
Author

Need guidance on how to get Javac compile to execute

Joe Raszewski
Greenhorn

Joined: Apr 14, 2012
Posts: 6
i am beginning a java programming class and have downloaded jdk1.6.0_30 and it recognizes the java command and confirms the version of java, but will not run the javac command and will not return a version for javac. I have spent hours retrying the download and can't get javac to work. one theory is that I originally doenloaded the JRE for 1.6.0_31 only to start and it created a separate folder in the Java folder for the jre6 vs. the jdk and the reinstall put the JRE in the 2nd file folder jre6 again. Does the jre6 need to be in the same folder as the remainder of the jdk1.6.0 files? that's just a guesss. I simply can't get javac to work and am going in cirlces. any helpm would be really welcome. Thank you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14348
    
  22

Welcome to the Ranch!

What is the exact error message that you get?

Did you follow the installation instructions? Especially take note of step 4, setting the PATH environment variable.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Joe Raszewski wrote:Does the jre6 need to be in the same folder as the remainder of the jdk1.6.0 files?

No! If you change the default to the folder where you just installed a JDK you'll lose the JDK, including javac.exe.


luck, db
There are no new questions, but there may be new answers.
Rajeev Motha
Greenhorn

Joined: Apr 05, 2012
Posts: 7
Do you see javac in your jdk1.6.0_30/bin ? How are you trying to compile? Command Line?
Please post more details on your execution environment and any error messages.
Joe Raszewski
Greenhorn

Joined: Apr 14, 2012
Posts: 6
hi Rajeev. Thanks for your reply. i see javac in my bin folder, but not javac.exe. I am trying to complie from the command line. A good example of the error is that when I try Javac Filename.java, it returns 'javac not recognized as an internal or external command...'. i tried uninstalling jdk today and reinstalling the latest 1.7 version. everything completed, but i still get same message whan attempting to compile and still do not see javac.exe in the 1.7 bin folder (I do see a file javac, but it has no extension).... This has to be something simple i am either missing in the download or install process. Everything else completes normally. I re-register with Oracle and i can see the java -version return the java 1.7, etc... I am still stumped. Any help would be really appreciated. Thanks
Vince Stout
Greenhorn

Joined: Apr 13, 2012
Posts: 19
As stated earlier, make sure you add the 'bin' folder (the folder where javac is) to your path. It should look something like this --> C:\Java\jdk1.6.0_30\bin\

Here, is a tutorial on doing so

-VS

Always consult the oracle before asking a question.
Joe Raszewski
Greenhorn

Joined: Apr 14, 2012
Posts: 6
Thanks Vince.

ok. i now know the software is operational because i was able to navigate to the bin folder and compile & run the HelloWorld program while in that directory. Therefore, i must not have my variables set properly. I also can't copy my java files into the bin for compile so i have to rely on PATH and CLASSPATH and must not have them set properly. Here's what i have set up.


User Variable

%JAVA_HOME% is set to: C:\Program Files\Java\jdk1.7.0_03\bin


System Variable

CLASSPATH is set to: .;C:\Program Files\Java\jdk1.7.0_03\bin

PATH is set to: %JAVA_HOME%\bin;C:\Windows\etc..other stuff....

This must be wrong. Got the ideas from other posts on setup. I presume that if they were set properly that i could run javac and java commands from any command prompt, correct? i think i made some progress today, but still not where i need to be.

Any guidance would be helpful. Thanks
Vince Stout
Greenhorn

Joined: Apr 13, 2012
Posts: 19
You said path is set to '%JAVA_HOME%\bin' if that's correct, you need to remove the '\bin' because its already defined in %JAVA_HOME%. And you should also add that to the end of your PATH variable, not the beginning.

You can also remove CLASSPATH, that's more for if you want the compiler (javac) to find your own 3rd party libraries and such without using the -cp switch.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39844
    
  28
Joe Raszewski wrote:. . . i was able to navigate to the bin folder and compile & run the HelloWorld program while in that directory. . . . I also can't copy my java files into the bin for compile so i have to rely on PATH and CLASSPATH and must not have them set properly. . . .
It is a serious mistake trying to work inside the bin folder. Progam Files is not for you to put your own work in. It is also a mistake to set your own classpath, even though some books tell you to. You can delete that classpath entirely and suffer no problems. Your %JAVA_HOME% variable should not end in bin. You can either set a JAVA_HOME which ends in jdk1.7.0_03 or similar, or put the whole path in the path variable entry. If you have bin in both, the computer will try to find a bin/bin folder which you haven’t got.

You know what error message you get if you supply a path to a non-existent folder? None at all! You might find our FAQ helpful.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14348
    
  22

Joe Raszewski wrote:%JAVA_HOME% is set to: C:\Program Files\Java\jdk1.7.0_03\bin

That should have been C:\Program Files\Java\jdk1.7.0_03 without the bin.

Note: For Java itself, the JAVA_HOME environment variable doesn't matter. Java doesn't use it. Some other programs do, but just for compiling Java source code with the JDK you don't need to set JAVA_HOME at all.

Joe Raszewski wrote:CLASSPATH is set to: .;C:\Program Files\Java\jdk1.7.0_03\bin

That is wrong. CLASSPATH is used by Java to find compiled *.class files. The bin directory of your JDK does not contain class files. It does not belong in the CLASSPATH.

It is best to not set CLASSPATH at all. If you leave it unset, Java will by default use the current directory "." as the classpath.

Joe Raszewski wrote:PATH is set to: %JAVA_HOME%\bin;C:\Windows\etc..other stuff....

That is correct. If you use JAVA_HOME in the PATH like this, then ofcourse JAVA_HOME has to be set too, but without the bin in it as I wrote above.
Joe Raszewski
Greenhorn

Joined: Apr 14, 2012
Posts: 6
Thanks for everyone's help.

I finally got the PATH set and got my test program to compile and run. I am running a 2nd test with a program copied verbatim from my text. It's the I Rule The World progam and while I have copied it right from the book, i keep getting the missing return statement error. I cannot figure out the solution. I've tried placing the closing bracket in al positions, butt . Heres the program and the corresponding message. What am i doing wrong?





C:\Tracey's Files> javac MyFirstJavaApp.java
MyFirstJavaApp.java:7: error: missing return statement
}
^
1 error

C:\Tracey's Files>
Joe Raszewski
Greenhorn

Joined: Apr 14, 2012
Posts: 6
P.S. the indentations are missing after the copy but they line up and are in line as per the program in the book...
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Joe Raszewski wrote:I have copied it right from the book

No you haven't. Java is case sensitive. Look carefully at the declaration of the main method.


Joanne
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Joe Raszewski wrote:P.S. the indentations are missing after the copy but they line up and are in line as per the program in the book...

UseCodeTags
Vince Stout
Greenhorn

Joined: Apr 13, 2012
Posts: 19
Let the compiler help you. It says your problem is on line 7. That is where you start looking. What looks different between line 7 in the book and yours?

To use code tags put code=java between sqauare brackets above your first line of code, and /code between brackets after your last line of code
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39844
    
  28
I can add code tags for you.
Joe Raszewski
Greenhorn

Joined: Apr 14, 2012
Posts: 6

Joanne. Thank You. When I am working in Notepad it is very hard to distinguish Caps from small case. Until I copied that code into the forum, i could not see that the 'V' was capitalized. It now runs.

Thank you. I am on my way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need guidance on how to get Javac compile to execute