How to compile java servlet
this the error i encounter.. i have read some of the posted topics on it but i dont understand how i can create my own classpath..where should i do that..what should i write...how i have to save it...pls help me...
C:\currentyaazmin1\java>javac login2.java
login2.java:9: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
^
login2.java:11: Package javax.servlet not found in import.
import javax.servlet.*;
^
login2.java:16: Superclass HttpServlet of class login2 not found.
public class login2 extends HttpServlet
^
3 errors
i have already installed jdk1.3 an jsdk2.1...i also copied javax folder from jsdk2.1 and pasted in c:....still i encouter the same thing... pls help
Download j2ee is recommended to solve any compling such as servlets and swing
http://java.sun.com/j2ee/download.html
Once done all you do is include j2ee.jar and you have xml, servlets, rmi the works!! :)
However since you download the servelet component only, search in you hard drive for ".jar" file.
You can open the .jar file with a WinZip and you can check if it as javax.servlet.http.* by looking at the far right for javax/servlet/http
Once you know the jar file to include. Next is to put it in the classpath. The most simple way using NT example, how Windows 95/98 is similar. Go to:
Control Panel -> Double Click on System -> Click on Environment tab
Type below in Variable: CLASSPATH
Type in Value: PATH TO SERVLET;.;
Don't forget the ;.; (the dot for currnet path to run)
If you need to add more to the classpath, seperate by classpath.
Log off and log back in as your user. No need to reset the machine.
The system will pick the new CLASSPATH.
Test on dos as "echo %CLASSPATH%" to see what its set to.
Similar Messages
-
How to compile java to exe by JDeveloper?
How to compile java to exe by JDeveloper?
You used to be able to use exegen to generate stand alone executables for Windows, but this no longer works in later versions of Windows. It works for Windows 98 and NT. For example
exegen/main:schedserv /out:sched.exe schedserv.class scheduler.class
will generate the executable sched.exe from the two class files.
Probably MicroSoft decided to make life a bit harder for Java users. -
Compiling Java Servlet with Depricated Methods
I have a problem of compiling Java servlets that contain depricated methods. If you compile against modern version of servlet.jar I see depricated methods error messages and if I use a very old servlet.jar it cannot find newer methods. What is is the best solution in this case?
Thank you,
Boris.The best thing to do would be compile your code with the -depreciated option to find which methods have been depreciated and the refactor your code to remove them.
The next best thing is to ignore the messages (they are warnings not errors) and your code should still work -
I am trying to compile a servlet using the import javax.servlet.*;
import javax.servlet.http.*; packages. But the only thing I keep getting is :
BasicServlet.java:1: package javax.servlet does not exist
import javax.servlet.*;
^
BasicServlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
BasicServlet.java:6: cannot resolve symbol
symbol : class HttpServlet
location: class BasicServlet
public class BasicServlet extends HttpServlet
I have included the servletapi2_1_1-win package from the sun site containing the servlet.jar in my classpath. Still it refuses to compile. Besides does anybody know how to compile using the servlet packages available in Tomcat or j2ee, both of which I have on my machine , but can't figure what to include.
Please help.
^have you actually included the servlet.jar file in your classpath or just the directory, as you need to explicity declare jar files in the classpath...
javac -classpath %CLASSPATH%;C:\[servlet-jar-path]\servlet.jar Servlet.class -
How to Compile/Run servlet in Tomcat 4.1
Hi All,
iam trying to compile my servlet program in tomcat4.1.. but its showing an error
in the import statement..
UN SOLVABLE SYMBOL... but the import ststement is correct...
can any one help ... is there i have to set any path for compiling/running the servlet...
Thanks in Advicehi thanks for your reply
i have loaded tomcat4.1 exe -- for windows i am starting the tomcat server by clicking from the start menu..
i dint set any env variable .. tell me how to set...
regards
ijay -
How to compile Java files using Ant in Eclipse
Hi All ,
I would like to compile all Java files using Ant in Eclipse.Since am very new to Ant and Eclipse can someone help me to create a build.xml file and let me know how to compile all the java files.
For ex , I have placed my java files inside the path C:\HEC\Terab.Initially the Terab folder holds 7 jar files which i had decompiled using JD compiler and placed the unzipped 7 folders (which contains the java files ).Now i have imported the HEC project into Eclipse using New ->Project ->Java Project.after importig it throwed me an error saying missing jar files.again i copied the jar files and placed inside Terab folder with other 7 folder.
Now How i can compile the java files and convert in to class files.Then after compiling the files i will again need to jar all the 7 folder.
Please tell me the steps i need to follow.How to write an build.xml file ? where i should keep it ? only one build.xml file is enough or should i write 7 build.xml file for each folder ? Please help me out...
Thanks & Regards
Kar1983put it another way, what I am trying to do is to compile David Brackeen's ch 18 code from his book. The java sourse files can be downloaded here:
http://www.brackeen.com/javagamebook/
my question is that how would I complie all of these file so that I can get the program in ch18src\src\com\brackeen\javagamebook\test\ to run? -
Java6: How to compile java using JavaCompiler class
Hi all,
Using JavaCompiler, we can run the java program thru programmaticaly using run() method.
Could anyone please tell me how to compile a java program using JavaCompailer class? Or calling run() itself will compile java file?
Thanks
Shagilimport spoon.support.input.SpoonInputStream;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Enter;
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.comp.Todo;
import com.sun.tools.javac.tree.Tree;
import com.sun.tools.javac.tree.Tree.ClassDef;
import com.sun.tools.javac.tree.Tree.TopLevel;
import com.sun.tools.javac.util.Abort;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Name;
* The Spoon compiler (uses javac).
public class SpoonCompiler extends com.sun.tools.javac.main.JavaCompiler {
Attr attr;
Enter enter;
boolean hasBeenUsed = false;
Log log;
Todo todo;
public SpoonCompiler(Context arg0) {
super(arg0);
enter = Enter.instance(arg0);
todo = Todo.instance(arg0);
log = Log.instance(arg0);
attr = Attr.instance(arg0);
sourceOutput=true;
* Main method: compile a list of files, return all compiled classes
* @param filenames
* The names of all files to be compiled.
@SuppressWarnings("unused")
public List<Tree> parseAndAttribute(List<SpoonInputStream> filenames)
throws Throwable {
// as a JavaCompiler can only be used once, throw an exception if
// it has been used before.
assert !hasBeenUsed : "attempt to reuse JavaCompiler";
hasBeenUsed = true;
long msec = System.currentTimeMillis();
ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
try {
// parse all files
ListBuffer<Tree> trees = new ListBuffer<Tree>();
for (List<SpoonInputStream> l = filenames; l.nonEmpty(); l = l.tail) {
trees.append(parse(l.head.getFileName(),l.head.getStream()));
// enter symbols for all files
List<Tree> roots = trees.toList();
if (errorCount() == 0)
enter.main(roots);
// If generating source, remember the classes declared in
// the original compilation units listed on the command line.
List<ClassDef> rootClasses = null;
if (sourceOutput || stubOutput) {
ListBuffer<ClassDef> cdefs = new ListBuffer<ClassDef>();
for (List<Tree> l = roots; l.nonEmpty(); l = l.tail) {
for (List<Tree> defs = ((TopLevel) l.head).defs; defs
.nonEmpty(); defs = defs.tail) {
if (defs.head instanceof ClassDef)
cdefs.append((ClassDef) defs.head);
rootClasses = cdefs.toList();
while (todo.nonEmpty()) {
Env<AttrContext> env = todo.next();
// save tree prior to rewriting
Tree untranslated = env.tree;
// attribution phase
if (verbose)
printVerbose("checking.attribution", env.enclClass.sym);
Name prev = log.useSource(env.enclClass.sym.sourcefile);
attr.attribClass(env.tree.pos, env.enclClass.sym);
return trees.toList();
} catch (Abort ex) {
ex.printStackTrace();
if (verbose)
printVerbose("total", Long.toString(System.currentTimeMillis()
- msec));
int errCount = errorCount();
if (errCount == 1)
printerCount("error", errCount);
else
printerCount("error.plural", errCount);
if (log.nwarnings == 1)
printerCount("warn", log.nwarnings);
else
printerCount("warn.plural", log.nwarnings);
return null;
private void printerCount(String str, int val) {
System.err.println(str + " - " + val);
private void printVerbose(String arg0, Object obj) {
System.out.println(arg0 + " - " + obj.toString());
--- NEW FILE: CtBuilder.java ---
package spoon.support.builder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
import spoon.query.Query;
import spoon.query.TypeFilter;
import spoon.reflect.CtFactory;
import spoon.reflect.code.BinaryOperatorKind;
import spoon.reflect.code.CtAbstractInvocation;
import spoon.reflect.code.CtArrayAccess;
import spoon.reflect.code.CtAssert;
import spoon.reflect.code.CtAssignment;
import spoon.reflect.code.CtBinaryOperator;
[...1760 lines suppressed...]
var.setSimpleName(tree.sym.name.toString());
var.setModifiers(getModifiers(tree.mods.flags));
enter(var, tree);
scan(tree.init);
exit(var, tree);
@Override
public void visitWhileLoop(WhileLoop tree) {
CtWhile whileLoop = new CtWhileImpl();
enter(whileLoop, tree);
builderContext.loopParameter = 1;
scan(tree.cond);
builderContext.loopParameter = 0;
scan(tree.body);
exit(whileLoop, tree);
} -
How to compile .java to .class in .jar file
Hey. I have code to make a .jar file, read .java files, and save them as .class files in the .jar file. When I open the .jar file, it says that the magic numbers on the classes are wrong. So I figured that Java must compile the .java files to .class files in bytecode.
Question: What's the code to compile a string from a .java file to a .class file?
Here's my code:
try {
// Name of jar file to write
String archiveFile = Name + ".jar";
Manifest jman = new Manifest();
try {
// Create a manifest from a file
//InputStream fis = new FileInputStream("manifestfile");
//Manifest manifest = new Manifest(fis);
// Construct a string version of a manifest
StringBuffer sbuf = new StringBuffer();
sbuf.append("Manifest-Version: 1.0\n");
sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
sbuf.append("Main-Class: Main\n");
sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
// Convert the string to a input stream
InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
// Create the manifest
jman = new Manifest(is);
} catch (IOException e) {
FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
JarOutputStream out = new JarOutputStream(stream, jman);
out.putNextEntry(new JarEntry("Main.class"));
StringBuffer sbuf = new StringBuffer();
sbuf.append(readTextFromJar("Main.txt")));
out.write(sbuf.toString().getBytes("UTF-8"));
out.closeEntry();
out.putNextEntry(new JarEntry("MainScreen.class"));
sbuf = new StringBuffer();
sbuf.append(readTextFromJar("MainScreen.txt"));
out.write(sbuf.toString().getBytes("UTF-8"));
out.closeEntry();
out.putNextEntry(new JarEntry("GCanvas.class"));
sbuf = new StringBuffer();
sbuf.append(readTextFromJar("GCanvas.txt"));
out.write(sbuf.toString().getBytes("UTF-8"));
out.closeEntry();
out.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.toString(), "BUG!", JOptionPane.INFORMATION_MESSAGE);
ex.printStackTrace();
}Thanks,
-GandolfSo I'm guessing that none of you guys have the knowledge on how to compile a java application within a java application. I was thinking that it had something to do with javac... but I'm unsure.
If no one can answer the question, could someone point me to an expert who would know?
-Gandolf -
How can make java servlet sent soap message to other java web application
hello,
i want to make simple servlet send soap message to other java web application containing web service????
for example
web application " A " contain web service add two number
java servlet " B " send soap message contain num1 and num2 to A to add them.
how can do this????I tried that but my problem is that the code is so old. At least what I saw. I don't know how old is too old and I'm trying to do things "right." I saw code from 1998, but I don't know if that's still what you do. It might still work, but that doesn't mean it's correct. There's so much out there on Java that so old that half the time I'm not sure what to do because some other technology in J2EE or the latest Java SDK might have come up with a new way to do things. Thanks.
-
Compiling java servlet programs
i have Tomcat 5.0 and SDK 1.5 . I am able to compile java programs. But in servlet programs the compiler is unable to recognize the javax.servlet package(the code below). I have pushed all the JAR files of TOMCAT to the CLASSPATH . But nothing has changed.
javax.servlet.*;
javax.servlet.Http.*;hi,..
javax.servlet.Http.*; should be javax.servlet.http.*; !
even though you have put the jar files in the classpath .. does it point to servlet-api.jar ? if it does.. it should work. Also try out specifing the classpath using the -cp while compiling the servlet program .
--Olakara -
How to run java servlet without using Web.xml?
How to run servlet without using Web.xml? From a book, I know that web.xml descriptor is optional, but the book doesn't tell us how to run java servelet without web.xm descriptor. So how to do that? Thanks a lot.
How to run servlet without using Web.xml?But Tomcat now uses a web.xml for its global server-wide configuration.
If you'd like to invoke a servlet with:
http://host/servlet/ServletName
you have to enable the invoker servlet.
[from an HTML]
<FORM METHOD="POST" ACTION="/servlet/HGrepSearchSJ">
[from resin.conf of Resin Web Server 2.1.12]
<!--
- The "invoker" servlet invokes servlet classes from the URL.
- /examples/basic/servlet/HelloServlet will start the HelloServlet
- class. In general, the invoker should only be used
- for development, not on a deployment server, because it might
- leave open security holes.
-->
<servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
[from TOMCAT5.0.19/conf/web.xml, a global server-wide web.xml file]
<!-- The "invoker" servlet, which executes anonymous servlet classes -->
<!-- that have not been defined in a web.xml file. Traditionally, this -->
<!-- servlet is mapped to URL pattern "/servlet/*", but you can map it -->
<!-- to other patterns as well. The extra path info portion of such a -->
<!-- request must be the fully qualified class name of a Java class that -->
<!-- implements Servlet (or extends HttpServlet), or the servlet name -->
<!-- of an existing servlet definition. This servlet supports the -->
<!-- following initialization parameters (default values are in square -->
<!-- brackets): -->
<!-- -->
<!-- debug Debugging detail level for messages logged -->
<!-- by this servlet. [0] -->
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
---comment out below----------------------------------------------------------
<!-- The mapping for the invoker servlet -->
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
--> -
When compiling the servlet below I get the errors below:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
Exception, IOException
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<Hello Readers>");
out.println("</html>");
out.println("</body>");
Why don't these packages exist?
Thanks!
/usr/java/j2sdk1.4.0/bin/javac HelloServlet.java
HelloServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloServlet.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class HelloServlet
public class HelloServlet extends HttpServlet
^
HelloServlet.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
Exception, IOException
^
HelloServlet.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
Exception, IOException
HelloServlet.java:7: cannot resolve symbol
symbol : class ServletException
location: class HelloServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
Exception, IOException
^
6 errorsThose packages do exists.
You just need to especify the JAR file where they are located in your classpath when compiling.
Those packages are not part of the Java 2 Standard Edition (J2SE). Download the Enterprise Edition SDK (J2EE SDK) and use the servlet.jar when compiling. -
How to call java servlet using webservice in webdynpro abap?
hi all,
we have a requirement to connect to non - sap database through webservices. But they do have a java servlet which has a data to get. please help me in this regard.
Regards,
Murthy.This is not a web dynpro ABAP related question. Please only post questions in this forum that are directly related to Web Dynpro ABAP.
-
How to compile java programs in j2EE 1.4 SDK
hi,
i HAVE JUST INSTALLED NEW J2EE 1.4 SDK , IT HAS BEED INSTALLED SUCCESFULLY BUT I AM UNABLE TO COMPILE JAVA PROGRAMS WHICH I USED TO RUN IN SDK 1.4 ,OR EVEN NEW WRITTEN EXAMPLES. CAN ANYONE PLZ HELP ME.J2EE by itself is not capable of compiling Java. It requires that a J2SDK be installed first - this is what compiles and runs Java programs. Did you install the combination J2SDK and J2EE, or just the J2EE?
If both are installed, then you should be able to compile and run as you used to.. -
How to compile java files in a bunch of drectories?
I have a bunch of java files in a bunch of different directories. How can I compile them all at once? Please note I also do not know how to get javac to work outside the java directory.
put it another way, what I am trying to do is to compile David Brackeen's ch 18 code from his book. The java sourse files can be downloaded here:
http://www.brackeen.com/javagamebook/
my question is that how would I complie all of these file so that I can get the program in ch18src\src\com\brackeen\javagamebook\test\ to run?
Maybe you are looking for
-
Building the mod_jk between apche and jboss in solaris environment
hi there, i have installed apache2 and running on one zone and jboss installed and running on another zone now when i connecting of them using the tomcat connector by building the mod_jk i am getting the error where i have followed the procedure in t
-
When Palm advertised two ways to conferenc call we assumed they were going to get it right. the first way is obvious, the second way they obviously got lost. it was assumed the software would allow a person to list the contacts, press send and simult
-
Jdbc driver running with 32 AND 64 bits Oracle 9i version ?
I would like to be sure that a thin java jdbc driver is independent with the fact that oracle9i is running as 32 or 64 bits. Thanks
-
When I try to connect to my application icon it states "cannot connect to itunes store" why and how can I fix it
-
Printer and airport in the same hub
This worked 2 days ago- but that was before the ISP put in a new satellite dish and the airport needed to have an IP set manually- now it doesn't work and I'm trying to find a solution in system preferences.. First off the printer is fine- the lights