Missing javax.servlet.http.Cookie class - java

I haven't been using Java extensively hence forget a lot fundamental things. Basically, I am working with a web-dynamic project (using Eclipse IDE with jdk 1.6), and during the build, I get errors that Cookie class and other web related classes cannot be found. What am I missing?
What Jars files do I need to add (and how)?
thanks

Think you need servlet-api.jar
Try here for any jar files you need http://www.java2s.com/Code/Jar/CatalogJar.htm

Sounds like you are missing servlet-api.jar
You can download it from the Maven repository.

Servlets are only part of the Enterprise Edition, not of the Standard Edition of Java. So you need the Java Enterprise Edition, AKA Java EE.
http://java.sun.com/javaee/

As others have said, you're missing the server api jar.
Having said that, downloading just the servlet api jar and not the server that goes with it means that you can't actually test your code.
In Eclipse, once you're installed a servlet container, such as Sun's Glassfish, Apache Tomcat, or Jetty, you can create a server instance of it so that Eclipse will compile against your server's servlet implementation. Creating a server instance also means that Eclipse's Run on Server command works.
IBM has a slightly outdated guide on Developing Web applications with Tomcat and Eclipse. The entire "Install the Web tools" section can be skipped if you have the Eclipse EE version, as Web Tools are already installed.

Related

Downloading and adding javax.enterprise.context.RequestScoped to my project

I've got a project running 1.7. I'm getting issues using javax.enterprise.context.RequestScoped. I'm confused as to why it isn't included as I have other javax.* libraries built into Netbeans by default.
Where can I download this library and how can I add it to my project?
By default, only the packages that are part of the Java Standard Edition are available. This library belongs to Java EE. Just go to project->properties->libraries->add library->Java EE Web 7 Api Library->add. That´s it.
It's part of the Java EE Specification. You should start your project within a container. In Netbeans use an Enterprise Application project type.
Try this:
You can import this jar file into your project.
Use cdi-api.jar
I found mine in glassfish folder
.\glassfish-4.1\glassfish\modules

How to create a Dynamic Web Project with JAX-WS based Web Service in Eclipse?

How can I create and run a JAX-WS web service in a Dynamic Web Project using Eclipse? I'll be using Tomcat 7 as my server. Can you provide a step by step tutorial on how to do it? A hello world web service will do.
I followed this tutorial but I wasn't able to make it run. I did not follow the tutorial's step 4 - 6 because I'm already using Eclipse and the directories are already properly structured on a Dynamic Web Project. Also, my Tomcat is running under JDK 6. Since JAX-WS is already part of JDK 6, there's no need for me to copy it inside Tomcat. When I run the URL indicated in the tutorial, I get a resource not found error.
I think the jax-ws is not part of the JDK. You have to copy the jax-ws implementation into the Tomcat.
Did you find the jax-ws.jar in your JDK folder?
Ok, JDK6+JAXWS often gives problems.
You need to create an endorsed-Folder.
Try to run Tomcat from Eclipse. using these additional VM-Arguments:
-Djava.endorsed.dirs="<your-server>\endorsed" -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.MessageFactoryImpl
-Djavax.xml.soap.SOAPFactory=com.sun.xml.messaging.saaj.soap.SOAPFactoryImpl
-Djavax.xml.soap.MetaFactory=com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
now, place the latest saaj-impl and saaj-api to the endorsed folder.
This should work.

Which Eclipse IDE version to choose?

How do I find which Eclipse version I have on my Ubuntu system?
This is what "About Eclipse SDK" says.
Eclipse SDK
Version: 3.5.2
Build id: M20100211-1343
I am not sure if its the Eclipse IDE for Java Developers or the Eclipse Classic version.
What I would like to do is use Eclipse for
Java based Web Application Development
Ant Builds
Deploy using Tomcat
including HTML, CSS Editing
Please help me decide which version I should choose? I would like to upgrade my Eclipse setup from whatever version it is now to a version that supports all the above. Should I go for Eclipse IDE for Java EE Developers?
Should I download a totally new version from Eclipse site or can I just ADD necessary features/plugins to my current Eclipse setup.
Please suggest.
See Compare Eclipse Packages for a nice chart
What I would like to do is use Eclipse for (...)
The Eclipse IDE for Java EE Developers allows to do what you're asking for out of the box.
Should I download a totally new version from Eclipse site or can I just ADD necessary features/plugins to my current Eclipse setup.
Both would work, although it would be simpler to just get directly the Eclipse IDE for Java EE Developers (especially if you don't know exactly what plugin(s) you're looking for). Personally, I don't use the version you can get from the repository but download Eclipse from the official website and install it in user mode.
If you are using Eclipse for only Enterprise Development, then as everybody has recommended I would use the Eclipse Java EE version. If you plan on occasionally using it for other development purposes then I would consider downloading a separate classic version as well.
The reason for this is that everybody is well aware of eclipse's plugin capabilities. Unfortunately, Eclipse can get bogged down with too many plugins or add on tools. What I have experienced is that if you are using it for Enterprise Development(J2EE) it might be a good idea to keep that as a separate environment then your other Java Development. That way you can download the plugins,tools,libraries,etc for your enterprise development, and you can use your classic version for any other development you might need.
The downside is you will have two versions, but this is not a problem granted you do not run them simultaneously.
If you want to play with Web development, then the Eclipse java EE for Developers is for you. It is shipped with components to make Java Enterprise applications to create Enterprise Applications (and bundle it in an Enterprise ARchiver, known as EAR file or Web ARchive, known as WAR file).
The default Eclipse shipping with Ubuntu is the Classic version, and you can add more plugins.
I would recommend, however, to download th eJEE version manually and unzip it and run. Then you have a local installation outside the system files.

