• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class file not getting created

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Holden Cornfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Campbell was referring to your inclusion of the JDK lib directory. That's definitely not needed.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was, Joanne. Thank you.
 
Rajdeep Biswas
Ranch Hand
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Super Old thread here.  I'm crossing my fingers that someone has visibility on this.  Only been programming training for about a year.  Started off with Python but now I am in love with JAVA.  This classpath is stressing me out.  I was lucky to have the .class file automatically made the first time I tried to run a test java file, and when I tried to replicate my findings, the .class file is no where to be found.  I'm used to using Atom or IntelliJ with built in terminals.  I figure I need to learn how to use the cmd.  I'm impatient and eager to learn.  Anyone who is willing to help this young programmer advance, just know, I will pay for your time.

disregard.  I found it out.  Happy Coding!!!
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

What have you done with a CLASSPATH variable? As a beginner, you are unlikely to need to set a CLASSPATH, and setting a system CLASSPATH usually causes much more trouble than it is worth.
 
reply
    Bookmark Topic Watch Topic
  • New Topic