Enabling full documentation for Java EE in eclipse - java

I'm new to Eclipse and am using it currently to play with Java EE.
When using Ctrl+Space for types/functions from the regular Java libraries I get a full description (i.e. general description of the type, what are the arguments of the method for, etc.). However I don't get the same for Java EE types.
For example, when using Ctrl+Space on methods of the HttpSession class I get only names like "arg0" or "obj" and no description.
How can I remedy this?

I'd suggest downloading the javadocs and adding them in eclipse. (right click project > properties > java build path > libraries > expand the library > set Javadoc location)

I think that's why Java EE defines a specification only, the implementation must then be done by the provider of your application server. javax.servlet.http.HttpSession e.g. is bundled in servlet.jar.
It you are using Tomcat as your application server, you could attach the java sources to your servlet.jar and then you can browse the source and read it's javadoc.
The source for the latest tomcat is here ->
http://www.apache.org/dist/tomcat/tomcat-6/v6.0.26/src/apache-tomcat-6.0.26-src.zip

I wanted to add what might be very pertinent information for projects using maven and eclipse / wtp. What I did to get the Javadocs to attach nicely was the following 2 steps.
1) I am using glassfish so using the glassfish plugin site I installed the java ee 6 (or 7) documentation. You can easily view this documentation with Help->Java EE 6 docs. I copied the URL from here.
2) Opened my projects build path and went to the libraries tab. Opened the Maven Dependencies and found the java ee 6 api entry (this should be part of the maven project). Opened this up and was able to add a location for the javadocs for the api. I pasted the file:/// url I had copied.
Then I verified this worked by using the ctrl + shift plus mouse pointer hover over some of the java ee 6 classes and methods.
I hope this information will be useful to other who searched and got here but didn't find the solution they were looking for (or for those who now use Maven!).

Related

How to set NetBeans project properties to use Java 7?

I am new to NetBeans, and have previously been using Eclipse. I have started using NetBeans now because I need to learn a variety of Java EE concept, and I have found more relevant tutorials for the NetBeans IDE. A lot of the abstract concepts in EE still has me confused, so I have found that step-by-step holding hands-tutorials works best for me for now.
I have however met a dead end. I am following this tutorial, on setting up a web service client. However, one of the lines include a try-with-resource statement, which is new in java 7. Picture here:
When I started this tutorial, I was using Netbeans 7.1.3, with Glassfish 3.1.2. I knew it didn't have support for EE7, so i downloaded NetBeans 8.0.1 with Glassfish 4.1. I have realized later on that the try-with-resources is a part of SE, and my upgrade was in this matter reduntant.
I figured there was something wrong with my project settings, so i right-clicked it and opened it's properties. Under the Libraries option, I found that the JDK was correctly set to Java 1.7 (update 51). Picture here:
I also checked the oter options, and under Run I found that Java EE is set to 6, even though Glassfish 4.1 is selected as server. I figured this was an implementation of EE7, but the option is locked to EE6. This confuses me a bit, but shouldn't be the cause of the problem. I still attach a picture of it, just in case it is relevant:
So what is wrong with my Java settings for this project? Why can't it accept a Java 7 feature, when it seems like it is set to use Java 7? Are there other places where i need to set java version/home?
You use Java7 for the system library but compile your source code to be compatible with Java6.
To change this you have to go to sources in your project settings and change the source compatibility to Java7.

Avatar.js and Project Avatar

