How can i hot-deploy my Java project? - java

I work in a team of Java developers. We write the code in Eclipse, and then we use maven to build the war. Afterwards we deploy the war in Tomcat.
Is there a free way to autodeploy files on save ?
Thanks.

JRebel gives you exactly that: auto-deploy files on save, using Eclipse AND Tomcat, but you do have to pay for it.
I recommend JRebel, but a quick glance around for free alternatives brings up this SO question, where someone suggested the Dynamic Code Evolution VM as a similar product.
There is a good article on the different ways to hot-deploy Java web apps here, which also details some of the other approaches already mentioned.

If you want to deploy for testing purpose on your developer machine, you should use the Tomcat Maven Plugin or, better the Maven Jetty Plugin (it's better because it's lighter and faster).
If you want to deploy it on a remote server, say at every commit on your SCM you must use Contiuous Integration tools like, for example, Jenkins or Apache Continuum.

If you have your class files, you could put them in WEB-INF/classes. Is that what you were looking for?

You can use the maven jetty plugin

Don't build with maven, use exploded deployment, so that static UI files and JSPs could be picked up automatically by the container. For reloading changes to classfiles, you can run the application in debug session and use hotswap (which allows you only the changes to method bodies) or overcome your demand for free software and buy yourself a JRebel license, which can be used for free on non-commercial projects (http://social.jrebel.com)

Related

DataSource Deployment Tool

Reading this tutorial on DataSource the text keeps saying thins like:
The system administrator would typically use a deployment tool, so the
code fragments shown in this section are the code that a deployment
tool would execute.
I have no idea on the deployment tools available, could anyone point me out the top options?
I am using Tomcat for my web application.
When a web-app has to run in the J2EE environment, it typically is done using a server like Tomcat (as you are right now doing in your application).
Now, apart from just placing files in a directory, a web-app requires a number of other steps to be done, before you can access all the intended functionality. For more on what deployment is and how to assemble your files, refer here
That said, J2EE evolution and the emergence of many web-servers has over the years resulted in simplifying the deployment using batch files for example or APIs. These are what your article is referring as deployment tools. For Tomcat specifically, the detail can be found here
Hope this helps you with the bigger picture of J2EE application management
I think the author is talking about java deployment tools. Below are the few deployment tools I'm aware of,
jenkins
go
bamboo
These java deployment tools typically need configuration/orchestration tools to streamline the configuring and maintaining applications and the hosts. Below are some tools which does this :
ansible
Chef
For dependency, build and project management, maven and gradle are widely used.
To generate config files for different environments,xslt transformation language can also be used.
I might have missed many deployment tools, but these are more popular in java realm.
With the help of these tools, a system administrator can manage the deployments without having any working knowledge of programming languages.
Hope this helps!

JRebel vs IntelliJ - hot swap

