aspose file tools*
The moose likes Beginning Java and the fly likes Class file not getting created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class file not getting created" Watch "Class file not getting created" New topic
Author

Class file not getting created

karthik chandrasekar
Greenhorn

Joined: Nov 12, 2008
Posts: 1
Hi all,

I am a beginner to java and I am not able to compile a program.

My "path" variable has been set to:
C:\Program Files\Java\jdk1.6.0_10\bin

My "classpath" variable has been set to:
C:\Program Files\Java\jdk1.6.0_10\bin

My program is also available in bin folder shown above. I executed javac compile command and my program compiled successfully. My CLASS file is not getting created at all. I changed the system setting to provide read/write to the particular folder in C drive.

Please let me know if I need to do anything else in order get myself running
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
Welcome to JavaRanch

Please don't put your files in the bin folder; leave that for java executables. If you uninstall Java to install a new version, your work will all vanish.
Create a new folder. If you are using Windows you will probably start in "my documents" when you open the command line.That will create a "java" folder where you happen to be working, move you to that "java" folder, and print its contents. At present there should be nothing there.
Use a text editor (preferably not NotePad, go for Jedit, Notepad++ or Notepad2 which can all be downloaded free) and save the .java file in that same java folder. Write dir again at the command line, then try compiling withIf that works, you need to go back and edit your CLASSPATH. Don't put your Java bin folder in the CLASSPATH. Delete it. If you have an empty CLASSPATH, then you don't need a CLASSPATH at all. If there is anything else in the CLASSPATH, add .; at the beginning.

The . means current folder. If you have no CLASSPATH set, then Java will look in the current folder anyway.

If that doesn't work, come back and ask again
Holden Cornfield
Greenhorn

Joined: Nov 28, 2012
Posts: 6
Campbell Ritchie wrote:Welcome to JavaRanch

Please don't put your files in the bin folder; leave that for java executables. If you uninstall Java to install a new version, your work will all vanish.
Create a new folder. If you are using Windows you will probably start in "my documents" when you open the command line.That will create a "java" folder where you happen to be working, move you to that "java" folder, and print its contents. At present there should be nothing there.
Use a text editor (preferably not NotePad, go for Jedit, Notepad++ or Notepad2 which can all be downloaded free) and save the .java file in that same java folder. Write dir again at the command line, then try compiling withIf that works, you need to go back and edit your CLASSPATH. Don't put your Java bin folder in the CLASSPATH. Delete it. If you have an empty CLASSPATH, then you don't need a CLASSPATH at all. If there is anything else in the CLASSPATH, add .; at the beginning.

The . means current folder. If you have no CLASSPATH set, then Java will look in the current folder anyway.

If that doesn't work, come back and ask again


Hello, I am also a beginner to Java (and to programming as a whole).

I am facing a similar problem:

I have installed JDK onto my computer and typed up code.
I set the PATH variable to C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0_09\bin

So now JDK compiles my program without any problem.
But I cannot find the class file anywhere on the computer.
And when I try to run my program, JDK/JRE says the class cannot be found.

I have followed all of your advice until compiling with
javac -cp . MyFile.java
which worked.

But CLASSPATH is nowhere to be found in the list of environment variables \ system variables.
Which according to you is not a problem.

What is the problem? How do I modify where class files are saved?

Thanks for your help!

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18712
    
  40

Holden Cornfield wrote:Hello, I am also a beginner to Java (and to programming as a whole).

I am facing a similar problem:

I have installed JDK onto my computer and typed up code.
I set the PATH variable to C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0_09\bin

So now JDK compiles my program without any problem.
But I cannot find the class file anywhere on the computer.
And when I try to run my program, JDK/JRE says the class cannot be found.

I have followed all of your advice until compiling with
javac -cp . MyFile.java
which worked.

But CLASSPATH is nowhere to be found in the list of environment variables \ system variables.
Which according to you is not a problem.

What is the problem? How do I modify where class files are saved?

Thanks for your help!



Well, from the way you compiled it, the classpath is the current directory. And the location of where the classes will be placed, is the current directory, plus the subdirectories that matches the package name of your class. So, where the classes are saved depends on the package defined in your java file.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Holden Cornfield
Greenhorn

