JBOSS explode war file on build (hot deployment) - java

The last Java project I was on used Tomcat as the server my new Java project is using JBOSS.
I am a front-end designer that needs to make frequent and rapid changes to JSP, HTML, CSS and JS files. Here is a rundown of what is happening...
In Tomcat, when an app is deployed into the webapps directory, it is automatically exploded. From there I can stop the server, create symbolic links pointing from the webapps/myapp directory to my GIT repository, ~/somedir/myapp and then restart tomcat. This way I am always working on my local repository and when I make a change in my IDE then go to the browser and refresh, the changes are there instantly.
In JBOSS, things are a bit different. When an app is deployed into the standalone/deployments directory, it remains compressed as a .war file.
I have tried expanding the .war file manually and renaming the folder to myapp.war and that seemed to work, however, JBOSS still re-deployed the app once it noticed there was a change to one of the files, which kinda defeats the purpose.
I have been searching for a couple of days now before asking this question as a last resort.
Does anyone happen to know of a way to accomplish in JBOSS what I was able to accomplish in Tomcat?
Thank you in advance!

Related

Deploy Magnolia CMS without installing it

I'am just starting with magnolia and at the very beginning it surprised me that Magnolia needs to be installed after each .war deploy to tomcat. I do some changes in my project, deploy it with mvn tomcat7:deploy/redeploy. Tomcat automatically recognise that ROOT.war has changed so it unpack it automatically and after that when I'm entering localhost:8080 it wants me to install Magnolia modules again. Is it really necessary to install all modules again and again after every single changes in my project and deploy? Maybe the way how I'm making changes in my project and deploying it is wrong? If I'am not mistaken in that way my content changes also will be overwritten/deleted?
You have to re-install Magnolia every time because I think that you delete your repository (database) every time that you deploy a new version. Probably you are saving your data in a folder inside webapps and every time that you deploy a new .war it is deleted.
If you want to keep your website and modules between deployments, I need to change the repository location to a different folder in the file system, or set a db connection.
You can do that by modifying the repositories.xml file or adding a custom jackrabbit conf file, in this article you will find a lot of useful info, and I suggest you to have a look into the paragraph 'Custom Jackrabbit configuration file'
Have a look at documentation on how to configure your Magnolia for details, but in essence it's enough if you open /WEB-INF/config/default/magnolia.properties and change magnolia.home= to point to the directory OUTSIDE of your webapp. By default it is set to be inside of the war file so you can wipe and reinstall Magnolia easily. In your case you want your data to be permanent, so you set it out. You should still read the article linked by Daniele about how to setup your devenv and you might still want to configure different database than derby for your production use, but you should keep all your data outside of the webapp too.
HTH,
Jan

Intellij IDEA 13.1 - Where does it keep the deployed webapp files in tomcat server?

