• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

classpath setting--Held up

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have just started reading classpath setting stuff and I am totally held up with the following scenario in setting classpaths during compilation/run.

I have the following folder structure:
C:\
|
|
----Prg

The Prg folder contains two more folders:
(1) com10 (contains test2.java)
(2) com11 (contains test1.java)

The file contents are:





I am able to succesfully compile test2.java (its direct compilation)

What class paths do I need to set in javac and java to get test1.java compiling and running? And, from which folder path do I need to run those commands? I am a Windows user.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your 1st package is package com10;and 2nd you imported Prg.com10.*;
it should be imported com10.*;
and in command line suppose you are in the c:\)
javac -cp Prg Prg\com11\test1.java
java -cp Prg com11.test1
 
Rekha Srinath
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it works Long Meng..

But, I am not clear on how we need to determine what should go into the import statements when there are subpackages also. What is the directory structure we need to follow?

For example, I further created the following packages under com10:
(1) TestPkg under com10
(2) Internal under TestPkg; Internal contains test3.java.

Now, if I want to instantiate test3.java inside my original test1.java, what should be my import statements and classpath settings? I tried some of the options based on what I understood, but I get errors like "package TestPkg.Internal does not exist"
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your package statement in the new class should be

package com10.TestPkg.Internal;

then your import statement in the test1 class should be

import com10.TestPkg.Internal.test3;

when you say this the compiler looks for for the structure com10\TestPkg\Internal

and there it finds the file test3.class

this should work.
 
Rajasekhar Devi Reddy
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should work with the same javac and java commands as listed in the reply above if you are working from c:\
 
Rekha Srinath
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes...It works.. Thanks Long Meng and Rajasekhar !!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic