Friday, April 18, 2008

Grokking Appfuse

I'm running CentoOS 5 and here is the output of mvn --version Maven version: 2.0.9 Java version: 1.5.0_14 OS name: "linux" version: "2.6.18-53.1.14.el5" arch: "i386" Family: "unix" To start having fun(or frustrating yourself) with appfuse, you need * jdk 1.5+ * maven 2.0.x * mysql 5+ Check the Installers folder in our file server if you need any of the above files. For reference, here is the output of mvn -version on my CentOS5 box Maven version: 2.0.9 Java version: 1.5.0_14 OS name: "linux" version: "2.6.18-53.1.14.el5" arch: "i386" Family: "unix" Appfuse makes use of Maven to automate most of its stuff. First thing to do is to setup the maven installation to make use of the internal repository. Locate and open(use a text editor) the settings.xml found in the conf directory of your maven installation. It should have a mirrors section, modify it so that it would look something like this: <mirrors> <mirror> <id>internal</id> <mirrorOf>*</mirrorOf> <name>internal</name> <url>http://scm:8080/archiva/repository/internal</url> </mirror> </mirrors> Next, you need to create the project structure. Using the commandline, go to your workspace directory and run: mvn archetype:create \ -DarchetypeGroupId=org.appfuse.archetypes \ -DarchetypeArtifactId=appfuse-modular-struts \ -DremoteRepositories= \ -DarchetypeVersion=2.0.1 \ -DgroupId=com.henyo.etg \ -DartifactId=eTestGen This will create a modular struts2 project instead of a basic project. Why modular? I dunno, seems way cooler than a basic project? or according to Matt Raible: The basic archetypes are ideal for creating projects that will serve as web applications. The modular archetypes contain "core" and "web" modules and are ideal for creating projects that have a re-usable backend. Using the command line, change into the project directory and run mvn clean appfuse:full-source This will download the source code of appfuse which we need because there is a STUPID error in the way the dependecies are downloaded. Specifically, there are two versions of spring on the classpath(2.0 and 2.5) so depending on the mood of the freaking class loader, the older version may be loaded which is NOT compatible with the applicationContext-service.xml so you will get this when you try running your project: ERROR [main] ContextLoader.initWebApplicationContext(203) | Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext-service.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.ParserContext.registerBeanComponent(Lorg/springframework/beans/factory/parsing/BeanComponentDefinition;) You need to modify the pom.xml file inside the web folder, locate the struts2-spring-plugin dependency declaration and modify it so that it looks like this: <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>${struts.version}</version> <exclusions> <exclusion> <artifactId>spring-context</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-web</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> then change into the core directory and run mvn clean install then go to the web directory and do mvn jetty:run-war You can now access the application in: http://localhost:8080

No comments:

Post a Comment