11 Replies Latest reply on Apr 2, 2011 3:16 PM by Dan Allen

    Archetypes: Weld archetypes update

    Dan Allen Master

      It's been a while and you might be wondering what's going on with the Weld archetypes. We are working on them, we've just been working upstream for a while.


      From the very start, we've wanted to make the generated project as simple as possible, yet give you the maximum utility. For that to happen, you need the full Java EE API (or as much of it as the environment you are using will support). Rather than requiring you to put a dozen dependencies in your pom.xml, it would be ideal of you could bring it the platform APIs with a single dependency.


      Here's what's brewing:


      <dependency>
         <groupId>org.jboss.spec</groupId>
         <artifactId>jboss-javaee-6.0</artifactId>
         <version>1.0.0.Beta4</version>
         <type>pom</type>
         <scope>provided</scope>
      </dependency>



      You may be asking, what about the javaee-api JAR that's in the GlassFish repository. It's bad for two reasons:



      • It's a shaded JAR, so you have no idea what it actually bundles

      • The code is stripped out of all the method bodies, so you get an Absent Code exception if you try to touch any of the classes



      Published stripped JARs was a bad decision in my viewpoint and I explain the resulting Absent Code Exception in an FAQ. Of course, you can just search for Absent Code in Google and read all about the problems it's causing.


      Another improvement in the archetypes are the repository definitions. The JBoss repository is now powered by Nexus and has become a hub for a catalog of other repositories, including central (though for users, it requires an addition to your settings.xml).


      So the repository definitions now look like this (notice that the snapshots are intentionally disabled, minimizing bandwidth usage):


      <repositories>
         <repository>
            <id>jboss-public-repository</id>
            <name>JBoss Repository</name>
            <url>https://repository.jboss.org/nexus/content/groups/public</url>
            <releases>
               <enabled>true</enabled>
               <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
               <enabled>false</enabled>
            </snapshots>
         </repository>
      </repositories>
      <pluginRepositories>
         <pluginRepository>
            <id>jboss-public-repository</id>
            <name>JBoss Repository</name>
            <url>https://repository.jboss.org/nexus/content/groups/public</url>
            <releases>
               <enabled>true</enabled>
               <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
               <enabled>false</enabled>
            </snapshots>
         </pluginRepository>
      </pluginRepositories>



      Finally, I'm thinking that we should change how the archetypes are stored in the source repository. Right now we are using the archetype structure. However, it seems that the recommend way to create archetypes is from an project. So you store the final project in the source repository and then generate the Maven archetype from that structure.


      You can read the documentation for the archetype:create-from-project goal for details, or check out this article which provides an example. I've followed this approach for the Arquillian archetypes. Steven, WDYT?


      I'm also going to prefix archetype discussions with Archetypes: so that they stand out from discussion of Weld itself.

        • 1. Re: Archetypes: Weld archetypes update
          Dan Allen Master

          Oh, I totally forgot to mention Arquillian! Now that it's released (in alpha), we are going to be adding Arquillian configuration to the POM file (in the space we save on the abbreviated dependencies). I don't plan on adding a ton of profiles. You can get those in the Arquillian archetype. We'll likely add these profiles:



          • weld-embedded

          • jbossas-embedded-60



          It's tempting to add the other containers, but it would be better if we just pointed you to an online menu :)

          • 2. Re: Archetypes: Weld archetypes update
            Steven Boscarine Apprentice

            Dan Allen wrote on Jun 15, 2010 02:08:


            You can read the documentation for the archetype:create-from-project goal for details, or check out this article which provides an example. I've followed this approach for the Arquillian archetypes. Steven, WDYT?



            Sounds like it will be much easier to test.  I see not reason not to.  Let's try this approach.


            So to move forward, should we tag what we have and then delete trunk and create this new project?

            • 3. Re: Archetypes: Weld archetypes update
              Steven Boscarine Apprentice

              I built a prototype in a separate branch in the project http://anonsvn.jboss.org/repos/weld/archetypes/branches/prototype/
              I haven't yet figured out how to escape variables, so anyone who builds the project will get:


              [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 25,column 19] : ${env.JBOSS_HOME} is not a valid reference.
              [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 109,column 27] : ${jboss.home} is not a valid reference.
              [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 110,column 28] : ${jboss.domain} is not a valid reference.
              [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 112,column 29] : ${project.build.directory} is not a valid reference.
              [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/pom.xml [line 112,column 56] : ${build.finalName} is not a valid reference.
              


              ...until we figure this out. 

              • 4. Re: Archetypes: Weld archetypes update
                Dan Allen Master

                Steven,


                This is just a harmless warning that Maven 2 outputs in some scenarios. Either I've worked it out in the latest check-in, or, if it does still happen w/ some version of Maven, it's harmless.

                • 5. Re: Archetypes: Weld archetypes update
                  Dan Allen Master

                  Maven 3 doesn't seem to have this issue. But actually, it's not the Maven core, but rather which version of the archetype plugin is running. It's fixed in the latest.

                  • 6. Re: Archetypes: Weld archetypes update
                    Dan Allen Master

                    After many trials and tribulations, I finally figured out arrangement that worked to use create-from-project and still be able to release using Nexus. I'll expand below. But first, some info about what has changed:


                    I'd like to call this archetype weld-basic-javaee6-webapp (or jboss-basic-javaee6-webapp, see below); it reads nicely



                    • I switched from Widget to Member as the example entity

                    • I added a very basic JAX-RS endpoint, MemberResource (because it's so simple)

                    • I added Arquillian configurations; you may feel uneasy about some, but know that we are trying to get the amount of configuration down more...this is a configuration that works well thus far

                    • I switch from TestNG to JUnit 4 (as that is what we are using in Seam now and likely Weld soon)

                    • I've staged a version for you to try. First, add the weld-staging repository to your $HOME/.m2/settings.xml and activate it



                          <profile>
                             <id>weld-staging</id>
                             <repositories>
                                <repository>
                                   <id>weld-staging</id>
                                   <releases>
                                      <enabled/>
                                   </releases>
                                   <url>http://oss.sonatype.org/content/repositories/orgjbossweld-040</url>
                                </repository>
                             </repositories>
                          </profile>



                    Next, put this archetype-catalog.xml in your $HOME/.m2 (same issue we had before, the user needs the catalog to see the entry in generate:archetype)


                    <?xml version="1.0" encoding="UTF-8"?>
                    <archetype-catalog
                      xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="
                        http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0
                        http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd">
                      <archetypes>
                        <archetype>
                          <groupId>org.jboss.weld.archetypes</groupId>
                          <artifactId>weld-basic-javaee6-webapp</artifactId>
                          <version>1.0.0.Beta2</version>
                          <description>Weld Basic Java EE 6 Webapp</description>
                        </archetype>
                      </archetypes>
                    </archetype-catalog>



                    Create an archetype:


                    $> mvn archetype:generate -DarchetypeCatalog=local
                    Choose archetype:
                    1: local -> weld-basic-javaee6-webapp (Weld Basic Java EE 6 Webapp)
                    Choose a number:



                    The readme.txt should have everything you need to know to run it. If not, it's a bug ;)


                    You can try out the Arquillian persistence test using the following command:


                    mvn test -Pglassfish-embedded-30



                    or, if you start a JBoss AS 6 instance:


                    mvn test -Pjbossas-remote-60



                    I'll explain how I structured the project to accommodate the upside down approach of create-from-project.


                    If we create from project, then what we need to tag is not the project, but rather the archetype generated from that project. However, generated code is not typically in SVN. However, in order for the release plugin to work, it has to be. So, what I finally figured out is that we can put the generated archetype under target and checkin just that directory.


                    I had to do a fair amount of scripting in build.sh to make this work, but I think it's worth it since we can actually work on the project before sending it through the blast furnace for it to become an archetype.


                    Here's the general process:



                    • mvn archetype:create-from-project creates an archetype under target/generated-sources/archetype

                    • we move the files we are interested in to target/archetype

                    • some transformations are done on the files

                    • archetype-pom.xml is moved into target/archetype/pom.xml (because the one that is generated is crap)

                    • When target/archetype is how we want it, we check it into SVN in preparation to be tagged. (this is the slightly messy, manual part)

                    • We perform the release from the target/archetype directory.



                    There are three remaining issues/tasks.


                    1. We should probably move trunk to a branch and take over trunk

                    2. We went from 3 archetypes to 1...we need to bring back servlet...so perhaps trunk should be:


                    trunk/
                       basic-javaee6-webapp
                       basic-faces-servlet-webapp



                    3. We are considering renaming the artifactId prefix from weld- to jboss-

                    4. Review and release!

                    • 7. Re: Archetypes: Weld archetypes update
                      Steven Boscarine Apprentice

                      Out of curiosity, why did we drop TestNG in favor of JUnit?


                      From what I've seen TestNG has more features and it's definitely much more thoroughly documented.  I had to go through their release notes, release by release, just to see examples of how to use their annotations. 

                      • 8. Re: Archetypes: Weld archetypes update
                        Dan Allen Master

                        Steven Boscarine wrote on Jun 19, 2010 22:57:


                        Out of curiosity, why did we drop TestNG in favor of JUnit?

                        From what I've seen TestNG has more features and it's definitely much more thoroughly documented.  I had to go through their release notes, release by release, just to see examples of how to use their annotations. 


                        Good question. The reason is because the integration with Arquillian is much cleaner atm (@RunWith rather than class extension) and because the Eclipse plugin is a lot nicer for JUnit than it is for TestNG. Also, we are using it in Seam 3. Truthfully, it comes down to a VI vs emacs debate, no doubt. This is when I really wish that the archetype plugin could give you a menu to select between two different contents. Perhaps with some script wizardry I could provide that support when the archetypes are created from project, so we end up with two archetypes. For now, I'd like to give JUnit a try.

                        • 9. Re: Archetypes: Weld archetypes update
                          Dan Allen Master

                          Just to give you a heads up, I've restructured the source repository to move the current archetype work into trunk. The previous archetypes are now in a branch:


                          http://anonsvn.jboss.org/repos/weld/archetypes/branches/Branch_1_0_0_BETA/



                          I've incremented the version of trunk to 1.0.1-SNAPSHOT since we've changed the artifact names of the archetypes.


                          I also add the servlet archetype back in. For that archetype, I added the Arquillian weld-embedded only (since we don't have a tomcat container for Arquillian yet).


                          I'd like to tag each archetype individually now. I think that will allow for maximum flexibility since a release of one does not necessary imply a release of the other.


                          The folder names are:



                          • javaee6-webapp-src

                          • jsf-weld-servet-webapp-src



                          The final artifactIds are



                          • jboss-javaee6-webapp

                          • jboss-jsf-weld-servlet-webapp

                          • 10. Re: Archetypes: Weld archetypes update
                            Todd Morrison Newbie

                            Bump.


                            Have these archetypes been updated in awhile? Any newer versions?

                            • 11. Re: Archetypes: Weld archetypes update
                              Dan Allen Master

                              Funny you should ask. I just updated them yesterday, as part of the worldwide April Fools' Day release bonanza (as it turned out to be).


                              Right now, I've only updated the jboss-javaee6-webapp, since our main focus is on the web profile. The version I just released is CR1. It's updated to use:



                              • Seam Solder 3.0.0.Final

                              • Arquillian 1.0.0.Alpha5



                              I've even updated the screenshots to match. Check it out: http://tinyurl.com/gojavaee.


                              I've got a few more tweaks coming in CR2 and I'll try to push out the Weld Servlet one soon too.