Matt RaibleMatt Raible is a writer with a passion for software. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.
You searched this site for "matt". 663 entries found.

You can also try this same search on Google.

What should we do with Tiles?

There's some discussions taking place on the Struts Developer Mailing List about what to do with Tiles. Tiles is gaining popularity in frameworks other than Struts - i.e. Spring and JSF. Personally, I don't mind that Tiles is buried deep inside struts.jar b/c it's basically the difference between a 500 KB JAR and a 100 KB JAR - and disc space is cheap! However, an advantage of extracting Tiles from Struts is that it then has the opportunity to become friendlier to other web frameworks. I'd even like to see a Sitemesh-like Filter so you could do Sitemesh stuff with Tiles. Or maybe just bundle Sitemesh with Tiles as a kick-ass templating engine.

So the question is: What should we do with it? Should it become a Jakarta Commons project or a Jakarta Project? Or even a java.net project? Tiles Users - we need your feedback!

Posted in Java at Apr 28 2004, 11:35:00 AM MDT 16 Comments

Goals for the week with XDoclet, Spring and AppFuse

I have a lot that I want to accomplish this week. Hopefully a few late nights will make it possible. I'm posting this list here in case someone has already done some of this.

  • XDoclet: duplicate the Struts-specific <validationxml> Ant task for Spring. Make it work with POJOs. This is primarily motivated by the fact that I got the commons validator stuff to work just like it does with Struts.
  • XDoclet: create a new <strutsform> task that doesn't depend on ejbdoclet. This will allow me to remove AppFuse's dependency on j2ee.jar.
  • Spring: extract the mock objects used in Spring's internal test suite so I can use them to test Spring Controllers (springtestcase? ;-)).
  • AppFuse: finish Spring MVC integration and release 1.5 beta.

Phew - it's gonna be a rough week with very little sleep. Fortunately, it'll all be worth it if I can pull it off.

Update: Sometimes things just click: generate validation.xml for Spring and generate ActionForms from POJOs w/o an EJB dependency. I also discovered that <hibernatedoclet> requires that xdoclet.modules.ejb.EjbDocletTask is in the classpath. It doesn't make sense, but the compiler doesn't lie.

Posted in Java at Apr 25 2004, 04:02:15 PM MDT 3 Comments

Logout your users automatically after their session times out

One of the common issues I see in webapps is a user leaves their computer, their session times out, and when they come back to do something - the app throws errors b/c their session is null. There are several easy ways to fix this. If you use Container Managed Authentication, the user will likely be prompted to do login and can continue as before. If you're using a slick Remember Me feature (like AppFuse has), the user won't even notice. However, you might not have these options available to you. For those circumstances, I recommend you put a meta-refresh in your app to automatically show the uses a timeout message when their session expires. It's as simple as the following:

<meta http-equiv="Refresh" 
  content="${pageContext.session.maxInactiveInterval}; url=timeout.jsp"/>

I used JSP 2.0's EL in this example for simplification. If you're using a JSP 1.2 container - you'll have to wrap that expression with a <c:out> tag.

Posted in Java at Apr 24 2004, 07:33:10 AM MDT 8 Comments

Full Time vs. Contract

I talked with some folks yesterday about joining their company as a full-time employee. Their opportunity sounds awesome: using open source tools to develop a product. The opportunity certainly appeals to me. In a sense - I could get paid to work on AppFuse. I could get paid to do the stuff I wake up early and go to bed late for. I could spend more time with my family because I'm doing my "moonlighting" stuff during the daytime.

At least that was their sales pitch.

In reality, no company in their right mind is going to pay me to work on all the open source projects I contribute to: AppFuse, Roller, Struts Resume, Struts Menu and DisplayTag. Sure, they might allow me to work on AppFuse and Roller for a few hours a week, but I can guarantee that I'll still want to contribute to the others - and hence, continue to burn the midnight oil. I've also started to think that the main reason for doing stuff "after hours" is because I spend my evenings with Julie and Abbie - whereas I used to work in the evening.

More than anything, the opportunity really got me thinking about doing full-time work vs. contract work. I've been doing contract work for almost 3 years now - and I've only had 2 months of no work in that 3 year period. So that whole contracting is so unstable has been a myth for me. In fact, I see contracting as more stable than an employee position because I control my own destiny for the most part. NOTE: This post is likely a bit biased because my contract just got extended until the end of the year and I'm working on an AppFuse-based application. In other words, I love my job right now.

The thing I enjoy the most about contracting over full-time is freedom. I am planning to take 7 weeks off in the next few months (3 weeks for Spring Live, 4 weeks for the new baby) - and with a full-time gig, that would be impossible. I also like the ability (again, this is probably because my current client is so cool) to take a week off to attend a conference, or take a few days off to run off and do some training. The fact that I'm not tied down to one client/company is awesome. With the full-time opportunity I'm considering, I feel like I'd be marrying a woman I met just a few weeks ago. I guess most full-time gigs are like this after you've been set free with contracting.

One of the main reasons I'm considering this full-time gig is because I don't know where I want to be in 5 years. Most of my career aspirations have been met. When I started in this industry, I wanted to gain enough knowledge about what I do to speak at conferences and such. I did that last week and it was a blast - but I don't really want to do that every month - especially if I have to travel. Traveling away from my family is no fun - and happiness is more important than anything. The nice thing about the full-time gig is that its centered around a product, rather than services. Services (i.e. consulting) are great - but they're only good as long as I'm capable of working. Developing products that earn money while you're on vacation - that's the ideal situation.

The only thing I don't like about my current contract is that I'm a lone wolf. I'm the only guy developing the current app - which is great, but there's no "team spirit." My favorite job ever had awesome team spirit. This opportunity is a startup, which often leads to team spirit - but they also enticed me with ideas of working with a smart bunch of developers. If you've ever worked with smart people, you know that this is a real treat. Learning from your peers just by going into the office is quite a rush. When someone tries to find their answer on Google before asking you - it's refreshing. But is this worth giving up freedom for?

Another important consideration is compensation. Contracting tends to pay 50%-100% more than a full-time position. Of course, this full-time opportunity has options (which supposedly narrows the gap), but we all know that those rarely come to fruition. And if they do - it usually takes a couple of years. I am well aware that a cool job is waaayyy better than a good paying one, but still - getting paid well is nice.

Lastly, to throw a wrench into everything, someone sent me an e-mail last night suggesting they might (someday) be interested in paying me to do full-time AppFuse development. Heh - now that sounds like the ultimate dream job.

Posted in Java at Apr 21 2004, 04:53:32 PM MDT 18 Comments

How does your MVC framework handle duplicate posts?

One of the problems that you'll often see in webapps is that when a record is added - hitting refresh on the browser will cause a 2nd record to be added. This is because the "Save" action usually does a forward, rather than a redirect, and the full post is re-created. I'm curious to know how other MVC Frameworks handle this issue, particularly Spring, WebWork, Tapestry and JSF. In Struts, it's pretty simple to solve. When the form is first displayed, you'll likely go through an Action. In AppFuse, this would be something like UserAction.edit(). In the edit method, you add a saveToken() call to put a token into the session:

// edit method - mark start of operation
saveToken(request);

Then in the save() method, you can check for a duplicate post using the isTokenValid() method:

// save method - check for valid token
if (!isTokenValid(request)) {
    // duplicate submit, continue to success mapping
    return mapping.findForward("success");
else {
    resetToken(request);
}

How does your Java MVC framework handle this? Do you have to programmatically handle it like Struts - or is it built-in to the framework to handle it auto-magically?

Posted in Java at Apr 20 2004, 11:36:29 PM MDT 22 Comments

Performance Tuning J2EE Applications deployed on MySQL

Last week I attended Mark Matthew's "Performance Tuning J2EE Applications deployed on MySQL" at the MySQL Conference (see Anthony's Review). Mark's presentation had a lot of tips and tricks with the MySQL JDBC Driver. I asked him to send me a copy - and he did. Below are a number of tips that you might be able to use in your apps. One thing that Mark forgot to mention (he did later over beers) was that MOST apps (with less than 50 tables) won't need this stuff. You should probably only performance tune your server (or JVM) if you *really* think it's not your app or database. The database, and its indexes, is the first thing to check for slow performance.

  • To get JVM Metrics, i.e. Heap/Garbage Collection stats, add the following to your java command:
    -verbose:gc -XX:+PrintGCTimeStamps
  • The default JVM heap size is 64MB, which is likely too small for most webapps. You can change the default min/max by adding the following to your JAVA_OPTS (or CATALINA_OPTS) environment variable:
    -Xms128m -Xmx256m
  • Young generation sizing - let the JVM do it by specifying:
    -XX:+AggressiveHeap
  • Connection Pool Size: 15-20 is more than enough to handle an average application. Never have more connections than threads that can use them. For MySQL, the pool size is resource throttling, not saving connection setup time. Click here for a chart that shows the number of connections used doesn't change between a pool size of 10 and 20.
  • Connection/J 3.0 is 40-400% faster than 2.0.14 depending on the situation - use the latest driver!

Finally, here is the really good stuff. Below are a number of parameters you can add to your JDBC URL (like autoReconnect=true) to get information from MySQL's JDBC Driver:

  • Logging Slow Queries: logSlowQueries=true and slowQueryThresholdMillis=n (2000 default)
  • Reporting Performance Metrics: gatherPerfMetrics=true and reportMetricsIntervalMillis=n (30s default)
  • Usage Advisor (abandoned objects, un-used columns in selects, incomplete ResultSet traversal): useUsageAdvisor=true

Reminder: if your app doesn't have performance issues - you probably don't need to modify anything. Mark said he'd put his presentation online soon, so I won't bother doing that. I'll try to link to it when he puts it up.

Update May 25th, 2004: Mark notified me that his slides have been posted.

Posted in Java at Apr 19 2004, 08:44:25 PM MDT 2 Comments

New PowerBooks

Apple's New PowerBooks (announced today) don't impress me. Sure it's great that you can get a 1.5 GHz processor now, but I want more. I want at least a 2 GHz PowerBook. Why? The simplest reason is easily demonstrated by the following numbers - comparing my 2.6 GHz Windows XP Deskop to my 1.33 GHz PowerBook.

AppFuse TargetPowerBookDesktop
ant compile 44 seconds 25 seconds
ant test-all 6 minutes 7 seconds 3 minutes 18 seconds

Most Mac Heads will probably cry "compare the Dual G5 and see what happens!" I tried doing this at the MySQL conference last week, but the G5s didn't have internet access so I couldn't download Ant and AppFuse to test it out. Regardless, even if I was able to test it out - the G5 is a Desktop - and I want kick-ass speed in a laptop. You can certainly buy speedy Windows laptops.

This post is not meant to be a bash on PowerBooks - I love my PowerBook and I think that Apple makes the best damn laptop hardware out there. I just wish that Megahertz did matter to Apple and they'd give us a faster laptop. Then again, I'm pumped that these PowerBooks are not G5s, 'cause then I'd want one... ;-)

BTW, I tried Jikes 1.20 to speed things up and AppFuse won't even compile. The problem seems to be a bunch of ".class has an invalid format" errors from Cactus. Sorry Jikes, you failed the 10 minute test.

Posted in Java at Apr 19 2004, 09:28:59 AM MDT 10 Comments

My Review of Java Studio Creator (a.k.a. Rave)

I attended a Rave Demo at Sun in Broomfield today. The meeting actually had two parts - the first hour was a marketing schpeel about Sun's Enterprise Java System and the second hour was a demo of Java Studio Creator. The first hour was boring and very marketing esque - they did have an interesting price point though - $100 per employee. This is small business friendly, which is nice to see.

The Rave (a.k.a. Java Studio Creator) Demo was when things got good. Here's my notes from Dan Robert's presentation, followed by my impressions and comments. Dan is the Product Manager for JSC and was seemed to be very in tune with the tools marketing (i.e. all the good stuff from Intellij and Eclipse - and how JBuilder sucks).

What is it?

  • New Java Development Tools initiative
    • For the corporate developers who write code, but don't understand all of the complexity of J2EE and just need to get their job done.
  • A full fledged Java IDE
    • Visual Design Tools, 2-way editing, Editor, Debugger, Repository Management, and Project Management
    • Cool new Look and Feel
  • Complementary to NetBeans and Java Studio
    • Even Enterprise developers can use it for Rapid Prototyping
    • Use Java Studio or any other tool to add persistence layers (heh, this is b/c they think that persistence can only be EJBs ;-))

What does it do?

  • Quickly builds web applications that solve time-critical, real world problems
    • Complete web application creation for departments, workgroups and businesses of all sizes
    • Focus on easy to understand, event driven coding model
    • Simplifies access to existing infrastructure
    • All Java-standards based servers, all databases, all Web services, all desktops
    • Their main goal is to do web applications well, they'll catch up with the rest later

Standards-based solution for all developers

  • A development solution based on 100% Java standards
  • Delivers "Write Once, Run Anywhere"TM benefits: portable apps, portable developer skillsets
  • Quickly solves time-critical app development needs
    • Drag and Drop, rapid visual access to databasess and web services
    • consistent UI look/feel/behavior across all apps

Visual features to speed development

  • Palette for widgets, custom graphics, code clips, etc...
  • Query Editor

Simplified Access to Existing infrastructure

  • Use any JDBC Compliant Database (3.0)
    • Drag in and automatically create DB connections to data-aware components
  • Web Service Consumption
    • Easily pull in existing web services from Enterprise wide solutions or business partners

Java Studio Creator Roadmap

  • Hammerhead:
    • 2-tier dynamic content web applications based on JSP and JSF with Page Flow design tools
    • Releases: Early Access Spring 04 (today!), FCS Summer 04 (at JavaOne)
  • Thresher:
    • Minor Update Release
    • Focuses on Ease of Development and Stability
  • Mako
    • Extended Client Support

Download today from http://www.sun.com/jscreator. OS X version will be available shortly after the release (JavaOne).

After the PowerPoint, Dan started into the Demo. The first thing I saw that was cool was that when he clicked on the "Run" button, it actually deploys the app and opens the browser to run it. What you see in the browser looks very similar to what you see in the IDE. The IDE looks very simple. My current client went with me and he remarked that it "looks a lot like Eclipse."

The IDE has lots of palettes, and the UI essentially looks very clean. The pallets can be docked just like in IDEA - which I like. It looks a lot more like a native Windows application than it does like Swing. Here are the palettes it has:

  • Server Navigator
    • Data Sources
    • Web Services
    • Deployment Servers Palette
  • User Defined
    • JSF Standard Components
    • JSF Validators / Converters
  • Property Sheet
  • Project Navigator

Dan then dragged a drop down component and a table component onto the page. Secondly, he added a stylesheet and it visually changed the background and fonts on the page. I asked him if there was an imbedded browser. He said they took a look at using Mozilla, but it was too much and apparently one of the "real smart" engineers wrote the embedded browser component from scratch. Dan said it was the same guy who wrote the demo from scratch in 2 minutes at JavaOne last year. The thing I found very cool was that the HTML that is written into the JSP is XHTML - none of this Netscape 4.x support. Fuck Netscape 4.x - I'm glad Sun had the foresight to drop support for it.

After adding the stylesheet, Dan used the Data Sources navigator to grab a table and drag it to the drop-down. Then he did the same for another table and the data grid. Using the Visual SQL Query Builder (which looks a lot like M$ Access) he linked two tables and added a new column from a 2nd table to the grid. He then showed us that JSC has pretty good support for 2-way editing. Edit the code, the visual representation changes. Edit the visual, the code changes. This seems to be a big problem with WYSIWIG editors, especially when it comes to dynamic webapps. It appears that they've done a pretty good job to solve this.

Next he showed us some cool features of the components. For the table, there is an "enable paging" checkbox - and for the drop-down, you can right-click and select "auto-submit on change." He then set a couple of converter types on the drop-down and had to hand-code the event handler for the drop-down. Two lines of very simple code and he was done. The code was simple enough that you could have guessed the syntax. Code completion popped up nicely as well. Apparently the JSF coding style is that each page (JSP) is backed by a Bean that contains different event handlers. The code looked pretty simple and all the data was retrieved via RowSets.

Bill Dudney was there and asked about testing tools (i.e. Cactus or JUnit). Dan's response was that these are usually used by more advanced Java developers and there's talk of it, but nothing has been done yet. Now he pulls up a very cool page navigation creator which he uses to drag and drop buttons and links to point to different pages. Then someone asked about cost - and here's what makes it great. Under $300. They also hope to have lots of add on components for JSF by JavaOne. Unfortunately, there's no tooling for building JSF components in Java Studio Creator. For more information checkout http://developers.sun.com/jscreator.

The main reason I really like Java Studio Creator was that you literally never had to see any JSF code - and you get all of the features I like to use in webapps. Furthermore, I've been training a couple of guys all week on JSPs and using JSTL's SQL tags to do CRUD on a database table. While it's simple stuff, since they've never done web development before, it's a bit advanced. I'm sure their eyes will glaze over tomorrow when I start showing them how to write JUnit Tests, DAOs and how to use Hibernate to CRUD an object. They'll probably fall asleep by the time I show them how to wire the DAOs to Hibernate using Spring. When they saw this demo today - there eyes lit up and they got inspired to do their projects again. It looks easy for them now. All they need is a JDBC 3.0 driver for DB2 and they should be able to rapidly develop webapps with Java Studio Creator. I don't blame them for wanting to use this tool - it greatly simplifies things.