I'm looking at getting JRebel licenses for my company.
However I just found out that IntelliJ already has a built in functionality to hot deploy classes.
At the moment we are using Netbeans and Eclispse and I'm wondering instead of buying JRebel licenses if we should just buy IntelliJ.
I tried a trial of IntelliJ (13.0.1) and the hot swap features seems to work fine (using JBoss AS 7.1.1). Only small details it seems that you have to manually compile the class that has been modified for IntelliJ to replace it on the server. JRebel does that automatically.
Now my question is for experienced user of IntelliJ and/or JRebel.
Is it really useful to have JRebel if I already have IntelliJ? Is JRebel better if I'm mostly interested in hot-replacing my classes?
All feedback/experience/advice welcomed.
For an environment like you described (mostly java EE 6 on JBoss 7 or later. Frameworks: JSF, Primefaces) the way to go is definitely JRebel.
Hotswap is capability of JVM, you can find comparison of this with JRebel on their website (http://zeroturnaround.com/software/jrebel/features/comparison-matrix/). So you can use this independently on your IDE.
The main advantage of JRebel is support for various frameworks and their lifecycles - e.g. when you change a bean class jrebel will reinitialize spring bean and all beans which depend on it - with hotswap you would need to redeploy because constructor/initialize method was already run.
I am a happy jrebel and intellij user (also used jrebel with netbeans successfully), no relationship with zero turnaround, angry at them for removing personal dev licenses.
IntelliJ does not have better hot swap than Netbeans or Eclipse, it is simply a matter of JVM. You can try DCEVM integration plugin, which have really good hot swap, in some cases even better than JRebel. But if you need support for frameworks like Spring, JRebel is the way to go. I recommend trying both before buying anything.

Agnostic automated deployment

What do you use to automatically deploy applications for various kinds of server applications (web, socket, daemon) that uses various technologies (different DBs, languages, etc)?
Here we use Python, Java and Ruby, and may use other languages as well in the future.
Update: I ended up using Puppet to manage all server setup, configs AND deploy. To trigger the deploy of newer versions I ended up using Python Fabric scripts.
I use Puppet for some of the deployements / initial configuration of server. Maven and Ant for Java based projects.
You could use Ant, Makefile, or a batch script. Or a combination of them.
Go for KWateeSDCM. It comes with a straightforward web GUI and does not require obscure scripting and integrates nicely with your build chain via a REST API.
We use Maven and pull out to the ant-plugin when required. In turn the ant-plugin very occasionally calls out to some native scripting language/application/packager/whatever but we're finding that over time we can generally find a Maven or ANT plugin/task to do the trick.
You might want to look up Continuous Deployment, it's a pretty hot topic in the build and CI space right now.
For Python you could use Fabric or Paver
For Ruby, there's capistrano and 'vlad the deployer'
For Java, it's the Ant.
For PHP/Python projects I also use Peritor Webistrano, a neat frontend for capistrano. It involves changing a few of the default recipes to remove the rails-specific stuff, but it's worth it once you get it setup correctly.
I think the best choice you could do is using maven. Even if maven is mostly used for Java projects, you can with the right plugins (or the one you write) deploy anything anywhere.
you can use maven, ant, ivy along with hudson for java projects.
We use Ant or Maven for different projects we have in house (depending on the need and how old the project is too...). We tend to use Jenkins (formerly known as Hudson) as our build and deployment tool.
And then we encourage developers to write code that does not hard code to DB's, URL's, etc. We try to abstract via the container (ie, Data Sources, pure JMS API's, etc) when running within an app server. And we tend to abstract environment specifics via properties files that we look up at runtime. The path to the properties file is to be defined as a variable on the server. This way we can be flexible enough to build code once and move it through to all our environments.

Automatic VM deployment

I have an idea to streamline deployments of prototypes within our team using VMs. The idea would be that a developer would be able to deploy their artifacts to Maven, then use a Web interface to pull them onto a development VM for integration/regression testing. They would then be able to to push those artifacts to a reference system, and finally onto production.
I'm currently thinking of doing this myself using the vSphere Java API ( http://vijava.sourceforge.net/ ), and some simple scripting to grab artifacts from the Maven repository, configuration from SVN, and then start up a JBoss server. It feels like the kind of thing that may already be available though, has anyone heard of something similar?
Isn't it the thing that Continuous Integration is made for? We have done similar stuffs by using JetBrains TeamCity and Jira Bamboo.

What do I need to write Java-based web applications and test them on my personal computer?

I currently have Apache HTTP Server, but I'm guessing I'll need Tomcat (and then have to configure it in a way that makes it not open to the public), a Java JDK (which I already have, but should probably update), and an IDE (I have Eclipse). But what else should I have or know before starting?
Lets see... you'll need:
A JDK. Preferably the Standard Edition, unless you plan on using GlassFish as a J2EE server. If you do use the standard edition, you need to include the jars from your servlet container/J2EE stack to access J2EE libraries.
A Servlet container. Apache Tomcat is a popular one, and Eclipse already has integration support for it. Keep in mind that Tomcat is not a complete J2EE stack... you need something like JBoss Application Server or Apache Geronimo for that.
(Semi-Optional) A web server. Apache Web Server surprisingly works well with Apache Tomcat or Apache Geronimo... it's almost like they were made by the same people! Eclipse has built-in support for Tomcat and doesn't appear to require a web server because of it. I could be wrong, though.
(Optional) An IDE. If you use Eclipse, get the version for Java EE Developers.
(Optional) A Database. MySQL and HSQLDB are popular ones for Java, at least for small to medium applications. Keep in mind that you also need to download the JDBC drivers for your database.
(Optional) A revision control system. Even on a single-developer project, a revision control system can save your hide if you accidentally remove code or a file that you shouldn't. There are several choices here; Subversion is my personal choice, along with an Eclipse plugin for it, such as Subclipse.
I'd recommend having a database server installed as well- you can go pretty far with the various pure Java implementations, but anything significant will probably benefit from having a copy of MySQL around.
I'd also get some sort of version control going- tortoiseSVN works really well for windows. Even if you're just goofing around for yourself, getting in the habit of using it will save time and heartache down the road.
If you're trying to stay pretty simple you have everything you need; a servlet container.
The IDE of course helps.
I would recommend Eclipse's Web tools project as it will allow you to code, and then hit a button that will put that code on tomcat all from the IDE.
http://www.eclipse.org/webtools/
As Bogdan mentioned maven is a dependency management tool but depending on your level of comfort I'm not sure if you want to muddy the water with that yet.
Another project that uses Maven is appfuse (http://appfuse.org/display/APF/Home) and will help you get off the ground quickly for generating a webapp. It will give you a webapp, a database, unit tests, dependency management, and a good skeleton to structure your project off of.
So, if you're just wanting to play around with some .jsps and a servlet or two I would stick with the IDE, but if you're comfortable with web applications, MVC, and build tools I'd recommend appfuse.
That's all you need from the tools.
Then, you need to google some tutorial on using servlets and jsp pages. Even documentation bundled with tomcat is good enough.
You'll probably also want a database like MySQL or HSQLDB. You could replace Tomcat with Jetty which is often easier to get class changes to reload without restarting the server.
You can do everything from within NetBeans if you're willing to switch IDEs (it's a relatively painless switch, but you might be able to create a similar setup in Eclipse). There's a Tomcat plugin for NetBeans that allows you to create, edit, run, and debug servlet and JSP web apps all from within NetBeans. There's a starter tutorial here. When you install the Tomcat plugin, you get lots of good example servlets and JSPs as a bonus.
I would go for maven.
It will give you a quick start in configuring your project (by using archetypes) and it will manage your dependencies.
Install it and run the archetype command to create your project.
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
After that just use the maven eclipse plugin to configure your eclipse environment for that project (http://maven.apache.org/plugins/maven-eclipse-plugin/).
I currently have Apache HTTP Server, but I'm guessing I'll need Tomcat (and then have to configure it in a way that makes it not open to the public)
For simple Java based web applications, you need not have Apache installed unless you are too concerned about performance and want to gain by letting Apache serve static resources.
But what else should I have or know before starting?
A good IDE is most recommended, otherwise the development will become painful. Use a simple database as people have already suggested. I would go with MySQL because its neither too complex for a webapp nor too trivial.
Instead of Tomcat I recommend Jetty, that is also a Servlet-Container. In my experience it's easier to setup and maintain. Good enough to test your application.
Other than that you need a JDK (naturally). A database is optional, but if your web-app wants to save data it's the best option.
Step 1:you need to have J2EE installed in your system if not download it from http://www.oracle.com/technetwork/java/javaee/downloads/index.html here.
Step 2: Should have Apache TomCat server to run your web project on your system locally(local Server).
installation steps https://www.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html go to this website.
Step 3:set Class path for java JRE.

Categories