| | |
What is the function of "-d ." command?
Thread Solved |
The program is given at the bottom
To compile java programs in the command prompt I use the following command:
C:\jtemp\MyPack>javac AccountBalance.java -d .
Only then are the classes compiled and I am able to run the main() function. When I execute the above command a folder "MyPack" is created inside the pre-existing MyPack folder. It contains the 2 classes specified in the program.
Then to execute the compiled program I use the following command:
C:\jtemp\MyPack>java MyPack.AccountBalance
No doubt the program succeeds and prints the expected lines.
Now that's fair enough. The reason I am writing this thread is that I am unable to understand the true significance of the "-d ." command. If I try to compile the classes without it, firstly no folder is created inside the pre-existing folder "MyPack" and secondly the following commands yield a "NoClassDefFoundError". Please note that the classes are still compiled and appear just besides the .java file in the window. It is just that they do not execute successfully this time.
C:\jtemp\MyPack>java MyPack.AccountBalance
C:\jtemp\MyPack>java AccountBalance
I know it has got something to do with the "Classpath" variable but even after reading about it, it's still Greek and Latin to me.
Please help. The Program is stored at the address "C:\jtemp\MyPack>" on my hard-disk, has the name "AccountBalance.java" and is as follows:
To compile java programs in the command prompt I use the following command:
C:\jtemp\MyPack>javac AccountBalance.java -d .
Only then are the classes compiled and I am able to run the main() function. When I execute the above command a folder "MyPack" is created inside the pre-existing MyPack folder. It contains the 2 classes specified in the program.
Then to execute the compiled program I use the following command:
C:\jtemp\MyPack>java MyPack.AccountBalance
No doubt the program succeeds and prints the expected lines.
Now that's fair enough. The reason I am writing this thread is that I am unable to understand the true significance of the "-d ." command. If I try to compile the classes without it, firstly no folder is created inside the pre-existing folder "MyPack" and secondly the following commands yield a "NoClassDefFoundError". Please note that the classes are still compiled and appear just besides the .java file in the window. It is just that they do not execute successfully this time.
C:\jtemp\MyPack>java MyPack.AccountBalance
C:\jtemp\MyPack>java AccountBalance
I know it has got something to do with the "Classpath" variable but even after reading about it, it's still Greek and Latin to me.
Please help. The Program is stored at the address "C:\jtemp\MyPack>" on my hard-disk, has the name "AccountBalance.java" and is as follows:
Java Syntax (Toggle Plain Text)
package MyPack; /** * * @author Shashank Sawant */ class Balance { String name; double bal; Balance(String n, double b){ name = n; bal = b; } void show(){ if(bal<0) System.out.print("->"); System.out.println(name + ":$" + bal); } } class AccountBalance { public static void main (String args[]){ Balance current[]=new Balance[3]; current[0]=new Balance("K. J. Fielding",123.23); current[1]=new Balance("Will Tell",157.02); current[2]=new Balance("Tom Jackson",-12.23); for(int i=0;i<3;i++) current[i].show(); } }
If your program file has package statement then all these classes defined inside the file must be stored into package name folder.
Example in above post:
statement creates a folder MyPack in current directory (. with command line) and both Balance.class and AccountBalance.class files are placed into MyPack folder.
Run - JVM launch AccountBalance class from file system folder MyPack.
If you want to store compiled classes in another folder other that current directory.
Example in above post:
Java Syntax (Toggle Plain Text)
>javac AccountBalance.java -d .
Run - JVM launch AccountBalance class from file system folder MyPack.
Java Syntax (Toggle Plain Text)
>java MyPack.AccountBalance
If you want to store compiled classes in another folder other that current directory.
Java Syntax (Toggle Plain Text)
>javac AccountBalance.java -d c:\test
Last edited by adatapost; Jul 5th, 2009 at 1:59 am.
Failure is not fatal, but failure to change might be. - John Wooden
•
•
•
•
If your program file has package statement then all these classes defined inside the file must be stored into package name folder.
Example in above post:
statement creates a folder MyPack in current directory (. with command line) and both Balance.class and AccountBalance.class files are placed into MyPack folder.Java Syntax (Toggle Plain Text)
>javac AccountBalance.java -d .
Run - JVM launch AccountBalance class from file system folder MyPack.
Java Syntax (Toggle Plain Text)
>java MyPack.AccountBalance
If you want to store compiled classes in another folder other that current directory.
Java Syntax (Toggle Plain Text)
>java AccountBalance.java -d c:\test
I did that. Actually to be exact I did the following thing:
c:\jtemp\mypack>javac AccountBalance.java -d c:\jtemp\adat
As expected a folder "MyPack" was created inside the "adat folder.
For confirmation this is the address of the folder I am talking about:
c:\jtemp\adat\mypack>
Also, as per expectations, it has the 2 class files.
Now this is where my usual problem begins. The problem I can't get around no matter what I try; the problem who's answer is what I am seeking on the internet.
How should I execute these class files? Every attempt I make yields the result "NoClassDefFoundError".
Please help. These are the ways I have attempted to execute the classes:
1. c:\jtemp\adat\mypack>java MyPack.AccountBalance
2. c:\jtemp\adat\mypack>java .AccountBalance
3. c:\jtemp\adat>java MyPack.AccountBalance
4. c:\jtemp\adat>java AccountBalance
All result in the same error. It is not the compilation, or the place where the class files get stored is the issue. The issue is how do I run the class files? I know only one way - and I must thank you (adatapost) for that respite - but that method is too restricted. This only method is what I have given in my first post. But when I change the location where the classes are finally compiled, I can't run them.
Please help!
Regards,
-sgsawant
Thanks,
I have correct that.
See,
.class files are copied at MyPack under c:\pqr folder.
Use -classpath or -cp swith with java launcher
or
I have correct that.
See,
Java Syntax (Toggle Plain Text)
c:\xyz>javac AccountBalanace.java -d c:\pqr
Use -classpath or -cp swith with java launcher
Java Syntax (Toggle Plain Text)
c:\xyz>java -cp c:\pqr MyPack.AccountBalance
or
Java Syntax (Toggle Plain Text)
c:\pqr>java MyPack.AccountBalance
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Mar 2009
Posts: 16
Reputation:
Solved Threads: 9
•
•
•
•
The program is given at the bottom
To compile java programs in the command prompt I use the following command:
C:\jtemp\MyPack>javac AccountBalance.java -d .
Only then are the classes compiled and I am able to run the main() function. When I execute the above command a folder "MyPack" is created inside the pre-existing MyPack folder. It contains the 2 classes specified in the program.
Then to execute the compiled program I use the following command:
C:\jtemp\MyPack>java MyPack.AccountBalance
No doubt the program succeeds and prints the expected lines.
Now that's fair enough. The reason I am writing this thread is that I am unable to understand the true significance of the "-d ." command. If I try to compile the classes without it, firstly no folder is created inside the pre-existing folder "MyPack" and secondly the following commands yield a "NoClassDefFoundError". Please note that the classes are still compiled and appear just besides the .java file in the window. It is just that they do not execute successfully this time.
C:\jtemp\MyPack>java MyPack.AccountBalance
C:\jtemp\MyPack>java AccountBalance
I know it has got something to do with the "Classpath" variable but even after reading about it, it's still Greek and Latin to me.
Please help. The Program is stored at the address "C:\jtemp\MyPack>" on my hard-disk, has the name "AccountBalance.java" and is as follows:
Java Syntax (Toggle Plain Text)
package MyPack; /** * * @author Shashank Sawant */ class Balance { String name; double bal; Balance(String n, double b){ name = n; bal = b; } void show(){ if(bal<0) System.out.print("->"); System.out.println(name + ":$" + bal); } } class AccountBalance { public static void main (String args[]){ Balance current[]=new Balance[3]; current[0]=new Balance("K. J. Fielding",123.23); current[1]=new Balance("Will Tell",157.02); current[2]=new Balance("Tom Jackson",-12.23); for(int i=0;i<3;i++) current[i].show(); } }
-d stands for deprecated. That means, some of the functions/features which were used in the earlier versions of java and not included in the newer versions. You might be using some of those functionalities or features. That's why you're getting such an error. So when you compile you've to use -d. The syntax actually is javac -d Sample.java
•
•
•
•
Thanks,
I have correct that.
See,
.class files are copied at MyPack under c:\pqr folder.Java Syntax (Toggle Plain Text)
c:\xyz>javac AccountBalanace.java -d c:\pqr
Use -classpath or -cp swith with java launcher
Java Syntax (Toggle Plain Text)
c:\xyz>java -cp c:\pqr MyPack.AccountBalance
or
Java Syntax (Toggle Plain Text)
c:\pqr>java MyPack.AccountBalance
The instruction to change the classpath works and executes the program. Even though after entering the directory where MyPack folder (containing the classes) is stored, the command
C:\jtemp\adat>java MyPack.AccountBalance
doesn't work. (refer the attachment)
Nevertheless my problem has been solved. Perhaps the classpath variable is locked by default and explicit instruction is necessary on my machine (just a guess).
Thanks to everyone, esp. adatapost!
Regards,
-sgsawant
![]() |
Similar Threads
- What is the function to recognize 8 & 9 as "8" & "9"? (HTML and CSS)
- The "gets" command with Borland C++ (C++)
- google "keyword" question (Search Engine Optimization)
- I am unable to open the "Help" function in IE 6 Print Preview! (Web Browsers)
- Keyboard function key "locked" but only in Windows (USB Devices and other Peripherals)
- "HELP" RUNNING MSDOS COMMAND ON VB (Visual Basic 4 / 5 / 6)
- "preg_match" For What purpose this command use? (PHP)
- loop in main function to an "if" statement (C++)
Other Threads in the Java Forum
- Previous Thread: Trouble with area
- Next Thread: Question of application implementation
| Thread Tools | Search this Thread |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres integer intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans openjavafx parameter php problem program programming project recursion repositories scanner scrollbar sell server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows






