0
votes

I have the following directory layout: The program folder contains java, class, and pack folders and my current location is program/java, which contains a.java and b.java files. Initially class and pack contains nothing.

b.java

package comm.domm;
public class b
{
    public void bFu()
    {
        System.out.println("b function");
    }
}

a.java

package com.dom;
import comm.domm.*;
class a
{
    public static void main(String args[])
    {
        (new b()).bFu();
        System.out.println("Utsab");
    }
}

Now, from program/java issue the following commands

javac -d ../pack b.java
javac -cp ../pack -d ../class a.java

Which creates comm/domm under pack and places b.class in program/pack/comm/domm and creates com/dom under class and places a.class in program/class/com/dom

now from the same current directory I issue,

java -cp ../class;../pack com.dom.a

Which does not work, it can locate a.class but not b.class(b.class is required by a.class, as described in the source code) this time but while compiling a.java using

javac -cp ../pack -d ../class a.java

It could locate b.class and produced a.class, then why b.class is not found when I tried to run a.class?? How it can be found? b.class is found during compilation but not at run time, why??

2
Can you post the exact exception you get? - Sotirios Delimanolis
As it looks like you're running on unix, that should probably be: ../class:../pack (separate with colons, not semicolons). - user1676075
am running on cygwin, that gives unix environment in windows and it takes ; not :. am unable to attach the screen shot, as it's saying "u need @ least 10 reputations!", it could be more clear if i could upload that.... - user1926364
@SotiriosDelimanolis : it's showing me java -help's output, then -bash: ../pack: is a directory. - user1926364

2 Answers

1
votes

Unless this is a typo

javac -cp ../pack -d ../class b.java

You haven't compiled a.java at all. If you have

javac -cp ../pack -d ../class a.java

instead, then it's working for me and prints

b function
Utsab

as expected.

0
votes

my logic was correct, it was a problem with the environment, after changing the environment it worked nicely, with out any change....thanks all