Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Not able to import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not able to import" Watch "Not able to import" New topic
Author

Not able to import

kathir chokka
Greenhorn

Joined: Dec 23, 2007
Posts: 5
Am having directory structure like this and files:

beerV1\src\com\example\web\BeerSelect.java
beerV1\src\com\example\model\BeerExpert.java
beerv1\classes

BeerExpert.java

package com.example.model;
import java.util.*;
public class BeerExpert {
public String getBrands() {
String suc="sucess";
return suc ;
}
}

BeerSelect.java

package com.example.web;
import com.example.model.*;//IMPORTING
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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
BeerExpert Beertype = new BeerExpert();
String brands=Beertype.getBrands();
out.print(brands);
}
}

Oncompilng:

c:\Allfiles\Programs\java\MyProjects\beerV1>javac -classpath C:\apache-tomcat-5.5.25\common\lib\servlet-api.jar -d classes src\com\example\model\BeerExpert.java

c:\Allfiles\Programs\java\MyProjects\beerV1>

And i get expected directory structure created:

beerV1\classes\com\example\model\BeerExpert.class

oncompiling

c:\Allfiles\Programs\java\MyProjects\beerV1>javac -classpath C:\apache-tomcat-5.5.25\common\lib\servlet-api.jar -d classes 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:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert Beertype = new BeerExpert();
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert Beertype = new BeerExpert();
^
3 errors

Am not able to find where am wrong but the package was present .
sheng liang
Greenhorn

Joined: May 03, 2007
Posts: 11
Maybe you didnt set the environment properly?
kathir chokka
Greenhorn

Joined: Dec 23, 2007
Posts: 5
I have set the envionmental varaibles properly

since it works for the first program. while compiling the second program which tries imports the first one am facing the problem
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
When attempting to compile BeerSelect, it can't find the BeerExpert class. Try adding .\classes to your -classpath when compiling BeerSelect.

Regards,
JD
Jay Pagnis
Greenhorn

Joined: Dec 04, 2007
Posts: 2
try this command:

javac -classpath D:\apache-tomcat-5.5.23\common\lib\servlet-api.jar<b>;classes</b> -d classes src\com\example\web\BeerSelect.java

If you notice, I have emphasized the part that I have added .i.e. classes folder in your classpath. Java doesnt assume the classpath by default. You need to explicitly mention the same.

Hence in this case, adding the folder in which the BeerExpert.class is residing, is mandatory.
 
Consider Paul's rocket mass heater.
 
subject: Not able to import