• 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

Not able to import

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you didnt set the environment properly?
 
kathir chokka
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When attempting to compile BeerSelect, it can't find the BeerExpert class. Try adding .\classes to your -classpath when compiling BeerSelect.

Regards,
JD
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic