Tomcat 6 conversion to Glassfish v3: servlet-api, el-api jars - java

I used ant when building my web app from eclipse to deploy to Tomcat 6 and referred to servlet-api.jar and el-api.jar within the Tomcat 6 release tree rather than pulling them in to my deployed library folder.
I am trying to deploy to Glassfish v3. I've pulled the jars from the www.java2s.com website.
Was this the right place to get them?
Did I need to do it at all? I searched within Glassfish and the jars weren't there
If I didn't need to do it at all, is there another course of action to follow to ensure the same functionality is available?

Seeing this question and the other questions you posted I have the feeling that you're doing things completely wrong. Here's just an answer which should get it all straight.
You should never have separate copies of servletcontainer-specific libraries wandering around in the classpath.
You should never put copies of servletcontainer-specific libraries in webapplication's WEB-INF/lib.
In an IDE like Eclipse, you should never add servletcontainer-specific libraries separately in project's build path.
In a nut: just do not touch servletcontainer-specific libraries at all. Don't even think of downloading them separately. That's plain recipe for trouble. Having separate libraries of different servletcontainer makes will only result in collisions in classpath. The servletcontainer should be downloaded and treated as its whole own.
In Eclipse, when integrating a servletcontainer (Tomcat or Glassfish), just add it in the Servers view.
To associate a dynamic web project with a specific servletcontainer (server) so that you can compile servlets and so on, you need to select it in the Targeted Rumtimes section of the project properties. Then everything will go well automagically, thanks to Eclipse smartness. That's also the place to change the servletcontainer implementation whenever necessary. When you're creating a brand new dynamic web project, you can just choose the desired servletcontainer implementation from the servers dropdown in the wizard.
When you want to create a WAR, simply rightclick the dynamic web project, choose Export and then WAR file. No need for a separate ant task or so.

Related

Add maven project build to tomcat in eclipse

I used to add my maven project to tomcat server v7.0 by right click server -> add and remove -> select my project -> Finish.
But today i dont find my maven project in the list.
There is only one project in the Available section.
How can i have my project in the list.
I have seen this kind of junk in IRAD (the IBM version of Eclipse) many times. I think the software is just plain buggy. Make sure you back up your code somewhere else, like in your code repository, and delete all your projects including local files. Then check everything out again. Also, tomcat is great for picking up changes in its webapps folder. You might want to just forget about deploying through eclipse all together. You have some other options that will actually allow you to see changes immediately with out having to redeploy.
Hot deploy solutions
1) Use Jrebel - this is expense
2) Expand your war in the webapps folder and send symbolic links back to your target folders containing your class, and to you jsp, javascript directories
3) Expand your war in the webapps folder and use filesync plug in (its been hard to find on the web for a while) to copy your changes to the expanded area
Other ways just to send your war/ear over, not hot deploy
1) Change your maven code to copy the ear/war to the tomcat directory for you every time you run maven install
Fully integrated IDE to webserver seems to be fantasy that they never quite worked out as far as I can tell.

what is the need of Servlet.jar in eclipseIDE when we create a servlet in Dynamic Web Project using Build Path option?

I was going through java tutorials and found that after creating the servlet they have added the servlet.jar file using build path opt. But in my case servlet is still working without that external jar file.
So what is the need of that external jar file?
It's still working fine in your case because
Just check below
Right click on your project then go to Properties -> Targeted Runtime -> Apache tomcat
If you have selected that checkbox you no need to add servlet jar and if it's not then you need to add servlet jar in lib folder
So in your case you must have selected targeted runtime that's why even though u have not added servlet jar file it's working fine
You don't need to add because you may have added Apache Tomcat as server run time in for your web project and Apache tomcat has servlet.jar in its lib folder so it will be there
you can check it by going in Apache tomcat folder > lib
You need Servlet-api.jar to compile servlets in eclipse but while deploying servlet container ( like tomcat ) will have it built in. Infact it is bad practise to include it inside your WEB-INF/LIB folder.If you configure your eclipse to use libraries from tomcat(or other servlet containers) then you might not need it manually.
Servlet-api.jar is by default provided by the container environment. So you should not put it in your WEB-INF/LIB folder when you are deploying your application. However, it is required for compiling your Servlets. In case if you are using Eclipse as your IDE, place it in your classpath using Add External JAR files option.
Ensure that you're using at least Eclipse IDE for Java EE developers (with the EE). It contains development tools to create dynamic web projects and easily integrate servletcontainers (those tools are part of Web Tools Platform, WTP). You also need to ensure that you already have a servletcontainer installed which implements at least the same Servlet API version as the servletcontainer in the production environment, for example Apache Tomcat, Oracle GlassFish, JBoss AS/WildFly, etc.
You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.
These links below will give you more information about this
How do I import the javax.servlet API in my Eclipse project?
Understanding who provides servlet-api.jar, is it web-container or part of Java EE download
http://wiki.metawerx.net/wiki/JARFilesYouShouldNeverIncludeInYourWebapp