I use IntelliJ IDEA 13.1 and have configured a Java web application to deploy to a Tomcat server. After starting the server, if I go to my tomcat webapps folder, I couldn't see the exploded version of my web app there.
So, do IntelliJ keep the deployed files somewhere else other than the tomcat webapps folder?
Btw, I did check the answer for this question: Where is my app placed when deploying to Tomcat?. But I couldn't find my deployed files in the ${dir.to.idea.project}\YourWebApp\out\artifacts folder either.
Any help?
Typically the exploded war is built in your web-module's target directory (called either target or out by default depending on whether you use maven or not), with a .war extension on the folder. Tomcat (and most other application servers) are pointed at this directory.
However, you shouldn't, in most cases, need to know this. When you make a change to your code, IntelliJ will update the contents of the exploded war for you. You shouldn't really change it yourself, otherwise the code will get out of sync with the deployed app.
I'm using gradle and the deployed wars are in project_root/.build/package/modules/.
If this doesn't help,here is how I found out.
While the project is running I run the gradle clean task, then tomcat kindly complained
java.io.FileNotFoundException: /project_root/.build/package/modules/exploded/my.war/WEB-INF/lib/xxx.jar (No such file or directory)` How sweet of it.
I hope this helps!

Upate a java file in war file

I am working on a project and the project is in running state. As there is some issue in a java file and I have resolved that issue. But I don't have an idea how to update that particular java file in war file which is deployed on the company server.Please help me out.
Tomcat doesn't support hot deployment. SO you have to restart Tomcat anyhow.
And if you are going to restart it, either replace the .class file(the one which u have changed) or generate new war and then retart Tomcat. Your changes will be reflected.
Update : for hot deployment http://www.mulesoft.com/tomcat-deploy-procedures
You can replace your new java .class file into your extracted project folder under tomcat
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Reload_An_Existing_Application
This will cause a service interruption anyway, but probably still shorter than restarting the whole server.
Note that this will only works when the web application is deployed from an unpacked directory, otherwise you will have to undeploy and deploy again the web app.
(http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Undeploy_an_Existing_Application)

Can not put anything into /var/lib/tomcat7/webapps/

I was starting on JAVA web development today and encountered some problems, I installed my tomcat7 on my ubuntu machine. Now when I browse to //localhost:8080, I get the default welcome page saying:
This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/ROOT/index.html
Tomcat7 veterans might be pleased to learn that this system instance of Tomcat is installed with CATALINA_HOME in /usr/share/tomcat7 and CATALINA_BASE in /var/lib/tomcat7, following the rules from /usr/share/doc/tomcat7-common/RUNNING.txt.gz.
But strangely when I try echo $CATALINA_HOME nothing shows up.
Also I can not copy/create anything in the default /var/lib/tomcat7/ROOT though it's just a matter of providing few permissions but I was wondering whether it is the right way to do it?,
What I would like to do is create a separate directory in my home where I can put my web application and tomcat can read hem from there. Is there a way to do it? In apache I can do it by changing the document-root and directory but I don't know how to do it for tomcat
But strangely when I try echo $CATALINA_HOME nothing shows up.
This is because the packaged version sets CATALINA_HOME just prior to launching Tomcat, after reading it from a configuration file (typically somewhere in /etc).
Also I can not copy/create anything in the default
/var/lib/tomcat7/ROOT though it's just a matter of providing few
permissions but I was wondering whether it is the right way to do it?
The permissions problem has to do with you not being root (or the Tomcat user). Most packaged Tomcat installations (deb or RPM) tend to install with a specific user in mind, and copying stuff in as a different sometimes won't work.
/usr/share/tomcat7 is your CATALINA_HOME directory, and it has links to the other directories, such as /var/lib/tomcat7/webapps, /etc/tomcat7, etc. You shouldn't copy directly into a web application, you should package the web application into a WAR file and "deploy" it. The advantages are numerous.
What I would like to do is create a separate directory in my home
where I can put my web application and tomcat can read hem from there.
Is there a way to do it?
Yes, one is created when "deploying a web app". Look to the standard Tomcat7 documentation, and consider installing the "manager" web application if you like a non-command line interface. Now that you know what "installation" of a web app is called, it will likely be an easier task.
In apache I can do it by changing the document-root and directory but
I don't know how to do it for tomcat
Tomcat has a different, slightly more restrictive set of requirements for a document-root. You need to learn it, and just come to terms with the idea that it's never going to be the same. Basically under the "webapps" directory, is a WAR file or a expanded directory that came from a WAR file. Editing in-place is not a good idea for Tomcat, as the CGI-equivalents are not read from disk each time they are ran, they are linked into the memory of Tomcat. This means that a change in the directory might not affect your web application, which is good enough reason to not bother changing the on-disk files for a deployed web application.
Modify the web application, repackage it, and update the deployment. It's really the "right" way to go with Tomcat.
Give permission 777 to the webroot folder
sudo chmod -R 777 Webroot
After moving to the tomcat folder

Deploying a Spring-based WAR with its JAR dependencies externalized

I have a Spring app that has a lot of dependencies (18 megabytes of JAR files..) - Now, when I am testing on the remote Tomcat 6.0 server, I'd like to not have to upload that 19 megabytes of dependencies, and just upload the classes. Pretty simple, right?
I can't get the damn thing to work.
I'm using Eclipse 3.4, and if in Java Build Path->Order and Export I remove the export of all of the dependencies, I get a nice small WAR.
So here's what I tried:
I uploaded all of the libs to the server, and stuck them in common/lib in Tomcat. The directory didn't exist, so I created it and modified catalina.properties:
shared.loader=${catalina.home}/common/lib/*.jar
I've tried a bunch of other configs, but none worked. Restart the server, deployed war fails to start. Specifically:
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderList$java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1
It's dying trying to load the Log4J listener, which it can't find in its classpath. The spring lib that listener is in is in common/lib.
Also - when I deploy the full 18 megabyte war, it works just fine. Everything inits and the app starts. Of course it works fine locally as well.
Oh - and I've replaced the hardcoded logging JARs with the ones out of the extras folder to allow Log4j to work.
Any help here? I have no idea why this isn't working.
"I have a Spring app that has a lot of dependencies (18 megabytes of JAR files..) - Now, when I am testing on the remote Tomcat 6.0 server, I'd like to not have to upload that 19 megabytes of dependencies, and just upload the classes. Pretty simple, right?"
I don't understand this - 19MB is not a lot. You'd be much better off just packaging a WAR and be done with it.
I recommend that you do your testing locally on your own identical Tomcat instance, get it all working, and then deploy the WAR to the remote Tomcat instance.
UPDATE: One issue I have with putting those JARs in Tomcat's /lib directory is that now every app that you deploy to that instance sees those JARs - change them for one, all are affected. If you put the JARs in each individual WEB-INF/lib, you can modify each application without affecting others. The cost is duplicate JARs and disk space, which is cheap.
Another problem if you have to migrate from devl->test->prod, now every environment has to have the identical JARs deployed in order for your app to work. Miss one and you're broken. Your app depends on having those dependencies available. If they aren't on the server you're out of luck. Keep control in your own hands and package the JARs in the WAR file.
You need to be careful externalizing the dependencies like that in a web server environment. Depending on the server there can be unexpected class-loading issues even when it seems to start up fine.
I agree with duffymo... 19MB is not really all that big... is there some reasoning behind wanting to do this? I wouldn't recommend it.
find the webapp folder
upload the files direct into the folder
for example
/path-to-tomcat/webapp/myapp/
keep the /path-to-tomcat/webapp/myapp/WEB-INF/lib folder and upload the changes to ur /path-to-tomcat/webapp/myapp/classes folder
then use tomcat manager to restart the app
I second the suggestion of sending updates directly to ${CATALINA_HOME}/webapps/<your-app> on the target server. WARs are for production deployment, but if you have a slow connection and a large WAR that's no fun.
You'll want your web app to restart after the update, of course. Tomcat in development mode will monitor a few files for changes; by default WEB-INF/web.xml is one of them, so update that along with whatever else you're updating and you should get an app restart soon. In a pinch, you can use the Manager web app to kick the app awake.
For more control and convenience, you'd eventually do well to use the Tomcat ant tasks (found near the Tomcat distribution, not included with ant!) to restart the server, and perhaps to deploy your changes as well. Takes some fiddling but this is well worth it as you'll want to re-use it for each project you do.
Is WEB-INF/lib empty?
Where is log4j.jar?
Where is spring.jar?
This looks like classloader visibility problem.
Listen to duffymo and cjstehno.
Adding jars to tomcat's is a sure recipe for disaster.
Keep your jars in your webapps directory.
It is strange that Tomcat can't find the jar files. Anyway, place all jars in the common folder (${catalina.home}/lib). (This is even worse than using the shared.folder, but it should work for you).
Of course, like others said, you shouldn't do that in your production system. I believe that is OK for a development system though - especially if you need to do extensive testing with the production system anyway.
Another note: you should only do this if you have full control of the server and you are the only one installing applications.
Why would you change the default ${shared.loader} property of tomcat?

Categories