In the context of Java 8 and Nashorn I see two projects being regularly mentioned.
Avatar.js and Project Avatar
What is the relation of these projects?
Avatar.js has very little documentation. As far as I gathered it offers the possibility to execute node applications on the JVM.
Project Avatar seems to build on Avatar.js. However the scope seems to be to provide an alternative Web-Framework for Java EE 7. Is it also possible to execute node programs (like i.e. grunt) with Project Avatar?
Update: Project Avatar was officially halted 2015-02-12.
Avatar.js is the open-source version of what was informally called 'node.jar' (See this post from the avatar-js mailing list). In other words, it is a NodeJS-compatible API, running on Nashorn. Project Avatar appears to be Oracle's answer to the NodeJS API, offering an alternative platform which also provides compatibility with the NodeJS API and ecosystem via Avatar.js.
Therefore it is not that Project Avatar is built on Avatar.js, but rather that "Avatar.js is one component of Project Avatar. Nashorn is the JavaScript engine used to run both." (again, from this post).
The Avatar.js homepage currently has a list of modules known to run, including "grunt". It would appear that Project Avatar currently includes a build of Avatar.js as "avatar-js.jar", as found in the current latest commit, though it is 4 months old. So I think the answer is that yes, the current build of Project Avatar will allow you to run Node-compatible modules.
As you've pointed out, both of these initiatives lack documentation, and are in their infancy. Time and community engagement will show where they fit best.
Indeed there is Avatar.js included in Project Avatar.
By looking at the Maven POM files of Project Avatar, I discovered that there is a binary distribution of Avatar.js available through the java.net Maven repository.
Based on this discovery I wrote a blog post how to run simple Node.js apps with Avatar.js here:
Running Node.js applications on the JVM with Nashorn and Java 8
Steps for OSX repeated here:
Download avatar-js.jar from the java.net Maven Repo. Current version
is here:
https://maven.java.net/content/repositories/public/com/oracle/avatar-js/0.10.25-SNAPSHOT/
Example file: avatar-js-0.10.25-20140313.063039-43.jar
Download the native library avatar-js.dylib from the java.net Maven
Repo. Current version is here:
https://maven.java.net/content/repositories/public/com/oracle/libavatar-js-macosx-x64/0.10.25-SNAPSHOT/
Example file:libavatar-js-macosx-x64-0.10.25-20140312.062209-35.dylib
For Linux
you would download the corresponding .so file from ../libavatar-js-linux-x64/0.10.25-SNAPSHOT/
For Windows you would
download the corresponding .dll file from
../libavatar-js-win-x64/0.10.25-SNAPSHOT/
Rename the native library to avatar-js.dylib and rename the jar to
avatar-js.jar and put both in a directory called dist.
Create a simple Node.js app in the a file called app.js.
Run the command: java -Djava.library.path=dist -jar dist/avatar-js.jar app.js
Project Avatar does indeed layer on top of Avatar.js; the code is integrated into our build using Maven. (The jar you found, Johann, was old because we no longer use it -- I just nuked it, thanks).
And yes, we're aware that our docs need more work. For now, we are focussing on fleshing out the server-side JavaScript framework. This services layer provides a runtime tuned for easily creating REST, WebSocket and Server-Sent Event endpoints.

Java 7 EE Tutorial examples

Where can I find code examples for Java 7 EE Tutorial? I've already found examples for Java 1.5, Java 1.6 with Ant tool & Glassfish server v3 and examples named "firstcup" for Java 1.7.
But there are no files coupled with this tutorial (it uses Apache Maven instead of Ant).
UPDATE
Here they are:
SVN
If you click "check out" on the page, it shows the URL for SVN checkout. You can use that URL in command line SVN as:
svn co https://svn.java.net/svn/javaeetutorial~svn
Or you can copy the URL into a tool like Tortoise SVN and check out that way.
Regardless, you need a login on the java.net to use when checking out.
Download the Java EE 7 SDK Update 3 no web profile
Unzip the file
glassfish4/docs/javaee-tutorial/example

How to organize my Eclipse GWT project for Java 7?

For the backend (services) I would like to use Java 7 and the new language features. For the frontend this is impossible, because the GWT compiler is unable to parse Java 7 language constructs at this point. So I would like to setup two Eclipse projects: One for the frondend with Java 6 and one for the backend with Java 7. Any idea how to do the build (no Ant, just in Eclipse) and manage the dependencies?
I think you would like three projects.
1: The frontend project which uses GWT to compile code to Javascript. This should use Java 6.
2: The backend project, which is pure Java and can use Java 7.
But, they will need to share some code (async interfaces, data structures, etc). Therefore you need a third project:
3: Shared project which contains shared code. This should also use Java 6 and GWT and should define a GWT module. The frontend project can therefore reference this project as a GWT module and that should cause the shared code to be compiled to Javascript.
The backend project should be able to reference this project even though it is Java 6.
Isn't it enough simply don't use java 7 features on your client and shared packages? I don't think you need two projects
I think GWT can run fine over a Java 7 VM, and the GWT compiler don't care about your server package
You should be able to set the project's Java in the project settings.
Select the project in Eclipse, then select Project > Properties.
Java Build Path > Add Library. You can Add/Remove the JRE you want. After those changes, make sure that the settings under Java Compiler look right too.

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