Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem with Compiling java files in packages

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch. Please BeForthrightWhenCrossPostingToOtherSites
http://forums.oracle.com/forums/thread.jspa?threadID=1774800
 
Marshal
Posts: 74069
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic