• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Package does not exist

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All...as i am new member i don't know where to post this particular post. Kindly accept my apologies if posted in a wrong forum.

I am working on Tomcat 5.5 and Java SE 5.0. I am working on servlets.

I do have a servlet file at the following directory. this is not a tomcat directory, but a simple directory as shown :

NO 1: C:\myproject\beerV1\src\com\example\web ..
Over here at Web i have servlet file by name BeerSelect.java. The package name give in this servlet file is "package com.example.web" (excluding the double quotes).

Now, i have another servlet program , a src file and a .class file at the following path..

NO 2: C:\myproject\beerV1\src\com\example\model

The problem i am facing is when i go to compile the Servlet file from the path as shown in the first path (No 1) my servlet is not being compiled and i get the following error..

BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
BeerSelect.java:19: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
BeerSelect.java:19: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors

As far as my knowledge goes the package path is correct as described in the NO 1 and N0 2 above.

Please help me out of this..

thank you.


This is a sample code from Head First Servlet and JSP, chapter 3 page 84.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to make sure that the directory C:\myproject\beerV1\src\ is in your classpath. The easiest way to do that is to navigate to C:\myproject\beerV1\src\ and compile/run your classes from there:
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i have the same problem. i have tried what ever you have said but it did not work. so please tell me the following solution.
my program is

package folder1;
public class CalledProgram
{
public void calledProgramFunction()
{
System.out.println("we are in CalledProgramFunction");
}
}

package folder2;
import folder1.CalledProgram;
public class CallingProgram
{
public void callingProgramFunction()
{
System.out.println("we are in callingProgramFunction");
CalledProgram cp1=new CalledProgram();
cp1.calledProgramFunction();
}
public static void main(String args[])
{
CallingProgram cp=new CallingProgram();
cp.callingProgramFunction();
}
}

C:\scjp_practice\chapter1\accessmodifiers>javac folder2\CallingProgram.java
folder2\CallingProgram.java:2: error: package folder1 does not exist
import folder1.CalledProgram;
^
folder2\CallingProgram.java:8: error: cannot find symbol
CalledProgram cp1=new CalledProgram();
^
symbol: class CalledProgram
location: class CallingProgram
folder2\CallingProgram.java:8: error: cannot find symbol
CalledProgram cp1=new CalledProgram();
^
symbol: class CalledProgram
location: class CallingProgram
3 errors

 
bhargav reddy vempalli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i tried to use -cp . it worked to compile but it is not executing. please tell me how to fix this issue
C:\scjp_practice\chapter1\accessmodifiers>javac -cp . folder2\CallingProgram.jav
a

C:\scjp_practice\chapter1\accessmodifiers>javac -cp . folder2\CallingProgram
javac: invalid flag: folder2\CallingProgram
Usage: javac <options> <source files>
use -help for a list of possible options

C:\scjp_practice\chapter1\accessmodifiers>java -cp . folder2\CallingProgram
Exception in thread "main" java.lang.NoClassDefFoundError: folder2\CallingProgra
m (wrong name: folder2/CallingProgram)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)


C:\scjp_practice\chapter1\accessmodifiers>cd folder3
The system cannot find the path specified.

C:\scjp_practice\chapter1\accessmodifiers>cd folder2

C:\scjp_practice\chapter1\accessmodifiers\folder2>java -cp . CallingProgram
Exception in thread "main" java.lang.NoClassDefFoundError: CallingProgram (wrong
name: folder2/CallingProgram)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)


C:\scjp_practice\chapter1\accessmodifiers\folder2>java CallingProgram
Error: Could not find or load main class CallingProgram
 
bhargav reddy vempalli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it got resolved by using -cp .

C:\scjp_practice\chapter1\accessmodifiers>java -cp . folder2.CallingProgram
we are in callingProgramFunction
we are in CalledProgramFunction
 
Marshal
Posts: 78709
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That Beer Expert application is supposed to be a beginner’s exercise. Delete the package names and import declarations and put everything into one folder which you use as the unnamed package.
 
bhargav reddy vempalli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you are true but i want to learn packages and access modifiers that is the reason i am using packages.
 
Campbell Ritchie
Marshal
Posts: 78709
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start here.
 
Greenhorn
Posts: 3
MySQL Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I made that working. You have to add your ../model in your classpath and compile with "-cp" option instead of "-d". In my case it successfully worked.
 
Campbell Ritchie
Marshal
Posts: 78709
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Arvind Das
 
Arvind Das
Greenhorn
Posts: 3
MySQL Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch Arvind Das


Thank You Sir Ritchie Its a place where I can find all of my solutions.
Proud to be a part of it.
I have one question in mind. If I want to upload my this sample web-app on Github. Will that work? I tried it. It shows only index.html content and nothing else If i perform any action on my index.html page. Or I will have to build it. Any solutions there?
 
Campbell Ritchie
Marshal
Posts: 78709
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aman Adhikari,
Your post was moved to a new topic.
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sammer khazi, try this:
javac -classpath c:\tomcat\lib\servlet-api.jar;classes -d classes src/com/example/web/BeerSelect.java
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Igor Dziuba wrote:sammer khazi, try this:
javac -classpath c:\tomcat\lib\servlet-api.jar;classes -d classes src/com/example/web/BeerSelect.java



This has worked for me. Thanks Igor.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Somnath Guha
 
A timing clock, fuse wire, high explosives and a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic