Hello,
I know this is a basic question but i didnt get the answer myself. So posting it here.
I have a program that spans many files, all are .java. If i have to compile them should all of them be in the bin folder of the JDK? Can i put all of them into a folder and compile it using javac as usual? How can i go about it? What should the command include?

Recommended Answers

All 4 Replies

Hello,
I know this is a basic question but i didnt get the answer myself. So posting it here.
I have a program that spans many files, all are .java. If i have to compile them should all of them be in the bin folder of the JDK? Can i put all of them into a folder and compile it using javac as usual? How can i go about it? What should the command include?

Put them all in the same folder, then get a command line and change directories till your command line directory is the directory that contains all of the .java files. Then just type:

javac *.java

If your path is set up correctly, there's no need to move them all to your bin folder.

I tried that method n i got this message:
'javac' is not recognized as an internal or external command, operable program or batch file.

I also tried this:
>javac -classpath . MyClass.java
in the new directory and got the same message again.

Any suggestions or corrections?

I tried that method n i got this message:
'javac' is not recognized as an internal or external command, operable program or batch file.

I also tried this:
>javac -classpath . MyClass.java
in the new directory and got the same message again.

Any suggestions or corrections?

Don't confuse your path and your classpath. You have a path problem. The computer can't find javac.exe. You can go into the Control Panel and add the bin directory where the javac.exe program is to your path. On my computer it is in this directory.

C:\Program Files\Java\jdk1.6.0_02\bin

If you are using Windows XP, do this. Go to:

Start->Control Panel->System->Advanced->Environment Variables->System Variables, and scroll down to the Path variable, hit edit, then go to the end of the line, add a semicolon, then add the relevant directory (in my case, it's the one above. Change it if yours is different).

Exit out of the control panel, close any console windows that are open, then open a new console window and try the javac *.java command again.

Hi,
That was exactly the problem. Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.