Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Error in compiling java program

Dear all,

     I am a beginner in java. I tried to compile one java program but encounter the following errors:
     error J0051: Undefined package 'servlet'
     error J0051: Undefined package 'http'

     How should I solve it? The compiler i am currently using is microsoft j++ 1.1
     Thank you.

Regards,
eliza
0
elizateh
Asked:
elizateh
  • 3
  • 3
  • 2
  • +3
1 Solution
 
amit_chauhanCommented:
Put servlet.jar in classpath while compiling.
sevlet.jar contains javax.servlet.http package. If its not servlet.jar, then find any other jar that contains it. Still cant find it, then download this from java.sun.com. BTW, this package is now a part of J2SDK1.4. Before that it used to come as a separate jar (as an extension)

Hope that helps
Thanks
Amit
0
 
elizatehAuthor Commented:
Dear amit,

     Thank you for the prompt reply. I have one servlet.jar file in this directory C:\jswdk-1.0.1\lib. So, i include this in the classpath. but the error still remains. What should i do next?

Thank you
0
 
amit_chauhanCommented:
Can you cut-paste the whole exception that you are getting.
Also how you are compiling this file ? from command prompt ? or from the tool itself ?
Also open servlet.jar using winzip and check for the directory javax/servlet/http in the path section. It should be there.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
elizatehAuthor Commented:
Dear amit,

     the following are the exception:

ompiling...
Microsoft (R) Visual J++ Compiler Version 1.01.7022
Copyright (C) Microsoft Corp 1996. All rights reserved.
C:\jswdk-1.0.1\examples\WEB-INF\servlets\HelloWorldKr.java(8,8) : error J0051: Undefined package 'servlet'
C:\jswdk-1.0.1\examples\WEB-INF\servlets\HelloWorldKr.java(9,8) : error J0051: Undefined package 'http'
Error executing jvc.exe.

HelloWorldKr.class - 2 error(s), 0 warning(s)

Line 8 and 9 are:
import javax.servlet.*;
import javax.servlet.http.*;

I am compiling this file from the j++1.1 tool itself

I have opened servlet.jar using powerarchiver and  i did find many class files under the directory javax/servlet/http in the path section.

I have included this servlet.jar in the classpath under the environment variables.  Currently the classpath variable is pointing to:
C:\jdk1.3\lib\tools.jar; C:\jswdk-1.0.1\lib\servlet.jar

Thank you.


0
 
amit_chauhanCommented:
Hi,
Try to compile it from command line by giving explicit classpath:

C:\>javac -classpath %CLASSPATH%;C:\jswdk-1.0.1\lib\servlet.jar HelloWorldKr.java

check if the error still comes.
0
 
Venci75Commented:
put your servlet.jar to the %JAVA_HOME%\lib\ext directory
0
 
kokchoon78Commented:
Hi,

   Visual J++ will use their own JVM called jvc.exe. When your program runs from within the Visual J++ development environment, the VM includes the information entered into the Java Packages tab of Settings dialog box when searching for .class files. Access the Java Packages tab from the Project menu's Settings dialog box.

regards,
Kok Choon.
0
 
girionisCommented:
0
 
ajaycvCommented:
I guess u haven't set ur environment variables properly. May I know which OS u r using VJ++ on?

Ajay.
0
 
ajaycvCommented:
Use this to set the classpath:

On the Project menu, click Properties.
In the Project Properties dialog box, click the CLASSPATH tab.
Click New, and then type the fully-qualified path name for including the servlet.jar file.

Ajay.
0
 
elizatehAuthor Commented:
Thank you very much. It did work! Thank you for the explanation as well. But yet to try to compile it from the tools itself...
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now