wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compile IMPORT PACKAGE file COMMAND PROMPT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compile IMPORT PACKAGE file COMMAND PROMPT" Watch "Compile IMPORT PACKAGE file COMMAND PROMPT" New topic
Author

Compile IMPORT PACKAGE file COMMAND PROMPT

Rohit Savant
Greenhorn

Joined: Oct 30, 2012
Posts: 15

1st class


2nd class


compiling with javac -d ../.. bin A.java




Want to compile 2nd class in command prompt. Want Command.I think it as something to do with classpath(Windows/Linux)

I have put pk1 and pk2 in src folder
and want to compile them in bin folder outside src.

ty for help
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Welcome to Javaranch

The import statement in the class A seems wrong - import pk2.B;. The B class is in pk1 not pk2.

What did you try to compile it from command prompt? Did it give any error?
Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 175
Welcome to the ranch Rohit.

Firstly I think you have a typo in your 2nd class:



You can use the -cp or -classpath command to compile and run the program.

How to do this depends on the file directories your calsses reside in, but here is an example:



Compile class in directory c:\_APIContents normally

Now let's test it, the following class is in c:\_APIContents2 and is compiled and run from c:\_APIContents2



We can use the -classpath option, (shorthand version is -cp), to tell the compiler where to find any dependencies we need to compile our TestATestPackage test class.
Save and compile the TestATestPackage test class in directory c:\_APIContents2 using the following command:



What the above command is saying is compile the TestATestPackage class and look for any dependencies in subdirectories of c:\

We also have to let the intepreter know where our package is and the following typed on the command line will do this:



What the above command is saying is run the TestATestPackage class from package _APIContents2 which is within a subdirectory of the c:\ drive.
Notice how we use dot notation to qualify the TestATestPackage class within the _APIContents2 package, just as you would use it within a java class.


Java5 Tutorials | Java6 Tutorials | HTML/CSS Tutorials | JavaScript and jQuery Tutorials
Rohit Savant
Greenhorn

Joined: Oct 30, 2012
Posts: 15

sorry for late reply. Didnt get time because of exams
import pk2.B;
sorry this was my typing mistake here.. actually i did it correctly in my prog.

i made the changes. the prog runs now just fine. thankyou all..!!

THANKYOU for help
 
jQuery in Action, 2nd edition
 
subject: Compile IMPORT PACKAGE file COMMAND PROMPT
 
Similar Threads
Extends will invoke constructor?
private constructors
Output of the Program
protected access
why this doesn't work on java 1.4?