classpath question, head first servlets book

I'm studying via Head First's Servlets and JSPs, and doing the assignment on the third chapter.
On page 81, there's this javac call:
> %javac -classpath /Users/bert/Applications2/tomcat/common/lib/
servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java
I don't get what it's trying to do. The book says that everything on the path before common should be suited for my specific system, but I don't have a common/lib path (not that I know of). I'm working on ubuntu 9 and I have created the following directory structures for deployment and developing of the web app that the chapter talks about, neither of them has a common/lib/ path on them. Where can I find this on my machine?
Which edition of the book are you using? The /common/lib is true for until with Tomcat 5.5 (Servlet 2.4). Since Tomcat 6.x (Servlet 2.5) and on the Servlet API libraries are available in /lib folder.
If you trace the rest of the path, you'll see that common/lib belongs to Tomcat, the engine on which you'll deploy and run your servlet when it's compiled and packaged.
I'm assuming that you've downloaded and installed Tomcat.
Since you said the book called for "common/lib", that tells me that the examples are based on Tomcat 5.5. Tomcat 6.x, the latest version, uses "lib" instead of "common/lib".
The point is that you need the servlet API JAR in order to compile successfully.
If you installed a packaged version of tomcat, it should be:
/usr/share/tomcat5.5/common/lib/servlet-api.jar for Tomcat 5.5
/usr/share/tomcat6/lib/servlet-api.jar for Tomcat 6
But my recommendation would be to get a binary distribution of Tomcat from the official website (get the version of the book if you want to stick to the book) and to uncompress it in your home folder (I put this kind of stuff in ~/opt)

Where's javax.servlet?

I have jdk1.6.0_13 installed, but when I try to find a javax.servlet package, or press Ctrl+Space in Eclipse after Servlet I cannot get anything. Where can I download this package, and why isn't it included in standard distribution for developers?
javax.servlet is a package that's part of Java EE (Java Enterprise Edition). You've got the JDK for Java SE (Java Standard Edition).
You could use the Java EE SDK for example.
Alternatively simple servlet containers such as Apache Tomcat also come with this API (look for servlet-api.jar).
A bit more detail to Joachim Sauer's answer:
On Ubuntu at least, the metapackage tomcat6 depends on metapackage tomcat6-common (and others), which depends on metapackage libtomcat6-java, which depends on package libservlet2.5-java (and others). It contains, among others, the files /usr/share/java/servlet-api-2.5.jar and /usr/share/java/jsp-api-2.1.jar, which are the servlet and JSP libraries you need. So if you've installed Tomcat 6 through apt-get or the Ubuntu Software Centre, you already have the libraries; all that's left is to get Tomcat to use them in your project.
Place libraries /usr/share/java/servlet-api-2.5.jar and /usr/share/java/jsp-api-2.1.jar on the class path like this:
For all projects, by configuring Eclipse by selecting Window ->
Preferences -> Java -> Installed JREs, then selecting the JRE you're
using, pressing Edit, then pressing Add External JARs, and then by
selecting the files from the locations given above.
For just one
project, by right-clicking on the project in the Project Explorer
pane, then selecting Properties -> Java Build Path, and then pressing
Add External JARs, and then by selecting the files from the locations
given above.
Further note 1: These are the correct versions of those libraries for use with Tomcat 6; for the other Tomcat versions, see the table on page http://tomcat.apache.org/whichversion.html, though I would suppose each Tomcat version includes the versions of these libraries that are appropriate for it.
Further note 2: Package libservlet2.5-java's description (dpkg-query -s libservlet2.5-java) says: 'Apache Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run. This package contains the Java Servlet and JSP library.'
Have you instaled the J2EE? If you installed just de standard (J2SE) it won´t find.
The normal procedure with Eclipse and Java EE webapplications is to install a servlet container (Tomcat, Jetty, etc) or application server (Glassfish (which is bundled in the "Sun Java EE" download), JBoss AS, WebSphere, Weblogic, etc) and integrate it in Eclipse using a (builtin) plugin in the Servers view.
During the creation wizard of a new Dynamic Web Project, you can then pick the integrated server from the list. If you happen to have an existing Dynamic Web Project without a server or want to change the associated one, then you need to modify it in the Targeted Rutimes section of the project's properties.
Either way, Eclipse will automatically place the necessary server-specific libraries in the project's classpath (buildpath).
You should absolutely in no way extract and copy server-specific libraries into /WEB-INF/lib or even worse the JRE/lib yourself, to "fix" the compilation errors in Eclipse. It would make your webapplication tied to a specific server and thus completely unportable.
If you've got the Java EE JDK with Glassfish, it's in glassfish3/glassfish/modules/javax.servlet-api.jar.
those classes are usually part of servlet.jar
http://www.java2s.com/Code/Jar/wsit/Downloadservletjar.htm

Categories

Resources