• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to import

 
kathir chokka
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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 .
 
sheng liang
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you didnt set the environment properly?
 
kathir chokka
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
John Dell'Oso
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Jay Pagnis
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic