Eclipse Java EE IDE not supporting javax.servlet package - java

I downloaded Eclipse Java EE IDE to build Java Web Applications (servlets and JSP pages). But it still is not supporting the javax.servlet package.
Why? What's the reason? Is there any plugin that I need to install?

You need to integrate a servlet container in Eclipse and associate it with your Dynamic Web Project. Eclipse doesn't ship with a servlet container by default. You need to download and install it separately. A widely used one is Apache Tomcat. Just download the ZIP and extract it somewhere.
Then in Eclipse, go to the Servers view in the box at the right bottom. Then Add a new server where in you choose Apache Tomcat 6 from the list and point the Tomcat root folder (there where you extracted it). Then you can select it from the Target Runtime dropdown during the Dynamic Web Project creation wizard. Or if you already have created one but didn't associate it with a server, then modify it in the Targeted Runtimes section of the project's properties. This way the server's libraries will be automagically added to the project's buildpath. That's finally also the whole point. The server is basically a concrete implementation of the abstract Servlet API. It has all the API libraries in its /lib folder.
Here's a video tutorial (which does it a bit differently than above described, but it's also sufficient) and here's a text/screenshot tutorial (you can just skip the JSF part if that's not of interest yet).

You probably need to create a Dynamic Web Project instead of a normal Java project.
Or you can add a server profile to your workspace, and then add the server runtime to a Java project's libraries.
To add the server profile, go to Window -> Preferences -> Server -> Runtime Environments. Click Add..., choose the server type that you're using, specify the directory where that server is installed, and click Finish.
Now that you've added the server, you should be able to add it to the project as a library. Right click the project, then go to Properties -> Java Build Path -> Libraries -> Add Library -> Server Runtime, choose the server you just added from the list, and click Finish. This will make all the server's libraries available to your project.

Related

Tomee Installation process?

SPEC : jdk1.8 ,TOMEE702, win10
Question : How/What/which to install and use TOMEE for open-ejb3.X ?
url : http://tomee.apache.org/download-ng.html
I could not find any easy install-able for all of the downloads from the url.
with regards
Karthik
How to install
Just unzip the archive you downloaded.
which distribution
TomEE comes in several flavors which offer either alternative implementations for some of the specifications and/or additional functionality. Without more concrete requirements it's not possible recommend concrete flavor.
You can see the comparison here: http://tomee.apache.org/comparison.html Note that the table is for version 1.7 For 7.0.x, the details are in the text below.
The difference between plume/plus is that the first one uses eclipselink and mojara, while "plus" uses openjpa and myfaces.
The difference between web-profile and the others interms of ejb is that web-profile by spec supports ejb-lite, while plus/plume should support ejb full.
Also I'd recommend you to use the latest and greates version of tomee - currently 7.0.3 and upgrade to 7.0.4 as soon as it's released as it contains A LOT of fixes.
I think you want to know the way of using openejb with tomcat server.
To do that you will have to download openejb.war file.
http://tomee.apache.org/download/apache-openejb-3.1.4.html
After downloading openejb.war file download the tomcat server which can be downloaded from the link given below.
http://tomcat.apache.org/
Extract your tomcat zip file to a folder and deploy openejb.war file to tomcat's webapp folder.
If you are using Eclipse as an IDE then setup a tomcat server by going to window menu -> preferences -> server -> Runtime Environments. Add your version of tomcat server.
After adding the server, check the Project Explorer view, there you should see Servers folder. Finally right click on the project explorer view, select import and search for war file and lastly add the openejb.war file.
If everything goes well you should have successfully added openejb to your tomcat server.
If you have an openejb based project then you can add it by going to window menu -> show view and search for server. You should probably see the server view at the very end of your eclipse window. Right click on it and select Add and Remove. In the Add and Remove window you can control your projects deployment.
If you don't have a project then develop a project and add it to your server and run the tomcat server. You might also need to configure openejb.xml file depending upon your needs.
Tomee installation is no different then any other Tomcat installation. You should download the compressed file and extract it into your desired directory, preferably into root drive in case of windows extract it into the c drive.
Once extracted you can start it from the bin folder startup.bat or startup.sh script. Make sure you have the compatible jdk installed into your system and the path is configured for the JDK.
You can find the detailed installation step from the official documentation of apache.

javax.servlet.* cannot be resolved to a type

I am running ubuntu 14.04 and eclipse Kepler (with java ee modules preloaded) , I am developing Dynamic Web App for first time, it always says javax.servlet.xyz cannot be resolved to a type please help I am including a screen snapshot for my error page!
Only two things are required in Eclipse for this:
One
In Eclipse, Window -> Preferences -> Server -> Runtime Environment
Specify your Web Server or Application Server path, by adding a "New Server Runtime Environment".
Update
Initially, there are only few Server Runtime Environments available with Eclipse like:
Apache
Basic
ObjectWeb
On an additional note, you can add more Server Adapters using the link Download additional server adapters in Server Runtime Environments dialog screen.
Two
In Project Properties (Right Click on Project -> Properties), in Java Build Path, add Library "Server Runtime".On adding Server Runtime to Project Library will add servlet-api.jar and jsp-api.jar jars to project dependencies.

How to remove reference of a jar file in a java based web application?

I have a java based web application, which has certain java files and due to some need, i have added some jar files with in the project and made it project specific.
Now, While deploying them in production, I see, that the web file server (tomcat6) already has those jar files in its global library. Now, How do i remove reference of that jar file it, with out disturbing my code(which is working fine).
I saw in other article saying we just have to change the build path to refer the global library instead of local library.
Finally I have 2 questions.
How to do this?
If i'm working on windows and using path while configuring the build path, will it not be a problem if i deploy it in Unix environment.?
Please suggest. Also, its the problem with servlet-api.jar.
I use eclipse IDE. So how to perform these changes in eclipse?
Open your web project in eclipse and right click on the project. click on Properties and then choose build path and remove the jars you want to remove under the tab 'Libraries' and then export the war and deploy it in your tomcat6 server. if you want to run your web application in eclipse, you have to configure the server libraries by clicking 'Add Library' button in build path and then choose server runtime and choose the tomcat6 server configured in eclipse. Hope this helps

Problem resolving javax.servlet

Eclipse can't resolve javax.servlet. I use Apache Tomcat.
My CLASSPATH variable looks as following:
C:\glassfish3\jdk\jre\lib;C:\glassfish3\jdk\lib;
C:\Programme\liferay-portal-tomcat-6.0.5\liferay-portal-6.0.5\tomcat-6.0.26\lib
As far as I know javax.servlet is in the file servlet-api.jar which is there.
Do I need to configure anything else than the classpath?
Ensure that you're using Eclipse for Java EE developers. If ensured, then first integrate Tomcat in your Eclipse environment if not done yet. Open the Servers view at the bottom, rightclick it, choose New, add Apache Tomcat from the list and follow the wizard.
Then rightclick your dynamic web project, choose Properties and then go to Targeted Runtimes and select the integrated Tomcat from the list and click OK.
That should be it.

How do I properly deploy and structure projects in Eclipse against Tomcat?

I am relatively new Java developer that's been thrown in the deep end, my usual skillset lies in Microsoft products and C#.
However I have managed to write a nice web service using Restlet and incorporating Toplink and doing some database CRUD stuff, etc etc.
I developed this in Eclipse against Tomcat 5.5. I followed tutorials and examples and managed to throw something together that works.
I had all my jar files in WebContent/WEB-INF/lib directory of my project - I soon realised that when I export this as a WAR file and deploy in Tomcat, it takes these jar files with it and stores them local to the application.
Fine, but then when you try to undeploy the app, it only does it partially as Tomcat "holds on" to some of the jars it was using i.e. the Oracle JDBC, and Toplink ones. This makes sense as the web service was using these jars as there was a live Oracle connnection going on.
So then I thought I should have all these jars in a common place where all deployed apps can access them, that folder I believe is:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib
(in my case). This made total sense, it's logical as you don't want loads of apps on Tomcat all referencing the same jars. So I removed all the jars out of my projects lib folder and put them in the common\lib directory.
Now my app will not work properly - it can't find my source code in src, the custom bespoke code that I have programmed against these jars. It will only work if I jar up my source code and put in the directory stated above. Odd.
I am obviously very confused with class paths and build paths and all of that stuff, and must have got this sort of stuff all wrong as I am no Java expert, as I readily admit I have pretty much hacked this together - so can anyone explain to me in laymans terms how I should structure my project to get it working with jars held in a common folder in Tomcat. Or are there any good resoureces on the web to help explain to me what I should do.
Hope this all makes sense...
Here is a pic of my current project:
Sounds like you are not using WTP web project.
If you've installed 'Eclipse IDE for Java EE Developers' flavor of Eclipse, the WTP is already bundled in there. Otherwise here its update site -> http://download.eclipse.org/webtools/updates
Once you've installed WTP you should create 'Dynamic Web Project'.
In general I would recomment to put only your presentation layer here ( JSPs, CSS, HTML ) and put all pure java projects into standard 'Java' project that you later add as a dependency to 'Dynamic Web Project'.
WTP can run your web application under a number of containers, fortunately Tomcat is supported.
You will need to configure it through Window->Preferences->Server->Runtime Environments.
Once runtime envirnonment is configured, you can create your server runtime:
Right click in 'Servers' view.
Choose New->Server
Select server type: 'Tomcat v.5.5 Server'
(Optional) Change server name to whatever makes sense for you
Select server runtime environment: This is the Runtime Environemtn that you have configured previously
Hit 'Next' button
Add your 'Dynamic Web Project' project to 'Configured projects:' panel
Hit 'Finish' button
After the server is configured you can just run it, or you can put it in Debug mode. All source code referenced by dependent projects will be available for debugging.
NOTE:
From personal experience, I would not recommend using common/lib. Put all the jars that your web application relies upon into its WAR file. If you are worried about dependency tracking then start looking into Maven and m2eclipse.
Usually I put my jars in $CATALINA_BASE/shared/lib/
Please read this documentation for more clarification and specially Class Loader Definitions section.
Also restart the server after you copied the jars.
Go to Window > Show View > Other > Server > Servers, a servers tab will appear below with console tab. Click on your server and then F3, this will open server configuration.
Check Server Locations, and make sure you checked Use tomcat installation(takes control of tomcat installation) then click Modules tab below and it will show your installed modules, make sure the module is present or add it.

Categories