You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
The Weld team recently collaborated with users just like yourself to create a set of Maven archetypes for Java EE 6 and standalone CDI (in a Servlet environment). Now it's even easier and faster to get started using CDI (with Weld as the provider).
To create your project, copy and paste one of the commands below in a terminal, then follow the prompts:Java EE 6 project
mvn archetype:generate -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=centralCDI project for Servlet containers (powered by Weld Servlet)
mvn archetype:generate -DarchetypeArtifactId=jboss-jsf-weld-servlet-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.Beta1 -DarchetypeRepository=central
* The -DarchetypeRepository=central flag is required when the archetype catalog is out of date, as it often is after a release.
Do not use the artifacts that have an artifactId beginning with weld-*. They are deprecated.
If you are getting the error below when building the generated project, it's a sure sign you are using Maven 2. Please migrate to Maven 3 for reasons explained in SEAM-10.
[ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Error building POM (may not be this project's POM). Project ID: org.jboss.spec:jboss-javaee6-specs-bom Reason: POM 'org.jboss.spec:jboss-javaee6-specs-bom' not found in repository: Unable to download the artifact from any repository org.jboss.spec:jboss-javaee6-specs-bom:pom:1.0.0.Beta1 from the specified remote repositories: central (http://repo1.maven.org/maven2) for project org.jboss.spec:jboss-javaee6-specs-bom
Please note that comments on this page are closed (because we have no good way to track them).
Maven archetypes are templates that allow you to get started writing your application much more quickly by generating a barebones, deployable Maven 3 project. The Weld archetypes can create either a Java EE 6 project that targets a Java EE 6 application server (e.g., JBoss AS 6.0 and GlassFish V3) or a JSF 2.0 and CDI application that runs on Servlet containers (e.g., Tomcat 6 and Jetty 6). You can select the view layer of your choice, though at the moment, JSF 2 is the only preconfigured option. In the future we will have archetypes for Wicket and other technologies that integrate with CDI that are requested by the community.
Now you can create a brand new project with a single command and dive right into writing your application rather than messing around with mundane setup tasks!
Keep in mind that Maven archetypes can theoretically generate projects which don't themselves use Maven. We'll be exploring that option in the future.
The only prerequisites are to have Java 6 (Java SDK 1.6) or better and Maven 3 or better installed.
Version 1.0.1.CR1 of the Java EE 6 archetype and version 1.0.1.Beta1 of the Weld Servlet archetype are available in the Maven Central Repository. They appear in Maven's default archetype catalog as well.
The archetypes are currently functional, useful, and a great way to increase your productivity. In fact, they are probably the fastest way to get started with CDI. The Weld team and volunteers from the community, such as yourself, are working closely together to add more features. The core functionality of the archetypes is completed. At this point, we are asking for your feedback. Do they provide too little? Too much? What other features do you want?
Choose your target environment by answering one of the questions below and follow the instructions provided to create your project.
The groupId (or package) you choose for your project must be a valid Java package name.
The script below creates a Java EE 6 WAR project and builds it. The generated POM includes a plugin to publish to a JBoss AS instance if you've set JBOSS_HOME in your OS. (See these instructions for how to setup Maven to use your JBoss AS 6 installation)
# Create empty project with default values mvn archetype:generate -DinteractiveMode=n -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=central -DgroupId=com.mycompany -DartifactId=myproject # Alternatively, you can use interactive mode. Select the jboss-javaee6-webapp archetype mvn archetype:generate # Change to the new project directory cd myproject # Build project mvn package # The generated POM includes a plugin to publish to a JBoss instance if you've set JBOSS_HOME or jboss.home in a settings.xml profile. mvn jboss:hard-deploy
The next two steps create a project that targets a Servlet container and launches it in Jetty. The example can also be deployed to a running Tomcat 6 instance or run in an embedded Tomcat instance that is started with Maven.The groupId (or package) you choose for your project must be a valid Java package name!
# Create empty project with default values mvn archetype:generate -DinteractiveMode=n -DarchetypeArtifactId=jboss-jsf-weld-servlet-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.0.Beta1 -DarchetypeRepository=central -DgroupId=com.mycompany -DartifactId=myproject # Alternatively, you can use interactive mode. Select the jboss-jsf-weld-servlet-webapp archetype mvn archetype:generate # Change to the new project directory cd myproject # Build project to confirm it runs. Launch via Jetty mvn jetty:run
As you've now noticed by your console output, Maven has downloaded and configured a Jetty Servlet container and launched your application. You can now view it at http://localhost:9090/myprojectname/index.jsf.
The Maven Integration for Eclipse extension allows you to work with Maven projects in Eclipse natively. With this integration, you can create, import, manage and deploy Maven 2 and Maven 3 projects. In this case, we are interested in creating a Maven 3 project.
You can install the Maven Integration for Eclipse directly from the Eclipse Marketplace, starting with Eclipse Helios. First, select About > Eclipse Marketplace..., then search for the extension as the screenshot below shows:
Once that is installed, you'll be ready to create a new CDI and JSF 2.0 project using Eclipse.
Begin by selecting New > Project... from the File menu. Now, follow the screens (left to right, top to bottom) below to create a starter Java EE 6 project using the jboss-javaee6-webapp.The groupId (or package) you choose for your project must be a valid Java package name!
The resulting project with have the following structure.
You can now build the project just like a normal Maven 3 project, either from the command line or using the Eclipse Maven plugin controls.
If you are going to deploy the project in Eclipse, make sure you mark the default-ds.xml as a deployable resource so that the data source is properly deployed on JBoss AS.
NetBeans 6.8 includes support for Maven out of the box. It allows you to create, open and manage Maven 2 and Maven 3 projects just like regular projects. Once again, we are interested in creating a Maven 3 project.
So you are all set to create a new CDI and JSF 2.0 project using NetBeans if you have NetBeans 6.8 (with the bundled GlassFish V3) installed!
Begin by selecting New Project... from the File menu. Now, follow the screens below to create a minimal Java EE 6 project using the jboss-javaee6-webapp archetype.The groupId (or package) you choose for your project must be a valid Java package name!
Here is what the resulting project will look like:
Now, there is one small tweak that you have to make. Open pom.xml and remove the <dependency> for org.glassfish.web:el-impl since GlassFish already provides an EL implementation (the correct one).
Now, you can simply right click and run the application on GlassFish V3. GlassFish will start automatically if it isn't already running.
We're not done and we need your help. Archetypes are created to meet the needs of the users that actually write applications on a daily basis. The Weld archetypes were actually suggested and started by a user while he was learning how use Weld. In order to fit your needs and help users, it needs your contributions.
You can help by providing feedback and suggestions, code submissions, or helping to improve the documentation.
We want Weld and CDI to be successful and we cannot be successful if using our product is a frustrating or confusing experience. You can help us make Weld fit your needs. The Weld team went to great lengths to make Weld easy to configure. Now the community can help them make it easy to understand and accessible to users, both novice and advanced.