Is there a way to deploy a Maven project with "jar" packaging into Tomcat7?

My project generates a Jar as the output package and uses an external War file, available on our Artifactory, as the Web Application to be deployed on Tomcat (currently using version 7). This War file contains all libs and modules required for the application to run.
I have already packaged and ran those projects outside eclipse on a "vanilla" Tomcat installation. In this scenario, the Jar my project generates is loaded on the context.xml file this way:
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/igor/workspace/myapp/myapp-2.4.3.jar"/>
Is there a way I can deploy this project on Tomcat using Eclipse and still be able to debug it? Can I use the Jar generated for this purpose or do I have to deploy the workspace project?
As for the War file, do (or can) I have to add it as an dependency?
Thanks in advance!
EDIT
We actually provide an Web Framework, which is packaged as a war. Other applications that use that framework are exported as jars and loaded into the framework through the context file as cited above.
Your question is confusing probably because of your custom plugin/classloader and deployment which is sort of orthogonal to debugging.
What I recommend is you keep whatever system you have to build/package/deploy and use JVM remote debugging. That is do not use the Eclipse WTP since you seem to have custom steps for deployment but rather build your code deploy & run a separate Tomcat instance and then run the remote debugger in Eclipse.
You will get some hotcode swapping with this method but not as much as something like JRebel.. (which you could use also) it will certainly be better than constantly redeploying.

Deploying GWT app with own external library

I have a GWT project [com.bob.gwt] that uses another library of my own, [com.bob.domain], which is used by both in the client and server. The domain project is exposed via gwt.xml project in com.bob.gwt.
When the server runs, it indicates that some Server classes from com.bob.domain could not be found in the web app, but were found on the class path and added. The WAR directory doesn't have the .java or .class files from com.bob.domain.
The com.bob.domain is added as a library in the Java Bulid Path Window's Projects tab, and also checked on the Order and Export tab in Eclipse. Do I have to set com.bob.domain as a jar and import that jar in com.bob.gwt? Can I just include the domain source in my gwt project so I can debug all at once without having to manually build a jar, and have everything in my WAR folder ready to go for deployment?
During development, it's convenient to use Eclipse's project reference mechanism instead of rebuilding "domain.jar" every time. In that case, it's safe to ignore GWT's warning.
When you perform the "real builds" outside of Eclipse (which I would strongly recommend), you usually can't make use of Eclipse's project reference (except maybe if you're using Ant4Eclipse), so you'll need to tell the GWT compiler (gwtc), and the server side compiler (javac), where to find everything they need, including the domain project's files.
Then, for deployment, you'll need to put "domain.jar" into the "WEB-INF/lib" of your war.

jsf and eclipse setup. Lib in Explorer is different than lib in tomcat. How come?

I am starter in JSF2.0, and I have a question related to Eclipse (I am using Helios).
1)I create a Dynamic Project
2)I add JSF project facet.
3)I choose JSF user library (I have created it using MyFaces)
All ok so far.
I notice though that in the Project Explorer in WebContent/WEB-INF/lib the lib directory is empty instead of having MyFaces jars.
The application works fine though.
I looked into this and the jars are actually being placed in the corresponding lib directory of the app deployed under wtpwebapps of the Tomcat instance of eclipse in the .pluggins directory.
Ok, it works but IMHO it is incorrect to have the Project Explorer inconsistent with the directories actually deployed.
I.e. lib is shown empty in Project Explorer but with jars under wtpwebapps.
Am I wrong to dislike this inconsistency?
Is this how it should work or am I doing something wrong in the way I am setting my project?
Thanks!
That's normal for user-definied libraries. It's listed in libraries folder of the Java Resources folder. It's just an extra layer on managing libraries. If you dislike this, then choose Disable Library Configuration in the wizard and drop the JAR's in /WEB-INF/lib yourself.

Categories

Resources