7

I have a rather large project (with quite a large stack including Spring and Hibernate) that I build through Netbeans using Maven.

Unfortunately, every time I make a change to a class, I need to rebuild. This means

  • Save All & Compile
  • Run all the tests
  • Build a Massive WAR
  • Undeploy from Tomcat
  • Redeploy from Tomcat
  • Start up the Application (Spring = Zzzzzzz / Hibernate = Zzzzzzz)

This can take up to 5 minutes to check if a small change made a difference. Perhaps I have the wrong approach?

Please advise...

sparkyspider
  • 13,195
  • 10
  • 89
  • 133
  • It also drives me NUTZ that Spring and Hibernate take so long and log so much. Surely there must be a Spring lite (just using the managed beans) and hibernate lite (really just using simple annotated entities). These Java frameworks can be soooo H E A V Y. – sparkyspider Sep 19 '11 at 12:54
  • 1
    I saw that using some hardware features (Solid State Disk) with OS tuning can increase building process. You can look something like that up. – Alex K Sep 19 '11 at 13:27
  • @Alex K, The good old Java performance approach... Add 8 cores, 12GB RAM, a Solid state disk. Thanks for the tip, but I'm going to rather try configure the stuff properly ;) – sparkyspider Sep 19 '11 at 14:13

3 Answers3

6

Okay, I'm also working on quite similar setup so here are my 2 cents.

First off, get your feet wet with Maven-Jetty Plugin. Make it scan the files for changes so that you don't have to rebuild/deploy the entire project for every changes. Also configure it to store session so that with every (automatic) deploy you don't have to relogin and get to the state you were at before making changes:

    <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.24</version> 
        <configuration>
            <stopPort>9669</stopPort>
            <stopKey>myapp</stopKey>
            <!-- Redeploy every x seconds if changes are detected, 0 for no automatic redeployment -->
            <scanIntervalSeconds>3</scanIntervalSeconds>
            <connectors>
                <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                    <port>8080</port>
                    <maxIdleTime>60000</maxIdleTime>
                </connector>
            </connectors>
            <webAppConfig>
                <contextPath>/myapp</contextPath>
                <sessionHandler implementation="org.mortbay.jetty.servlet.SessionHandler">
                    <sessionManager implementation="org.mortbay.jetty.servlet.HashSessionManager">
                        <storeDirectory>${project.build.directory}/sessions</storeDirectory>
                    </sessionManager>
                </sessionHandler>
            </webAppConfig>
        </configuration>
    </plugin>

Now, go to project Properties (by right clicking project)> Build > Compile > Compile on save and select For both application and text execution.

Also go to Options > Miscellaneous > Maven > and check/select Skip Tests for any build executions not directly related to testing, so that test are only run when you actually Run 'Test'.

Following these simple steps, I can code and test changes live, quickly and without needing a redeploy. That said, I have faced a few minor issues/annoyances:

  1. You still have to clean-build at times when something does not work (for example, you deleted something and changes do not reflect)

  2. Keeping it running long time can give PermGen exception (Out of space), which is reasonable and you can always increase the memory using jvm opts

  3. you will hate to develop/test projects on containers like jboss/websphere once you get used to this setup

kdabir
  • 9,623
  • 3
  • 43
  • 45
  • 1
    Thanks so much for this post. I'll try this all. Does this work with Tomcat, or is the Jetty plugin only to be used with Jetty? Perhaps there is nothing wrong with Jetty. I'm sure it's light weight. I have no interest in using JBoss or Websphere. – sparkyspider Sep 27 '11 at 15:30
  • 1
    Initially I also wanted to use tomcat in place of jetty, but now i am in love with mvn-jetty. I have never used jetty as a server to deploy war on it, but the plugin works like magic. I think there is a plugin for tomcat too (but maven-jetty cannot run tomcat). – kdabir Sep 27 '11 at 17:23
  • Wow, now you really have me thinking. I mean, my loyalty to Tomcat is strong, and I "like" the idea of using the same server, local and live. Please tell me more about your experience with Jetty. By the way, does the maven plugin come with the Jetty plugin? – sparkyspider Sep 29 '11 at 11:52
  • Actually nevermind. I'm going to use Jetty now too. Seems like there isn't yet a reliable Tomcat solution... – sparkyspider Sep 29 '11 at 12:06
  • 1
    I thought exactly like you regarding developing/testing on tomcat when my app if finally going to be deployed on tomcat. But it hardly makes any difference for testing out while developing unless you are using some tomcat specific feature/api. Also, Netbeans natively supports tomcat hot deployment too (slower than jetty restarts though) – kdabir Sep 29 '11 at 19:38
  • YOU ARE A GENIUS!!!!!!!! Thank you!!! Now editing Java class files is like editing PHP files - in maven. Woo Hoo!!! – sparkyspider Oct 04 '11 at 19:44
  • am glad to see you so happy :) – kdabir Oct 09 '11 at 06:05
2

Give JRebel a try. http://www.zeroturnaround.com/jrebel/

BTW I'm not paid by zt - only a satisfied user.

Ben
  • 2,235
  • 18
  • 17
1

Why do you need to run the Tests on each change? That's a huge cost, when making trivial changes. Switch it off using -DskipTests=true

Take a look at : http://wiki.netbeans.org/HotDeploymentWebApplicationWithMaven

Also, setup Netbeans to hot deploy on Tomcat (use Jetty). See this post : Incremental hot deployment on Tomcat with Maven and NetBeans.

Community
  • 1
  • 1
Saket
  • 45,521
  • 12
  • 59
  • 79