Forums Register Login

Problem with Compiling java files in packages

+Pie Number of slices to send: Send
Hello I have a question in Java when compiling with packages. Can anyone Help??
My 2 java files BeerSelect2.java & BeerExpert.java are in packages com.example.web & com.example.model respectively. The root folders goes like this.
C:\MyProjects\beerV1\src\com\example\web\BeerSelect2.java
and
C:\MyProjects\beerV1\src\com\example\model\BeerExpert.java

I have compiled the BeerExpert.java in the model package.(ie the class file for BeerExpert is in the com.example.model package.)

My BeerSelect2 file which is inside the web folder is like this



This shows 3 comile errors.
& the BeerExpert.java file which is in the model folder is like this:

This compiles fine in the model folder.

Now in the above BeerSelect2.java program(Servlet)-- when I'm trying to compile my BeerSelect2.java in the 'web' folder in which I'm trying to import the com.example.model.* ;

ie In the Command Prompt:

C:\MyProjects\beerV1\src\com\example\web>javac BeerSelect2.java
gives 3 errors like this

BeerSelect2.java:3: package com.example.model does not exist
import com.example.model.*
^

BeerSelect2.java:22:cannot find symbol
symbol: class BeerExpert
location: class com.example.web.BeerSelect2.
BeerExpert be=new BeerExpert();
^

BeerSelect2.java:22:cannot find symbol
symbol: class BeerExpert
location: class com.example.web.BeerSelect2.
BeerExpert be=new BeerExpert();


Can anyone help???
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Welcome to the Ranch

Please avoid coloured text, which many find difficult to read. Please use the code button; since you are new I have edited your post and you can see how much better it looks.

Search these fora for "compiling packages" and you will find several old threads about similar problems, which will help you, but the simplest thing to do for a beginner's exercise is to //comment out the package names in all your classes and compile them in a folder, called the "unnamed package."
I'm gonna teach you a lesson! Start by looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1030 times.
Similar Threads
problen in headfirst mvc tutorial
servlet compiling errors
Package doesn't exists - error!!- How to resolve?
Compile error.
Problem in accessing model in diffeerent package(Servlet-HFS)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:38:44.