Joined: Nov 28, 2012
Posts: 6
Henry Wong wrote:
Holden Cornfield wrote:Hello, I am also a beginner to Java (and to programming as a whole).

I am facing a similar problem:

I have installed JDK onto my computer and typed up code.
I set the PATH variable to C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0_09\bin

So now JDK compiles my program without any problem.
But I cannot find the class file anywhere on the computer.
And when I try to run my program, JDK/JRE says the class cannot be found.

I have followed all of your advice until compiling with
javac -cp . MyFile.java
which worked.

But CLASSPATH is nowhere to be found in the list of environment variables \ system variables.
Which according to you is not a problem.

What is the problem? How do I modify where class files are saved?

Thanks for your help!



Well, from the way you compiled it, the classpath is the current directory. And the location of where the classes will be placed, is the current directory, plus the subdirectories that matches the package name of your class. So, where the classes are saved depends on the package defined in your java file.

Henry



Hi Henry, thanks for replying so fast.

Well, I believe the current directory is C:\Users\MyName\java because that's what is written on the command prompt.

But when I look into this folder, I cannot find my class file!

So where could it be?

By the way, JRE is running programs without a problem. I really think the problem lies in where these class files are being saved, if they are being saved at all.

Thanks for your help!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.
Holden Cornfield
Greenhorn

Joined: Nov 28, 2012
Posts: 6
Campbell Ritchie wrote:Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.


Thank you Ritchie, this is illuminating!

I get .;C:\Program Files (x68)\Java\jre6\lib\ext\QTJava.zip

Which happens to be the value for a system variable called QTJAVA.

Shall I add ;C:\Users\MyName\java ? That's where I keep my imported java and class files.
Holden Cornfield
Greenhorn

Joined: Nov 28, 2012
Posts: 6
Campbell Ritchie wrote:Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.


Well I did that and it didn't work.

To answer your other questions:

I get C:\Users\MyName\java from the dir command, which is why I suggested changing value for QTJAVA to .;C:\Users\MyName\java (but that has not worked)

As for your last question, I'm not sure what you mean by name inclusion for .java files
The filename for my .java files are ones such as Set.java and Item.java so nothing special.
But perhaps you mean something else?

In any case, echo %CLASSPATH% shows that my classpath is set to something weird.
I included the zip file at address C:\Program Files (x68)\Java\jre6\lib\ext\QTJava.zip in attachment so you can check it out!
From what I've found, there are a bunch of random classes (APIs?) that come from god knows where.
It looks like this file is a library for exterior classes coming from this QTJava variable.
Holden Cornfield
Greenhorn

Joined: Nov 28, 2012
Posts: 6
Holden Cornfield wrote:
Campbell Ritchie wrote:Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.


Well I did that and it didn't work.

To answer your other questions:

I get C:\Users\MyName\java from the dir command, which is why I suggested changing value for QTJAVA to .;C:\Users\MyName\java (but that has not worked)

As for your last question, I'm not sure what you mean by name inclusion for .java files
The filename for my .java files are ones such as Set.java and Item.java so nothing special.
But perhaps you mean something else?

In any case, echo %CLASSPATH% shows that my classpath is set to something weird.
I included the zip file at address C:\Program Files (x68)\Java\jre6\lib\ext\QTJava.zip in attachment so you can check it out!
From what I've found, there are a bunch of random classes (APIs?) that come from god knows where.
It looks like this file is a library for exterior classes coming from this QTJava variable.


woops can't send zip files... sorry!
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Find any file by doing a system search. Listing by "ls" in unix or windows search in Windows. You can find where they are going.
_____________________________
Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib

See if javac in that directory works. (I mean go to current dir in cmd and then enter "javac". Is it responding?)
The dot in the beginning indicates your current directory (where your classfiles reside).

PS. The PATH has the location to binary executable files like java.exe. And the CLASSPATH locates the classes necessary for running Java classes. Normally they are inside .jar files in lib directory inside jdk installation folder.

EDIT: Welcome to the Ranch


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
Rajdeep Biswas wrote: . . . Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib . . .
No, it shouldn’t. That would be a mistake. Some older versions of Java required such a classpath, but those days are long behind us.

