Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile IMPORT PACKAGE file COMMAND PROMPT

 
Rohit Savant
Greenhorn
Posts: 21
Fedora Java ME Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rohit Savant
Greenhorn
Posts: 21
Fedora Java ME Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic