javax.ws.rs package - java

I am learning RESTful Web Services and all the tutorials use javax.ws.rs.* package. But with JDK 6 and JDK 7, my Eclipse doesn't seem to recognize javax.ws package. What am I missing here?

javax.ws.rs is not a JDK package; it is a server-side API that forms part of the Java EE specification. You would need to include a Java EE runtime on your classpath or source an implementation from a 3rd party if you're going the self-assembly route (e.g. using Tomcat.)

You're may be missing Jersey installation, or something in your environment configuration. Try also installing Eclipse WPT. You can follow this tutorial, it covers prerequisites and basic installation procedures as well.

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

Doesnt JAVA EE SDK include the APIs in JAVA EE DOC?

I installed JAVA SE JDK and then installed JAVA EE SDK java_ee_sdk-6u4-jdk7-windows-x64.exe
because the latter one requires a jre. But then I found that the java ee sdk is merely nothing new than java se but a combination of java se jdk+ glassfish platform. I do not know if I am right because I cannot find those "java ee" classes in it. (And the .jar files in jre/lib are the same) It is strange. Lets say JavaMail package, I cannot find it in my java ee jre but it is said this package is included in Java ee platform.
What I expected is the new apis and "java ee" source code which I could not find either. I really would like to know how to get a jdk which includes all the apis descripted at
http://docs.oracle.com/javaee/6/api/
Can some one tell me if I am right about this issue (JAVA EE SDK does not contain JAVA EE API)? If I am right, do I need to get each jar lib from the internet when I use it? Then what is the different between java se + external lib and java ee? Or Did I make any mistake when I installed?
Thank you guys!

How to handle missing ExpressionFactory#newInstance() method in api downloaded by maven?

According to java ee 5 api ExpressionFactory provides a method #newInstance.
I'm using the official javaee-api available in maven: Java EE 5 APIs now in a Maven repository...
But this jar does not provide this method. So I get compiler errors.
How can I get a compilable version without using javaee implementations like e.g. glassfish, openejb?
The official Java EE 6.0 jar provided by maven (java.dev.net) contains this method.
According to java ee 5 api ExpressionFactory provides a method #newInstance.
Well, javadoc is not a proof and, actually, this is very likely an error in the Java EE 5 javadoc. The two newInstance() factory methods have been added in the Maintenance Review 1 of the JSR-245 (to make EL standalone and take it out of JSP 2.1, have a look at the JSR-245 MR1 Change Log for the details) but that review has never been released.
So it's not surprising that you don't find this method in the java-ee bundle available in the java.net repo.
But this jar does not provide this method. So I get compiler errors.
As expected. This method is not in Java EE 5 (at least this is my understanding). So you need to use:
ExpressionFactory factory = new ExpressionFactoryImpl();
The official Java EE 6.0 jar provided by maven (java.dev.net) contains this method.
Yes, because this is Java EE 6, because EL is now standalone, with its own specification (technically, EL is still in JSR-245, sorry if this is confusing). So Java EE 6 includes EL 2.2 (yes, the version jumped from 1.1 to 2.1.2 and then 2.2 for a better alignment with the JSP version). And this version does expose the newInstance() methods on ExpressionFactory.
Why don't you want to use the libs from a Java EE server ? You'll eventually have to test in one, even if locally. You could use Tomcat, it's easy to install and to use.
In Tomcat for example, all the jars providing the Java EE api are available in the lib folder. If you compile using those libs, and stick to the standard Java EE API, your code will be compatible with all servers that implement the Java EE API.
If you use Maven and don't want to have these libs in your arborescence, and have a server installed, you can use the system dependency type (see here for more informations)

Missing javax.servlet.http.Cookie class

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.

for-each loops and generics in Java EE

I am designing a website-based project wherein I first designed my logical layer in Java SE application development. Then I made the GUI in Java EE for the website. I am importing my Java SE files in the Java EE architecture using JSTL and I will call the data using this only.
But, it is giving me an error as follows:
for-each loops -- for-each loops are not used in source 1.4, try source 1.5 to enable for-each loop.
generics -- generics are not supported in source 1.4, try source 1.5 to enable generics
variable-arity methods are not supported in -source 1.4
It appears you have the wrong JDK selected - all those features were added in JDK 1.5. Make sure you have the 1.5 JDK selected for both your IDE, and your web application App Server. This should resolve your problem.
If you are building via Ant or by the command line, ensure that you specify "-source 1.5" on the javac command line. Also, JSP files will not necessarily use Java 5 features by default. This depends on what Servlet standard you're using. For example, see this blog entry that tells you how to set Tomcat 5.5 so it will allow 1.5 features in its JSPs.
In Netbeans the Java EE format is part of the project settings. Unfortunately it can't be changed in the project settings once you have created the project.
Create a new project with the Java EE 5 version and copy your source across.
To be able to select Java EE 5, you will need a Java EE 5 capable server installed, eg. Tomcat v6 or GlassFish v2. You can install the servers using the NetBeans Tools->Servers menu.

Categories

Resources