Holden Cornfield, take it easy. I was safely in the Land of Nod while you were trying all sorts of things. It can be hazardous to try too many things too quickly. You never know what sort of confusion you get into!
That classpath .;...QTJava.jar tells me that you have installed QuickTime at some time. That is notorious for setting a classpath, which can mess up all your other settings. Adding .; should, however, sort it out. The fact that your programs work when you use the -cp . option and not without makes me suspicious that there is something wrong with that classpath. Is that the system or the user classpath? Is it down as an environment variable called classpath (case‑insensitive in Windows® so might be CLASSPATH)? Does it come up as .;%QTJAVA% or similar anywhere? What happens when you use -cp .;%CLASSPATH% instead of -cp . ?
What I meant about package name is: is the first non‑comment line in the code something like package foo; ? If you have written that (it must be the first part of the .java file), then the name of the .class file will not be MyClass but foo.MyClass.
When you used the dir command inside your java folder (which you have by the way chosen a good location and name for), do the .class files appear? What messages do you get after using the javac instruction? [Normal compilation ≡ no messages at all.] Are there any subfolders inside java?
If you are working inside your java file then having . inside the classpath should sort it out without your adding your java folder to the classpath.
Holden Cornfield
Greenhorn

Joined: Nov 28, 2012
Posts: 6
Campbell Ritchie wrote:
Rajdeep Biswas wrote: . . . Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib . . .
No, it shouldn’t. That would be a mistake. Some older versions of Java required such a classpath, but those days are long behind us.

Holden Cornfield, take it easy. I was safely in the Land of Nod while you were trying all sorts of things. It can be hazardous to try too many things too quickly. You never know what sort of confusion you get into!
That classpath .;...QTJava.jar tells me that you have installed QuickTime at some time. That is notorious for setting a classpath, which can mess up all your other settings. Adding .; should, however, sort it out. The fact that your programs work when you use the -cp . option and not without makes me suspicious that there is something wrong with that classpath. Is that the system or the user classpath? Is it down as an environment variable called classpath (case‑insensitive in Windows® so might be CLASSPATH)? Does it come up as .;%QTJAVA% or similar anywhere? What happens when you use -cp .;%CLASSPATH% instead of -cp . ?
What I meant about package name is: is the first non‑comment line in the code something like package foo; ? If you have written that (it must be the first part of the .java file), then the name of the .class file will not be MyClass but foo.MyClass.
When you used the dir command inside your java folder (which you have by the way chosen a good location and name for), do the .class files appear? What messages do you get after using the javac instruction? [Normal compilation ≡ no messages at all.] Are there any subfolders inside java?
If you are working inside your java file then having . inside the classpath should sort it out without your adding your java folder to the classpath.


Hi everyone!

Woke up this morning, had another go at compiling and running, and lo and behold! Class files are now being created in the appropriate C:\Users\MyName\java file
Thanks a lot for your help, but not really sure what made it succeed... did rebooting the computer come into play?

In any case, thanks a lot for your help Ritchie and Rajdeep. I'm going to be setting up JDK on other computers in the near future, so this thread will come in handy.
Also, it's my first time on a java forum! So thanks for the initation guys

PS: would you still like me to perform the commands which you recommended so that we can understand why things are working now?
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Holden Cornfield wrote:PS: would you still like me to perform the commands which you recommended so that we can understand why things are working now?

Until you play, you can't get your nuances perfect! Anyways, the Internet is at your rescue.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
Possible explanation: you have to close the command window before the new variables take effect. I think it says somewhere in this FAQ that you have to restart the computer on some versions of Windows® for them to take effect (please check). I don’t know whether that is part of the explanation.
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Campbell Ritchie wrote:
Rajdeep Biswas wrote: . . . Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib . . .
No, it shouldn’t. That would be a mistake. Some older versions of Java required such a classpath, but those days are long behind us.

In that case, Mr. Ritchie, how will it find out our class files in any directory where we have compiled the java file? It wont search in current directory!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
I think Campbell was referring to your inclusion of the JDK lib directory. That's definitely not needed.

Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
I was, Joanne. Thank you.
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Alright dear. From which version do you mean its no more required? Is there any registry addition that serves the purpose? Further is there any difference in Windows and Unix for this?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
Rajdeep Biswas wrote: . . . From which version do you mean its no more required?
Don’t know
Is there any registry addition that serves the purpose?
No. It is not necessary
Further is there any difference in Windows and Unix for this?
No. The path would be different, however.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class file not getting created