After the meeting, I asked Dan about transactions and if it was possible to use Hibernate instead of the RowSet stuff. He said that since JSC is based on NetBeans, you could probably write a plugin to use Hibernate instead of RowSets. As far as I know, the main reason you'd use Hibernate is for caching - but rowsets probably have that too. I know that the spec lead for JSF is talking to the Spring developers about JSF-Spring integration, so maybe that will be a future option as well.

Another thing that's not currently supported is the use of great technologies like Tiles or Sitemesh. Sitemesh integration would likely be pretty easy - you'd just never see your decorated UI in the IDE. Tiles is definitely something on the roadmap, but they don't have a solution yet. Dan indicated that using "includes" in your JSPs should work just fine - rendering in the IDE as they would in your browser. Good stuff - I hope we start using it at my current project - I think it'll do wonders for productivity. Since it's based on standards (JSF and RowSets) - the generated code looked pretty clean too.

Posted in Java at Apr 08 2004, 10:12:34 PM MDT 20 Comments

Make your JUnit Tests run faster when using Spring

JRoller is down, and has been down for an hour or so - so I've decided to post this Spring Live entry here.

I discovered an interesting thing today about Spring and my JUnit tests. I noticed that the VelocityEngine I was setting on my PositionManager was getting initialized once for each test* method in my Test. This means that since my PositionManagerTest has 10 test methods - it would load the context 10 times.

Loading the context so many times was because the following code was in my Test's parent's constructor:

    ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");

I suppose I expected any constructor-iniatialized variables to be initialized once and only once. So I figured out a solution to make my JUnit tests run faster. By making the ctx variable static, and loading the file in the member variables definition, I greatly reduced the amount of time needed to run tests. Below is the new code I'm using:

    protected static ApplicationContext ctx = 
    	new ClassPathXmlApplicationContext("/applicationContext.xml");

By doing this, the ApplicationContext is only set once, and my tests run much faster. Here's some performance comparisons from Struts Resume:

Average time to run "ant test-dao": 36 seconds
Average time to run "ant test-dao" after this change: 26 seconds

A 10 second improvement - that's crazy talk dontcha think?! I've tried it on single tests, as well as suites - and it seems to improve performance by approximately 30% across the board.

Because of this experience, I have to recommend that when you write JUnit tests that use Spring - you should initialize your ApplicationContext in a static member variable. It seems to be the best performing and logical choice. Of course, if I'm off my rocker - please let me know.

On a sidenote, it would be cool if Roller allowed me to turn off comments for a single post. I like how Simon posts stuff on java.net and then aggregates it to his personal weblog.

Posted in Java at Apr 08 2004, 01:22:14 AM MDT 21 Comments

Eclipse Plugins updated for 3.0 M8

At my current client, I'm teaching a class this week on developing Java-based webapps. I'm starting simple with basic JSPs and JSTL's SQL Tags. Later, I plan to teach them how to write JUnit tests, DAOs, Actions, etc. I hope to show them how Hibernate and Spring can reduce the pain of J2EE.

The main problem is that it's kinda tough to teach this stuff to people that have no webapp development experience. How can you tell them Hibernate is soooo much easier, when they've never used JDBC? How can you show them that Spring simplifies things when they've never developed a complicated app?

Anywho, back to the point of this post. As part of the first day, I had the class (actually, there's only 2 students) setup their development environments (JDK, Eclipse and Tomcat). I decided to go with the latest Eclipse 3.0 M8 b/c I'm an upgrade junkie and I firmly believe that it's best to teach the latest and greatest stuff. Because we're using M8, I had to update a bunch of plugins and decided to package it up and release it. So without further ado, I give you Eclipse Plugins 1.1. [Download, Release Notes]

Here's the current list of plugins included in this package:

NOTE: I updated most of these plugins because older ones didn't work with Eclipse 3.0 M8. I haven't tested all of these, but they are the latest versions (as of yesterday).

I still use Eclipse on Windows, but I sure am getting used to using IDEA on the Mac. Now if I could only figure out some slick ways to pre-program keys-to-code. The Flex guy in NYC last weekend would press one key and a whole block of text would appear. I think that'd be a nice touch for next week's presos in Florida. It'd be cool to write a JUnit Test, DAO Interface, and DAO Implementation in a matter or keystrokes (i.e. one for each method).

Related posts: 1.0 Release.

Posted in Java at Apr 08 2004, 12:37:23 AM MDT 17 Comments