I'm creating a web application that uses Apache Tomcat (Latest), Spring 3, Struts2 and Hibernate. I need to have a listener that observes a directory for any new XML files that appear. While the web application is deployed onto Tomcat and running it should keep doing this.
What method is recommended when doing something like this, using these frameworks?
Are there any examples that I can look at to assist with the beginning stages?
Try jdk7 WatchService. I have already done it a project which has a similar structure to the one you have. Otherwise you could try to use FileAlterationListner from org.apache.commons.io. I would rather go for jdk7 as it worked perfectly.
i have used JNotify in one of the project, it worked like charmed, if switching to JDK 7 is not possible.
Related
I need help here with the below issue. I am learning JMS and I am quite new to it. I came across a tutorial which I was following, however when I try to run this by selecting the project in eclipse I do not get an option to run on server. Is there a way we can run a simple java application on application servers?
Below is the link to the tutorial I am following
https://www.javatpoint.com/jms-tutorial
I have mostly worked with dynamic web projects for which the option is present to run on server.
I have not posted the code as it's the exact same as given in the tutorial.
For that you need to figure out which server(s) you want to deploy JMS. You can go with Weblogic or with ActiveMQ.
Below are the 2 reference links that would actually help you to resolve your query :
http://www.catgovind.com/java/test-weblogic-jms-java/
https://javainsider.wordpress.com/tag/jms-with-activemq-sample-example/
Yes, I would suggest you to go through spring-boot.
Here, you have an option to try a simple Hello World application
http://www.mastertheboss.com/jboss-frameworks/spring/your-first-jms-application-with-spring-boot
In the above example, you just have 2 java classes and one maven pom xml file to edit :)
Just try it out.
You can configure it to run from your eclipse too.
In/with spring-boot -
you don't have to do any web-server configuration on your own. Spring boot itself contains a web container.
It just creates a JAR file with which you can just run your application as "as your run a jar" which has your code + server.
And my last point is - you will get lots of support from different forums as spring boot is used widely.
I am in a project which uses hibernate, spring, and apace camel as third party tools. To launch the project I create a war file using maven and then run it using Jetty (jetty-distribution-8.1.14.v20131031).
Now I am supposed to add a new simple functionality on the project startup. It can be something as simple as adding a print line, but there is no main() function.
I have the output lines that the project printed to a file:
http://paste.kde.org/pnhee4u7s
I have read the file but all I see is calls by hibernate, apache and spring. All are third party tools. I have no idea how to do this, and I appreciate any possible help :s
If you're writing a Web application with a war, start with your web.xml; if you're using traditional configuration, that's where Jetty starts loading your app.
Since you're using Spring, I recommend writing an #Component that logs on startup, or adding such logging to an existing component or #Configuration.
Is using JSP Hot deployment a solution to publish new or updated content to avoid restarting the Java EE server (cannot hot deploy jar)? I should not use JSP to code a lot of java, but do I have any other solution?
With Tomcat, you can use the Parallel Deployment method. You will be able to deploy your new version and keep older one running with every users that has a session on it.
It is really simple when you are using WAR files, I recommend a simple script to delete older versions after couple of days for exemple, just to keep only few running versions.
You can get more informations here : http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Parallel_deployment
Did you have a look at JRebel yet?
I want to get a development experience like I get with Play! framework with JAX-RS (with Jersey for example). More specifically I want to use some kind of background compilation and run the compiled code immediately so that I have almost no waiting time.
My first attempt was to use NetBeans background compilation and Maven with plug-ins for Tomcat and Jetty which are restarting the application in the running container. But restarting took too long. I'm wondering if I need to restart the application if code changed or if something like Grizzly or Netty instead of a Servlet container would help.
Any ideas how to get fast reloads with JAX-RS?
Try this,
you need to add the dependencies. It uses jreloader (open source).
ant archetype
Edit:
People are still visiting this post after two years. Now there's a complete alternative for hot reloading and the project is active again http://dcevm.github.io/
You may need to use this as well https://github.com/HotswapProjects/HotswapAgent
Take a look at gretty: https://github.com/groovypp/gretty
It should work with jersey and you should see fast runtime reloads.
JRebel does this: http://zeroturnaround.com/jrebel/
We just discovered that every time we restart JBoss, all of our Java Web Start clients redownload all of their jars, instead of reusing the cached jars, even if our application has not changed.
From what I've seen on the web, Java Web Start does an HTTP HEAD to decide whether or not to download a jar. So I ran HTTP HEAD on all jars in our application, and discovered that after restarting JBoss, the modified time of all the jars has changed!
Why is this, and how can I fix it? The jars inside of my application archives have not changed at all. As near as I can tell, JBoss uses the time of startup or time of deploy as the modified time. This is going to completely short-circuit Java Web Start's ability to use cached jars from previous runs, if I understand correctly.
We use JBoss 6, if that's an issue. Previously we used JBoss 4. I want to check to see if we had the problem under JBoss 4, but we now have so many dependencies on the newer JBoss that it is going to take some work to make that test happen.
Try deploying your application as an exploded web application instead of a WAR file.
That would prevent JBoss having to decompress the application and potentially mess up the modification dates.
You'll have to handle updates to your app in a way that preserves modification dates, e.g., rsync, but that might be easier than downgrading or patching JBoss.
It looks like VFSUtils isn't maintaining the lastModifiedDate of the file when it mounts the filesystem to the tmp directory on server startup. You could patch the copy methods in that class to try to set the timestamp of the new file based on the values from the physical file.
As a response to the comment by chubbard: the problem does not occur with Tomcat (tomcat 7.0.21 to be precise).
There is an issue (https://issues.jboss.org/browse/JBVFS-177) created about the VFSUtils.unzip() which does not preserve timestamps while deploying (still applicable to JBoss 6.1).
As the issue is related to the unzip method the solution of blahdiblah may indeed works.
Another way would be to use Java Web Start with a version based (Modification of the jnlp with versionEnabled and creation of a version.xml).