Java Web Container implementation independant development - java

One of the most important non-functional requirements of any project is the build process in my opinion and that's where I kinda get stuck in my java project, which has just one external dependency, a jdbc compatible database. All the tutorials about spring and deployment out there; I've read them all, but they either say:
run it with gradle bootRun applications.properties (yes works but on a webserver I'm not going to have any properties-files, but JNDI resource for example) or
build a deployable war file with JNDI resources (yes it works on the webserver, but not in my embedded webserver or I'm doing it wrong, but I cannot find any doc about how an embedded tomcat loads a context.xml from outside the jar file).
Now I tried to use the same setup as my server and installed tomcat7 and the #Asyc #Scheduled services run, but no servlets, like a simple /status page should return "OK" just for checking. catalina.out does not show any errors. My /manager from tomcat7-admin says deployment ok, and when I click start: "FAIL - Application at context path /xyz-0.1.0 could not be started
FAIL - Encountered exception org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xyz-0.1.0]]"
And now I want to make a cut here and throw every "bootstrap" stuff away and start from zero.
So my question is, am I wrong when I say, that the big deal of my deployment is a jdbc JNDI resource provided from the web container, which is called 'jdbc/xyz' and everyone who wants to deploy my war needs that JNDI. That means so matter if you're using wildfly, jboss, tomcat, glassfish or any embedded server: your server impl has to provide that web container and jndi resource to make it run. And I don't want to configure any tomcat, glassfish or whatever implementation in my war.
Is that wrong?
It would be great, if you could help me. I'm playing around with that many weeks now :( and if A works B does not and vice versa. Would it be easier to use JEE?
Thank you.

Related

Difference between an Enterprise application project and a Web project application in Netbeans IDE

Please I would like to know the major difference between a Jave EE project and a Java Web project in netbeans IDE with respect to the EJB. In fact you can create a web application based on EJB, JPA and JavaServer Faces in Netbeans IDE if you choose the Java Web category.
On the other hand you choose the project category as Jave EE project, NetBeans IDE will create 3 sub-projects, e.g: StoreApp (Enterprise Application project), StoreApp-ejb (EJB project), and StoreApp-war (Web project).
The first one will be packaged as a single .war file, the second one will be packaged as an .ear file, containing the web .war and the EJB .jar.
The difference between these is a bit broad to handle here, but I wouldn't advise on creating EARs unless you know that you want/need to.
I think you should learn firstly about web server and a application server..
well i'll happy to help you.
1) we cannot run enterprise application in web server.. i.e. if u are using EJB etc. to run this EJB project you have to use Application Server like JBoss and many more.
2) while using web server it cannot load any heavy application means if your application having multiple users , in that case connection pooling will come into the picture. for connection pooling Application server much better then web server.
For more you can visit below link:-
What is the difference between application server and web server?
I hope it'll helps you
Thanks!!!
There are 3 kinds of project/application:
Standalone Java application and sometimes call it as swing application. Bundle it in the form of Jar and you can run this application without any web or application server.
Web-application: Basically we have to create a war which is combined with html/jsp,jar etc. This war file has to deployed into webcontainer.
Enterprise Application: We have to create a EAR file which is combined with war, EJB & jar. This has to deployed into application server.
A very helpful tutorial https://www.youtube.com/watch?v=6vMB3rzN_Xw
Hope this helpes... cheers!!!

How to redeploy a war in tomcat seamlessly?

I just packaged my maven web application into a war file, upload it to remote server which has installed the tomcat environment. After I unpacked my war file and put all files in the /webapps/ROOT directory, I run bin/startup.sh to fire up the tomcat.
This just works fine, but when I intend to change my web application and redeploy it on the server, I don't know how to do that seamlessly, that is to say, not letting the users who is using my website lose any request.
Could anyone give me some idea? Thanks a lot!
You can always use manager app coming with tomcat to deploy a war without bringing the website down, even from a remote machine using browser.
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Deploy_A_New_Application_Remotely
You may use reverse proxy as door of you site. After deploying your "second" war into Tomcat, you can change the configuration of reverse proxy and reload it. The reloading of reverse proxy is very speedy, so that it likes "seamless" re-deployment of Java web application. After the reloading of reverse proxy, you could un-deploy "first" war of application safely.
This way to re-deploy is especially useful if the application needs time for initialization(for example: including ORM, Spring Framework...).
There are few concerns about using multiple-war-at-the-same-time:
1) There will be two applications(although, temporary) running on your Tomcat concurrently, make sure there is nothing hazard about concurrent executing. For example: scheduled jobs
2) You need to confirm that there is enough memory on Tomcat to live with two web applications, or Tomcat may hang.
3) Be meticulous about Java.lang.OutOfMemory: PermGen Space problem

Convert Spring Roo Application into a JBoss 6 Application

I have a Spring Roo app that is deploying to Tomcat with no issues. I'm trying to deploy it to JBoss 6, but I'm finding it impossible to do so.
I've exhausted all resources from Google and I simply receive errors everywhere. Unfortunately, they do not seem specific enough to start narrowing them down to list here.
What can information could I provide to help resolve this situation?
Essentially, I need to know what I need to change from a standard Spring Roo app, using Hibernate and Mysql to work with JBoss 6.
EDIT:
This is the error that I am getting
[ClassLoaderManager] Unexpected error during load of:org.apache.commons.collections.DoubleOrderedMap$1$1: java.lang.IllegalAccessError: class org.apache.commons.collections.DoubleOrderedMap$1$1 cannot access its superclass org.apache.commons.collections.DoubleOrderedMap$DoubleOrderedMapIterator
Impossible to tell, since you posted no errors.
I'm guessing that it's a problem with the configuration difference between JBOSS and Tomcat.
You set up JDBC data source connection pools differently. Tomcat has the context.xml in the server /conf folder. JBOSS has other XML config files in its server/default/deploy folder. Did you create those correctly?
I assume that you're using JNDI names for injected data sources.
Your JDBC driver JAR for MySQL goes in the Tomcat /lib folder and the JBOSS server/default/deploy/lib folder, not the wAR WEB-INF/lib.
But you should be able to take a WAR with all the Spring Roo stuff, put it into an EAR with jboss-web.xml configuration, and start it up.

java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener

I have a webapp built using spring framework. I'm trying to deploy this to Tomcat6 using Eclipse. Everytime i make a change to jsp file, I had to clean the build, publish it & then start the server. I believe, we don't have to do all these steps for JSP changes. If i just publish the files, when the server is running, i get the below exceptions
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.util.Log4jConfigListener
java.lang.NoClassDefFoundError: org/springframework/util/Log4jConfigurer
And the war file is not getting deployed in server.
If I make a change to JSP file & then click restart in eclipse, it sometimes publish the files & then start the server. But in some cases, it restarts the server & then publishes the files (in which case i got the above mentioned exceptions & the war file was not getting deployed).
Ideal way that it works is, Stop the server, publish the contents & then start the server. I hate to do this every time i make a simple jsp change. Is there any alternate one click process to do this?
There's something wrong with the way you setup your project or server in Eclipse. I'd recommend following the instructions here. Also, you may want to download STS (Eclipse already bundled with Spring support) and use that instead of the vanilla eclipse.
Make sure that spring is deployed together with your application. Either set the correct export options in eclipse or copy the spring libraries to /WEB-INF/lib.
MyEclipse works fine here. You could also check JRebel as well. They advertise no redeployments. ;)
you can use exploded war and incremental hot-deploy.
this should work http://www.youtube.com/watch?v=OMtcjgTyP-g
folow at 2:30

how do i wait for service when another service depends on it

i'm about to deploy two different but dependent war-files into a single jboss (AS 4.2.x GA)
One implements some webservices (jax-ws) exposing their interfaces through
a wsdl. The other one is a (say) web frontend using the aformentioned webservices. When I drop both warfiles to $JBOSS_HOME/server/default/deploy at the same time I can see that the first gets deployed (somehow) but the second one gets stuck and the entire jboss is not responding.
When I deploy them one after another, everything is fine (it just works:)
Is there a way to tell jboss that deployment of warfile2.war has to wait
for warfile1.war to finish deployment before starting deployment of warfile2.war?
Is there a way to determine programatically wheter a given 'service' is deployed
and ready?
I'm wonder what happens when both wars are present and jboss is restarted?
Kind regards,
Jay Wee.
To answer your last question first, JBoss will deploy the contents of its deploy directory in alphabetical order. If you drop two WAR files into a running server's deploy directory, the results are unpredictable, but should be safe, so I'm not sure what's going on there.
By the way you describe the dependency, it sounds like when a user uses the frontend WAR, it calls the web service WAR, and that on startup there's no link between the two? Could anyone be trying to use the frontend WAR while the web service WAR is still deploying? Which WAR comes first alphabetically?
As a possible solution, when you have two WAR files that depend on each other, you should consider packing them both into a single EAR file. That way JBoss will deploy them together in a controlled way.
What about implementing a listener in the web frontend waiting for a successfull head request to the wsdl on localhost?
Thats right. backend.war is deployed before frontend.war.
I deployed it on my local jboss and nobody else has acces to it.
What I can see when i debug into jboss is that the frontend accesses the backend wsdl (https://localhost:9999/app/svc?wsdl ) hangs while jboss is not ready.
\at Arne Burmeister: the listener approach doesen't help. the listener is called to early in the process: I can connect to the backendWsdlUrl but backenWsdlUrl.getConnection().getOutputstream() hangs
I think I'll give the ear a try. Is there a good documentation on how
to pack things together in an ear? (skaffman already pointed me into the right direction)
Thanks a lot to all who help so far,
Jan

Categories

Resources