• 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

Compile IMPORT PACKAGE file COMMAND PROMPT

 
Greenhorn
Posts: 21
Java ME Oracle Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 192
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Java ME Oracle Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic