Matt RaibleMatt Raible is a Web Developer and Java Champion. 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.

Database Profiles in AppFuse 2.0

Last night, I added several database profiles to AppFuse 2.0 and its archetypes. What does this mean? It means AppFuse should work out-of-the-box with several databases, including:

  • H2
  • HSQLDB
  • MySQL
  • PostgreSQL
  • SQL Server

For example, here's how to test a new AppFuse project works with H2:

mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=1.0-m4-SNAPSHOT -DgroupId=com.mycompany -DartifactId=myproject
Yeah, I wish there was a way to shorten this command (or prompt for choices) too.

After doing this, you can cd into the "myproject" directory and run mvn integration-test -Ph2. AppFuse 2.0 projects are configured for MySQL by default, so if you want to permanently activate one of these profiles, you can add the following between the <id> and <properties> section of the profile.

    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>

In addition to the profiles listed above, I tried to get Oracle Express and embedded Derby working. No dice on either one. I took a brief look at DB2 Express as well, but with a 400 MB download and 3 JARs required for its JDBC Driver - it seemed like a lot more trouble than it was worth.

Maven 2's build profiles are a powerful feature that we hope to make easy to use. For example, to test your new project with H2 and JBoss, you can simply run mvn integration-test -Ph2,jboss. Thanks to the power of Cargo, this will download JBoss 4.0.5, install it, and run all the Canoo WebTests within it. Of course, this will take a while the first time - especially since JBoss is a 77MB download. Fortunately, we allow you to change one small setting in your pom.xml and use an existing install instead.

Maven 2 is a kick-ass build/deploy/test tool once you figure it out. With AppFuse 2.0, we're doing all the "figuring out" for you. ;-)

NOTE: I would add more server profiles, but Cargo's Maven Plugin (version 0.2) has issues with Geronimo 1.1, Jetty 6.x and Resin 3.x. Strangely enough, Jetty's Maven Plugin version 6.0.0 works great, but 6.1.0 throws stack traces.

Update: Support for Oracle and Derby (in networked mode) has been added. We'll consider adding support for DB2 if IBM can figure out how to package their JDBC Driver into a single JAR.

Posted in Java at Feb 14 2007, 05:41:37 PM MST 27 Comments
Comments:

Yeah, I love archetypes but hate how hard they are to use. I wrote this little app called Archy [1] to help make it easier. It uses a simple microformat on the maven wiki to discover new archetypes and is simple to run.

[1] https://www.twdata.org/projects/archy

Posted by Don Brown on February 15, 2007 at 01:14 AM MST #

Hi Matt, I'm successfully running mvn commands from quickstart, and the project runs and tests correctly, but not getting any java sources for the org.appfuse.webapp.controller, filter, listener, etc. classes. Am new to maven; thanks for your help.

Posted by anonymous on February 17, 2007 at 05:35 PM MST #

If you run "mvn eclipse:eclipse" or "mvn idea:idea", it should create project files with sources attached for the various AppFuse dependencies (as well as many other libraries). This FAQ might help:

http://appfuse.org/display/APF/FAQ#FAQ-whereisthesource

Posted by Matt Raible on February 17, 2007 at 05:40 PM MST #

Don - can I checkout the source for Archy? I'd love to put a UI (web and webstart/swing) on it and allow project generating from a website. When I try to view the source, I get an error.

I also added AppFuse archetypes to the wiki page, but they still don't show up with Archy.

Posted by Matt Raible on February 19, 2007 at 05:20 AM MST #

Matt, For 1.9.4 I easily added DB2. JDBC Type-2 and -4 is one JAR (zip). For Type-4, there are two JAR's. I created one \lib entry for db2-jdbc-type23-8.2 and for db2-jdbc-type4-8.2. A few build,xml and properties.xml changes and I can easily switch from MySQL, Oracle XE and DB2 Derby. I do not understanding your concern for "multiple jar files". You superbly demonstrate this all throughout \lib with other frameworks.

Posted by Jeff Lambros on February 27, 2007 at 07:42 AM MST #

Jeff - the reason I need one JAR is because of how we've setup Maven 2 and our profiles in AppFuse 2.0. We use the following to signify database dependencies for the dbunit-plugin, the hibernate3-plugin and many others:

<dependencies>
    <dependency>
        <groupId>${jdbc.groupId}</groupId>
        <artifactId>${jdbc.artifactId}</artifactId>
        <version>${jdbc.version}</version>
    </dependency>
</dependencies>
You're correct - this issue doesn't happen in the Ant version of AppFuse.

Posted by Matt Raible on February 27, 2007 at 07:58 AM MST #

"...you can add the following between the <id> and <build> section of the profile."

I think that you might mean 'between the <id> and <properties> section of the profile' because I cannot find a <build> section in the profile?

eg.
<profile>
            <id>postgresql</id>
	    <activation>
	    	<activeByDefault>true</activeByDefault>
	    </activation>
            <properties>
             .....
</profile>
Is that correct?

Posted by Luke McLean on April 11, 2007 at 10:21 AM MDT #

