1 2 Previous Next 29 Replies Latest reply on Nov 10, 2009 5:12 AM by Dan Allen

    Weld Maven 2 Archetype Proposal

    Steven Boscarine Apprentice

      I wrote two Weld team members with a proposal for creating a Maven Archetype for Weld. Here is my proposal, my prototype hosted at Google Code and the JIRA to track the initiative:




      The proposal link contains a proof-of-concept/prototype of a Hello World Weld + JSF 2 archetype. It's based on a tutorial I wrote. It would obviously get modified drastically in the final product based on community feedback.


      I am hoping that writing a good set of archetypes will greatly help new users get started with Weld. I think these are likely to become official JBoss artifacts, something Seam 2 never had. I have volunteered to get the ball rolling and start writing them and we're hoping to shape them based on user input. 


      I was hoping to get feedback. There are many things we know we need to do, but there are still some questions we need help answering, all of which are on the page. Please give it a try!

        • 1. Re: Weld Maven 2 Archetype Proposal
          Dan Allen Master

          We're well aware that Maven 2 archetypes are something the community has requested to have for Seam many times. These archetypes for Weld will lay the groundwork for what we provide in Seam 3, so if you are one of those people who requested them, please jump in!

          • 2. Re: Weld Maven 2 Archetype Proposal
            Arbi Sookazian Master

            good idea.  there better be a Seam 3 archetype!


            thoughts regarding your proposal:


            1) what about a plugin for Glassfish V3?


            2) Should it contain a hello world facelet + Weld app?
            yes, but by that I assume you mean JSF with xhtml as view technology and backing beans using Weld (CDI)?


            3) Should it contain a small HSQL CRUD piece as well? If so, the CRUD piece should have an example of AJAX and highlights of the new JSF 2 features.
            yes and yes (<ajax:foo> has been added to JSF 2.0 so showcase that as well!).

            • 3. Re: Weld Maven 2 Archetype Proposal
              Dan Allen Master

              1) what about a plugin for Glassfish V3?


              I believe that Steven was looking into that. Here are two reference articles:





              2) Should it contain a hello world facelet + Weld app?
              yes, but by that I assume you mean JSF with xhtml as view technology and backing beans using Weld (CDI)?


              Absolutely. Btw, we are looking right now into getting rid of the need for the Faces Servlet definition in web.xml as defined by the JSF 2 spec.



              3) Should it contain a small HSQL CRUD piece as well? If so, the CRUD piece should have an example of AJAX and highlights of the new JSF 2 features.
              yes and yes (<ajax:foo> has been added to JSF 2.0 so showcase that as well!).


              Highlighting <f:ajax> would be a nice addition.

              • 4. Re: Weld Maven 2 Archetype Proposal
                Arbi Sookazian Master
                <?xml version="1.0" encoding="UTF-8"?>
                <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
                     <modelVersion>4.0.0</modelVersion>
                     <groupId>${groupId}</groupId>
                     <artifactId>${artifactId}</artifactId>
                     <packaging>war</packaging>
                     <name>${artifactId}</name>
                     <version>${version}</version>
                     <repositories>
                          <!--
                               As of October 2009, a few of the weld dependencies were not yet on the main maven repo. We can add JBoss repo as it
                               is updated more frequently.
                          -->
                          <repository>
                               <id>repository.jboss.org</id>
                               <name>JBoss Repository</name>
                               <url>http://repository.jboss.org/maven2</url>
                               <releases>
                                    <enabled>true</enabled>
                               </releases>
                               <snapshots>
                                    <enabled>false</enabled>
                               </snapshots>
                          </repository>
                     </repositories>
                     <dependencies>
                          <!-- Common -->
                          <dependency>
                               <groupId>javax.enterprise</groupId>
                               <artifactId>cdi-api</artifactId>
                               <scope>provided</scope>
                               <version>1.0-CR1</version>
                          </dependency>
                
                          <dependency>
                               <groupId>javax.annotation</groupId>
                               <artifactId>jsr250-api</artifactId>
                               <version>1.0</version>
                          </dependency>
                
                          <dependency>
                               <groupId>javax.faces</groupId>
                               <artifactId>jsf-api</artifactId>
                               <version>2.0.0-RC</version>
                          </dependency>
                
                          <!-- Jetty-specific scopes and artifacts -->
                          <dependency>
                               <groupId>javax.faces</groupId>
                               <artifactId>jsf-impl</artifactId>
                               <scope>runtime</scope>
                               <version>2.0.0-RC</version>
                          </dependency>
                
                          <dependency>
                               <groupId>javax.servlet</groupId>
                               <artifactId>jstl</artifactId>
                               <version>1.2</version>
                               <scope>runtime</scope>
                          </dependency>
                
                          <dependency>
                               <groupId>org.jboss.weld.servlet</groupId>
                               <artifactId>weld-servlet</artifactId>
                               <version>1.0.0-CR1</version>
                               <scope>runtime</scope>
                          </dependency>
                
                          <dependency>
                               <groupId>org.glassfish.web</groupId>
                               <artifactId>el-impl</artifactId>
                               <version>2.1.2-b04</version>
                               <scope>runtime</scope>
                               <exclusions>
                                    <exclusion>
                                         <groupId>javax.el</groupId>
                                         <artifactId>el-api</artifactId>
                                    </exclusion>
                               </exclusions>
                          </dependency>
                
                          <!-- Sun Bean Validation API (JSR 303) -->
                          <dependency>
                               <groupId>javax.validation</groupId>
                               <artifactId>validation-api</artifactId>
                               <version>1.0.0.GA</version>
                          </dependency>
                          <!-- hibernate bean validation impl -->
                          <dependency>
                               <groupId>org.hibernate</groupId>
                               <artifactId>hibernate-validator</artifactId>
                               <version>4.0.0.GA</version>
                          </dependency>
                          <!-- For some reason, this is a dependency of Bean Validation -->
                          <dependency>
                               <groupId>org.slf4j</groupId>
                               <artifactId>slf4j-log4j12</artifactId>
                               <version>1.4.2</version>
                          </dependency>
                     </dependencies>
                     <build>
                          <finalName>${artifactId}</finalName>
                          <plugins>
                               <!-- Compiler plugin enforces Java 1.6 -->
                               <plugin>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-compiler-plugin</artifactId>
                                    <configuration>
                                         <source>1.6</source>
                                         <target>1.6</target>
                                    </configuration>
                               </plugin>
                
                               <!-- Eclipse plugin enforces download of source and JavaDoc jars -->
                               <plugin>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-eclipse-plugin</artifactId>
                                    <configuration>
                                         <wtpversion>2.0</wtpversion>
                                         <downloadSources>true</downloadSources>
                                         <downloadJavadocs>true</downloadJavadocs>
                                    </configuration>
                               </plugin>
                               <!-- Embedded Jetty (jetty:run) -->
                               <plugin>
                                    <groupId>org.mortbay.jetty</groupId>
                                    <artifactId>maven-jetty-plugin</artifactId>
                                    <configuration>
                                         <!-- force friendly name instead of artifact name + version -->
                                         <contextPath>${build.finalName}</contextPath>
                                         <!-- Where the BeanManager is constructed.  This is where we'll later declare datasource. -->
                                         <jettyEnvXml>\${basedir}/src/test/resources/jetty-env.xml</jettyEnvXml>
                                         <!-- This parameter will auto-deploy modified classes...my personal favorite Jetty feature. -->
                                         <scanIntervalSeconds>3</scanIntervalSeconds>
                                    </configuration>
                               </plugin>
                          </plugins>
                     </build>
                </project>



                http://crotchetycoder.googlecode.com/svn/trunk/labs/weld-archetype-servlet-quickstart/src/main/resources/archetype-resources/pom.xml


                So please explain (to the uninitiated).  What is the purpose of a Maven archetype?  So you can start a new project faster/easier (regarding dependency mgmt?)



                What is Archetype?

                In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The names fits as we are trying to provide a system that provides a consistent means of generating Maven projects. Archetype will help authors create Maven project templates for users, and provides users with the means to generate parameterized versions of those project templates.

                http://maven.apache.org/guides/introduction/introduction-to-archetypes.html


                seems somewhat similar to the seam-gen interview/process from Seam 2.x, in that if you use the same answers to the interview then the results will be very similar in terms of a project structure, libraries, etc...

                • 5. Re: Weld Maven 2 Archetype Proposal
                  Arbi Sookazian Master


                  I believe that Steven was looking into that. Here are two reference articles:





                  That first link/article was very interesting.  I just recently experienced the old days scenario at a new job.  Can we use the Jetty Launcher Plug-in with JBoss embedded?


                  So in this example, it's configuring and using three app servers simultaneously?  It's basically three plugins that somehow sets up Maven downloads all of the dependencies, builds the application, downloads a container, configures it based on our pom.xml and and deploys it to an embedded container.  Is the below the complete pom.xml to do all that?


                  <build>
                     <plugins>
                        <!-- Embedded Glassfish v3 prelude (glassfish:run) -->
                        <plugin>
                           <groupId>org.glassfish</groupId>
                           <artifactId>maven-glassfish-plugin</artifactId>
                           <version>1.0-alpha-4</version>
                           <configuration>
                              <!-- technically optional, but helpful to declare explicitly. -->
                              <!-- I personally put all 3 containers on different ports. -->
                              <!-- This allows me to test them simultaneously. -->
                              <httpPort>8070</httpPort>   
                           </configuration>
                        </plugin>
                        <!-- Jetty Launcher Plug-in -->
                        <plugin>
                           <groupId>org.mortbay.jetty</groupId>
                           <artifactId>maven-jetty-plugin</artifactId>
                           <configuration>
                              <contextPath>${project.artifactId}</contextPath>
                              <!-- This parameter will auto-deploy modified classes -->
                              <scanIntervalSeconds>3</scanIntervalSeconds>
                              <connectors>
                                 <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                                    <port>8090</port>
                                    <maxIdleTime>60000</maxIdleTime>
                                 </connector>
                              </connectors>
                           </configuration>
                        </plugin>
                        <!-- embedded tomcat (tomcat:run) -->
                        <plugin>
                           <groupId>org.codehaus.mojo</groupId>
                           <artifactId>tomcat-maven-plugin</artifactId>
                        </plugin>
                     </plugins>
                  </build>

                  • 6. Re: Weld Maven 2 Archetype Proposal
                    Steven Boscarine Apprentice

                    Arbi Sookazian wrote on Nov 07, 2009 00:39:



                    So in this example, it's configuring and using three app servers simultaneously?  It's basically three plugins that somehow sets up Maven downloads all of the dependencies, builds the application, downloads a container, configures it based on our pom.xml and and deploys it to an embedded container.  Is the below the complete pom.xml to do all that?



                    Correct!  That's exactly what it does.  I personally used to use WTP's Tomcat launcher to develop, but it is the buggiest program I've ever seen.  Now I basically use Jetty exclusively.  I add that snippet to my POM, run 'mvn jetty:run' and modify code, switch to browser, refresh, and view my change.  It's exactly like WTP, only it works.  Also Jetty is really fast. 


                    The glassfish and tomcat plugins automatically publish text files as you modify them, but not classes at this point.  The glassfish one has a great feature where you hit enter in your console and it redeploys.  All of this autopublishing fun is in Eclipse (and NetBeans and IntelliJ IIRC).  You may experience different results if your IDE doesn't compile to the target folder.  (Sorry vi users!)


                    I wrote a tiny tutorial here, in which I tried to distil the JBoss example POM and a trivial application to the absolute bare minimum needed to get started.  No container is needed.  All you need is a JDK and maven.  You can also download the code from SVN and run it using 'mvn war:inplace jetty:run'.  I'm halfway through a similar CRUD tutorial I hope to publish next week.  At this point I'm looking for those cool barely-documented or completely undocumented features they've all been telling us about in JSF2 to show off.  It also only requires a JDK and maven.


                    There are a few caveats.  At this precise moment in time, those plugins don't work for Weld applications the way they work for a SpringMVC, Struts, or (presumably) Seam application.  For some reason, the Weld examples all use war:inplace in Jetty, which breaks Jetty's autopublish of classes.  The embedded tomcat plugin is presently using 6.0.16, which doesn't work with weld.  I haven't tested Glassfish yet.  As soon as I get time, I'll either document the correct procedure if it works or rant to the JBoss team if it doesn't. 


                    I heard a rumor JBoss is close to having an embedded version of JBossAS to compete with the glassfish/jetty plugin.  The instant it resembles a working application, I'll add the pom configuration and update the documentation, unless you or the JBoss staff beats me to it. 



                    • 7. Re: Weld Maven 2 Archetype Proposal
                      Steven Boscarine Apprentice

                      Arbi Sookazian wrote on Nov 07, 2009 00:24:



                      So please explain (to the uninitiated).  What is the purpose of a Maven archetype?  So you can start a new project faster/easier (regarding dependency mgmt?)

                      What is Archetype?

                      In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The names fits as we are trying to provide a system that provides a consistent means of generating Maven projects. Archetype will help authors create Maven project templates for users, and provides users with the means to generate parameterized versions of those project templates.


                      http://maven.apache.org/guides/introduction/introduction-to-archetypes.html

                      seems somewhat similar to the seam-gen interview/process from Seam 2.x, in that if you use the same answers to the interview then the results will be very similar in terms of a project structure, libraries, etc...


                      Hello Arbi,

                      You're on a roll today with posts :). 


                      I think you explained quite well what an archetype is and what it's used for.  If you read my Hello World tutorial I wrote a while back, the prototype archetype you are referring to creates the entire HelloWorld application with a single command.  I'll be writing some stuff about how to use them as well.  I'll try to answer your question persuasively in the documentation.  If I don't, that's were people in the community like you are a valuable asset. 


                      If someone tells you to use their product and can't give you a persuasive answer as to WHY?, that's a sign of a huge problem in my book.  Grill anyone, especially me, who tells you about cool technology, but can't answer WHY you need it.


                      I'm almost done with a prototype of the first one to submit to JBoss.  Once the archetypes are up, documentation will follow and getting started documentation will be a LOT shorter. 


                      Also, Maven archetypes are primarily designed to give you a working project.  They generate the pom.xml and the boilerplate code needed to run whatever framework they cover.  It is common to add small examples of code for training or the user's convenience.  For example, the quickstart archetype provided by Apache adds a trivial class and a unit test to highlight the intended use of Maven. 


                      SeamGen, in contrast, is much more interactive and designed to closely model your actual entities IIRC.  SeamGen competes with Grails and Rails.  Archetypes just create projects for you to get started with.  They're super easy to write, so you may want to write some for your own company to model your most common use cases.  We do that at my employer. 


                      Thanks,

                      Steven

                      • 8. Re: Weld Maven 2 Archetype Proposal
                        Dan Allen Master

                        Archetypes just create projects for you to get started with. They're super easy to write, so you may want to write some for your own company to model your most common use cases.


                        Yes, it's very important to keep in mind that the goal of an archetype is pretty much the same as New Project... in an IDE. The main difference is that an archetype is not dependent on an IDE, and an IDE can consume the archetype. So everybody wins!


                        We'll address seam-gen down the road. That is a whole other beast that, as Steven points out, is really a compliment to Grails. I wouldn't say it competes with Grails since we are talking about two totally different platforms. Grails is for Grails applications. My vision is that seam-gen encore will be for Java EE applications (with Seam sprinkled in). Let's keep that discussion separate from this thread.


                        Let's focus on the Weld archetypes.

                        • 9. Re: Weld Maven 2 Archetype Proposal
                          Dan Allen Master

                          One comment. We tend to prefer to use port 9090 to run embedded containers so that it doesn't conflict with a running JBoss AS or Tomcat instance on port 8080. Could you make that change?


                          Many of the Weld developers are running JBoss AS continuously and will have to change this setting each time. These are the ports we tend to use:



                          • JBoss AS - 8080

                          • Tomcat - 8080 (I know, the same as JBoss AS, but folks tend to pick either JBoss AS or Tomcat and stick with it)

                          • GlassFish - 7070

                          • Embedded Jetty (or Tomcat) - 9090



                          If you disagree, feel free to state your reason.

                          • 10. Re: Weld Maven 2 Archetype Proposal
                            Dan Allen Master

                            Also, I think you should add the empty faces-config.xml file. Otherwise, it's a pain for developers to have to go find the right root declaration when creating one. It's easy enough to delete.


                            <?xml version="1.0" encoding="UTF-8"?>
                            <faces-config version="2.0"
                               xmlns="http://java.sun.com/xml/ns/javaee"
                               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                               xsi:schemaLocation="
                                  http://java.sun.com/xml/ns/javaee
                                  http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
                            </faces-config>

                            • 11. Re: Weld Maven 2 Archetype Proposal
                              Dan Allen Master

                              I get this in the output of the build:


                              [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!



                              Don't know why this happens. Do we need these lines in the parent?


                              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                              <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

                              • 12. Re: Weld Maven 2 Archetype Proposal
                                Dan Allen Master

                                Why is jetty-env.xml in src/test/resources and not src/main/resources?

                                • 13. Re: Weld Maven 2 Archetype Proposal
                                  Dan Allen Master

                                  I think you should put the Jetty resources in either src/jetty/resources or src/main/webapp-jetty. Obviously src/main/resources is no good because it will get packaged.


                                  Also, I suggest you should use Jetty's web.xml override mechanism to register the listener and JNDI resource.


                                  src/main/webapp-jetty/WEB-INF/override-web.xml


                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <web-app version="2.5"
                                     xmlns="http://java.sun.com/xml/ns/javaee"
                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                     xsi:schemaLocation="
                                        http://java.sun.com/xml/ns/javaee
                                        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                                  
                                     <listener>
                                        <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
                                     </listener>
                                  
                                  </web-app>



                                  And the pom.xml config:


                                  <jettyEnvXml>${basedir}/src/main/webapp-jetty/WEB-INF/jetty-env.xml</jettyEnvXml>
                                  <overrideWebXml>${basedir}/src/main/webapp-jetty/WEB-INF/override-web.xml</overrideWebXml>



                                  See here for a working prototype: http://anonsvn.jboss.org/repos/weld/examples/trunk/jsf/permalink/

                                  • 14. Re: Weld Maven 2 Archetype Proposal
                                    Dan Allen Master

                                    Unless I put beans.xml in src/main/resources/META-INF, the application does not pick up the helloWorld bean when I run:


                                    mvn clean
                                    mvn jetty:run

                                    1 2 Previous Next