hi folks,basically i am facing a problem importing a package,

dir structure is like

src
|---com
      |---example
                |---model
                        |---BeerExpert.java




package com.example.model;
import java.util.*;

public class BeerExpert
{
    public List getBrands(String color)
    {
        //code goes here
    }

}





src
|---com
      |---example
                |---web
                      |---BeerSelect.java

now in BeerSelect.java i am importing the BeerSelect class from the model directory

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelect extends HttpServlet
{
    public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
    {
        //code goes here
    }
}

now at the time of compiling the BeerSelect.java,from cmd,by follwing command

e:\JAVA\Beer-v1\javac -classpath D:/tomcat/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java

i am getting error

 src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
    import com.example.model.*;
    ^

plz help

i set the classpath through environment variables,and set the following value

E:\JAVA\JSP\beerV1\src;

but it still gives the error.

src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
    import com.example.model.*;
    ^

plz help...

Edited 4 Years Ago by subhraakasuny: typing mistake

What is the command line you are using? Do you put the path to the src folder in the -classpath option used in the command line?
I don't know if the javac command will use both the environment variable AND the -classpath option's value.

To see what classpath is used by the java program make a small program with this:
System.out.println(System.getProperties().getProperty("java.class.path"));

and execute it with a -classpath option and without to see the difference.

Edited 4 Years Ago by NormR1

@NormR1

my cmd line is:

e:\JAVA\Beer-v1>javac -classpath D:/tomcat/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java

and it gives the error:

src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
    import com.example.model.*;
    ^

and i also set E:\JAVA\JSP\beerV1\src; this path to th CLASSPATH value through environment variables

I don't see the path to the src folder in javac's -classpath option. Try putting it there.

Did you write the small test program and test it the two ways I suggested?
What happened?

Edited 4 Years Ago by NormR1

i already set the path through environment variables

like,

my computer->properties->advanced->environment varibles->classpath->(and here i set the path)

Re-read my past posts.

Did you try putting the path to the src folder on the -classpath option?

@Norm R1

you are saying that i have set the path of the src directory in the -classpath option of the cmd line.

so now my new cmd line is going to be....

E:\JAVA\beerV1>javac E:/JAVA/JSP/beerV1/src D:/tomcat/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java

but it gives th same error

if i'm wrong please make me correct

to set path or classpath:
use following command in prompt

Set path = " path which u wnat to set "

set classpath=" path u want to set "

The posted command line doesn't have the -classpath option. You should get a different error with that command line. For example: javac: invalid flag: E:/JAVA/JSP/beerV1/src
Please copy the full contents of the command window so we can see what has been entered and what the javac program's response was.

To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Edited 4 Years Ago by NormR1

@Norm R1,thnx for ur response

my cmd line is:

E:\JAVA\JSP\beerV1>javac -classpath D:/tomcat/common/lib/servlet-api.jar -d clas
ses src/com/example/web/BeerSelect.java
src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:14: cannot find symbol
symbol  : class BeerExpert
location: class com.example.web.BeerSelect
                BeerExpert be=new BeerExpert();
                ^
src\com\example\web\BeerSelect.java:14: cannot find symbol
symbol  : class BeerExpert
location: class com.example.web.BeerSelect
                BeerExpert be=new BeerExpert();
                                  ^
3 errors

E:\JAVA\JSP\beerV1>

Where is the path to the src folder pointed to by the -classpath option?
You keep leaving that off. You need to have it in the classpath.

What folder is the src folder in? If it is in the beerV1 folder then you only need to add a . to the -classpath you are using:

-classpath D:/tomcat/common/lib/servlet-api.jar;.

Edited 4 Years Ago by NormR1

@Norm R1

can you please write the full cmd line.....

now the value which is set on the classpath is E:\JAVA\JSP\beerV1\src\;

and yes,src folder is in the beerV1 folder

BeerV1
|---src
    |---com
        |---example
            |---model
                |---BeerExpert.java

and BeerSelect.java resides in

BeerV1
|---src
    |---com
        |---example
            |---web
                |---BeerSelect.java

@NormR1

can you please explain the line

"If it is in the beerV1 folder then you only need to add a . to the -classpath you are using:

-classpath D:/tomcat/common/lib/servlet-api.jar;.

"
it will be helpful for me....

This article has been dead for over six months. Start a new discussion instead.