You are correct Luke - I've corrected the typo in this post. Thanks!

Posted by Matt Raible on April 17, 2007 at 04:40 AM MDT #

I've got the same error for the embedded derby in dbunit even without hibernate3 plugin. Other words, just one plugin, the dbunit plugin, that use embedded derby. Does it sound like a derby or dbunit question? Where should I go for help? Thanks.

Posted by Luan on April 20, 2007 at 02:50 PM MDT #

Nevermind, it's because mevenide in netbeans did not shutdown the db instance after the first "mvn test" is run.

Posted by Luan on April 20, 2007 at 04:49 PM MDT #

activeByDefault only works, if no other profile is active. If you do the integration-test it won't work, because the integration-test profile will be active.

Posted by squiddle on May 06, 2007 at 02:43 PM MDT #

RE: the reason I need one JAR is because of how we've setup Maven 2 and our profiles in AppFuse 2.0. A better solution would be to roll your own mini-jar that has all the IBM jars as dependencies, that way you need only specify that mini-jar (which could just have a manifest and nothing else!) and Maven will pull down all it's dependencies

Posted by Stephen Connolly on May 27, 2007 at 06:35 PM MDT #

Good

Posted by Sangeeta on June 06, 2007 at 09:41 AM MDT #

Hi Matt, good work :-) how do you manage to replace the jdbc parameters in the jdbc.properties file with the values specified via properties defined in the pom? I want to achieve the same in my app but the placeholders are not replaced with the property values... Thx for any tip!

Posted by lasse on June 06, 2007 at 03:08 PM MDT #

Hey i got it ;)

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>
that did the trick for me!

Posted by lasse on June 06, 2007 at 03:37 PM MDT #

Yeah, don't use activeByDefault, it will be active in some cases but not others and cause you trouble.

Posted by Tobu on June 11, 2007 at 11:13 PM MDT #

Tobu - if we shouldn't use activeByDefault, what should we use to activate a profile by default?

Posted by Matt Raible on June 11, 2007 at 11:23 PM MDT #

DB2 9 jdbc driver have two jar files. One of them is the licence jar. Without this jar, DB2 connection can not be established. I added two jars as dependencies in pom.xml. But Maven shows an error as "You need to set db2cc_licence_*.jar in CLASSPATH". How can I put these jar files together in maven classpath?

Posted by Mustafa Sait Özen on June 22, 2007 at 11:07 AM MDT #

Mustafa - I think Stephen Connolly provides the best solution for this:

A better solution would be to roll your own mini-jar that has all the IBM jars as dependencies, that way you need only specify that mini-jar (which could just have a manifest and nothing else!) and Maven will pull down all it's dependencies.
You could try that - or try to find a JDBC Driver for DB2 (maybe Derby's?) that is a single dependency. If you come up with a good solution (i.e. a dependency that references both of DB2's JARs), we'd be happy to host it in AppFuse's repo. Of course, you'll still need to install DB2's JARs locally, but we can handle the higher-level metadata.

Posted by Matt Raible on June 22, 2007 at 11:11 AM MDT #

The first maven command in this article makes no reference to H2. How does maven know what database to deal with? What would be an example of the syntax for postgresql?

Posted by Peder Jakobsen on July 08, 2007 at 06:53 PM MDT #

I have a solution about using DB2 JDBC Driver in Maven 2. I have expanded those two jars into a folder. Then I have zipped the contents inside the folder as a jar file. Now I can use only one jar file to execute DB operations. The solution is simple but efficient, i think.

Posted by Mustafa Sait Özen on July 10, 2007 at 11:53 AM MDT #

Peder - for PostgreSQL, you can use "mvn -Ppostgresql". Maven's Introduction to Profiles explains how profiles are activated (with -Pprofilename being one of them).

Posted by Matt Raible on July 26, 2007 at 05:20 AM MDT #

how can i edit the database connection to SQL Server connection.

Posted by Jayasanka on April 28, 2008 at 06:57 AM MDT #

I notice at the bottom of pom.xml, outside the <profiles/> element (within <properties/>) are a whole bunch of jdbc properties/values for MySql. Wouldn't those jdbc/MySql properties be better placed in their own <profile/> element, using an <activation/> to set them as the default, or am I missing something here? - I've been a die-hard Ant user and only just come to Maven!

Also, is there a way to instruct AppFuse to always use one of the other databases by default (I'd prefer one with a more liberal commercial licence).

Posted by Paul Pepper on September 09, 2008 at 01:26 PM MDT #

@Paul (and others) - please post your questions related to this post to the AppFuse User Mailing List. Thanks!

Posted by Matt Raible on September 09, 2008 at 03:45 PM MDT #

I need to Use Ecllipse IDE and Oracle instead of mysql. I couldn't see, what all steps i have to go through to set oracle as back end.Please help

Posted by bini on February 24, 2009 at 05:28 PM MST #

@bini - please post your questions to the mailing list.

Posted by Matt Raible on February 24, 2009 at 07:17 PM MST #

Post a Comment:
Comments are closed for this entry.