-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d178c5b
commit 3b1ce6d
Showing
10 changed files
with
390 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0"?> | ||
<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>org.jboss.as.quickstarts</groupId> | ||
<artifactId>jboss-as-ejbinwar</artifactId> | ||
<version>7.1.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<name>JBoss AS Quickstarts: EJB in War</name> | ||
<description>JBoss AS Quickstarts: EJB in War</description> | ||
|
||
<url>http://jboss.org/jbossas</url> | ||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<distribution>repo</distribution> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<!-- Explicitly declaring the source encoding eliminates the following | ||
message: --> | ||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered | ||
resources, i.e. build is platform dependent! --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<!-- Define the version of JBoss' Java EE 6 APIs we want to import. | ||
Any dependencies from org.jboss.spec will have their version defined by this | ||
BOM --> | ||
<!-- JBoss distributes a complete set of Java EE 6 APIs including | ||
a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or | ||
a collection) of artifacts. We use this here so that we always get the correct | ||
versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can | ||
read this as the JBoss stack of the Java EE 6 APIs). You can actually | ||
use this stack with any version of JBoss AS that implements Java EE 6, not | ||
just JBoss AS 7! --> | ||
<dependency> | ||
<groupId>org.jboss.spec</groupId> | ||
<artifactId>jboss-javaee-6.0</artifactId> | ||
<version>3.0.0.Beta1</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
<!-- Import the CDI API, we use provided scope as the API is included | ||
in JBoss AS 7 --> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the Common Annotations API (JSR-250), we use provided scope | ||
as the API is included in JBoss AS 7 --> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.annotation</groupId> | ||
<artifactId>jboss-annotations-api_1.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the JSF API, we use provided scope as the API is included | ||
in JBoss AS 7 --> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.faces</groupId> | ||
<artifactId>jboss-jsf-api_2.0_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Import the EJB API, we use provided scope as the API is included in | ||
JBoss AS 7 --> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.ejb</groupId> | ||
<artifactId>jboss-ejb-api_3.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<!-- Set the name of the war, used as the context root when the app | ||
is deployed --> | ||
<finalName>jboss-as-ejbinwar</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.1.1</version> | ||
<configuration> | ||
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch | ||
up! --> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
<!-- JBoss AS plugin to deploy war --> | ||
<plugin> | ||
<groupId>org.jboss.as.plugins</groupId> | ||
<artifactId>jboss-as-maven-plugin</artifactId> | ||
<version>7.1.0.Beta1b</version> | ||
</plugin> | ||
<!-- Compiler plugin enforces Java 1.6 compatibility and activates | ||
annotation processors --> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.1</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
ejb-in-war | ||
======================== | ||
|
||
What is it? | ||
----------- | ||
|
||
This example demonstrates the deployment of an *EJB 3.1* bean bundled in a war archive for deployment to *JBoss AS 7*. | ||
|
||
The example follows the common "Hello World" pattern. These are the steps that occur: | ||
|
||
1. A JSF page asks the user for their name. | ||
2. On clicking submit, the name is sent to a managed bean (Greeter). | ||
3. On setting the name, the Greeter invokes the GreeterEJB, which was injected to the managed bean (notice the field annotated with @EJB). | ||
4. The response from invoking the GreeterEJB is stored in a field (message) of the managed bean. | ||
5. The managed bean is annotated as @SessionScoped, so the same managed bean instance is used for the entire session. This ensures that the message is available when the page reloads and is | ||
displayed to the user. | ||
|
||
System requirements | ||
------------------- | ||
|
||
All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven | ||
3.0 or better. | ||
|
||
The application this project produces is designed to be run on a JBoss AS 7 or EAP 6. | ||
The following instructions target JBoss AS 7, but they also apply to JBoss EAP 6. | ||
|
||
With the prerequisites out of the way, you're ready to build and deploy. | ||
|
||
Deploying the application | ||
------------------------- | ||
|
||
First you need to start JBoss AS 7 (or EAP 6). To do this, run | ||
|
||
$JBOSS_HOME/bin/standalone.sh | ||
|
||
or if you are using windows | ||
|
||
$JBOSS_HOME/bin/standalone.bat | ||
|
||
To deploy the application, you first need to produce the archive to deploy using | ||
the following Maven goal: | ||
|
||
mvn package | ||
|
||
You can now deploy the artifact to JBoss AS by executing the following command: | ||
|
||
mvn jboss-as:deploy | ||
|
||
This will deploy `target/jboss-as-ejbinwar.war`. | ||
|
||
The application will be running at the following URL <http://localhost:8080/jboss-as-ejbinwar>. | ||
|
||
To undeploy from JBoss AS, run this command: | ||
|
||
mvn jboss-as:undeploy | ||
|
||
You can also start JBoss AS 7 and deploy the project using Eclipse. See the JBoss AS 7 | ||
Getting Started Guide for Developers for more information. | ||
|
||
Importing the project into an IDE | ||
================================= | ||
|
||
If you created the project using the Maven archetype wizard in your IDE | ||
(Eclipse, NetBeans or IntelliJ IDEA), then there is nothing to do. You should | ||
already have an IDE project. | ||
|
||
Detailed instructions for using Eclipse with JBoss AS 7 are provided in the | ||
JBoss AS 7 Getting Started Guide for Developers. | ||
|
||
If you created the project from the commandline using archetype:generate, then | ||
you need to import the project into your IDE. If you are using NetBeans 6.8 or | ||
IntelliJ IDEA 9, then all you have to do is open the project as an existing | ||
project. Both of these IDEs recognize Maven projects natively. | ||
|
||
Downloading the sources and Javadocs | ||
==================================== | ||
|
||
If you want to be able to debug into the source code or look at the Javadocs | ||
of any library in the project, you can run either of the following two | ||
commands to pull them into your local repository. The IDE should then detect | ||
them. | ||
|
||
mvn dependency:sources | ||
mvn dependency:resolve -Dclassifier=javadoc |
69 changes: 69 additions & 0 deletions
69
ejb-in-war/src/main/java/org/jboss/as/quickstarts/ejbinwar/controller/Greeter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, | ||
* and individual contributors as indicated by the @author tags. | ||
* See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* This copyrighted material is made available to anyone wishing to use, | ||
* modify, copy, or redistribute it subject to the terms and conditions | ||
* of the GNU Lesser General Public License, v. 2.1. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT A | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public License, | ||
* v.2.1 along with this distribution; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
* | ||
* (C) 2011, | ||
* @author JBoss, by Red Hat. | ||
*/ | ||
|
||
package org.jboss.as.quickstarts.ejbinwar.controller; | ||
|
||
import org.jboss.as.quickstarts.ejbinwar.ejb.GreeterEJB; | ||
import javax.ejb.EJB; | ||
import javax.enterprise.context.SessionScoped; | ||
import javax.inject.Named; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* A simple managed bean that is used to invoke the GreeterEJB and store the response. The response is obtained by | ||
* invoking getMessage(). | ||
* | ||
* @author paul.robinson@redhat.com, 2011-12-21 | ||
*/ | ||
@Named("greeter") | ||
@SessionScoped | ||
public class Greeter implements Serializable { | ||
|
||
/** | ||
* Injected GreeterEJB client | ||
*/ | ||
@EJB | ||
private GreeterEJB greeterEJB; | ||
|
||
/** | ||
* Stores the response from the call to greeterEJB.sayHello(...) | ||
*/ | ||
private String message; | ||
|
||
/** | ||
* Invoke greeterEJB.sayHello(...) and store the message | ||
* | ||
* @param name The name of the person to be greeted | ||
*/ | ||
public void setName(String name) { | ||
message = greeterEJB.sayHello(name); | ||
} | ||
|
||
/** | ||
* Get the greeting message, customized with the name of the person to be greeted. | ||
* | ||
* @return message. The greeting message. | ||
*/ | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
ejb-in-war/src/main/java/org/jboss/as/quickstarts/ejbinwar/ejb/GreeterEJB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, | ||
* and individual contributors as indicated by the @author tags. | ||
* See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* This copyrighted material is made available to anyone wishing to use, | ||
* modify, copy, or redistribute it subject to the terms and conditions | ||
* of the GNU Lesser General Public License, v. 2.1. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT A | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public License, | ||
* v.2.1 along with this distribution; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
* | ||
* (C) 2011, | ||
* @author JBoss, by Red Hat. | ||
*/ | ||
|
||
package org.jboss.as.quickstarts.ejbinwar.ejb; | ||
|
||
import javax.ejb.Stateful; | ||
|
||
/** | ||
* A simple Hello World EJB. The EJB does not use an interface. | ||
* | ||
* @author paul.robinson@redhat.com, 2011-12-21 | ||
*/ | ||
@Stateful | ||
public class GreeterEJB | ||
{ | ||
/** | ||
* This method takes a name and returns a personalised greeting. | ||
* | ||
* @param name the name of the person to be greeted | ||
* @return the personalised greeting. | ||
*/ | ||
public String sayHello(String name) { | ||
return "Hello " + name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Marker file indicating CDI 1.0 should be enabled --> | ||
|
||
<beans 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/beans_1_0.xsd"> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- Marker file indicating JSF 2.0 should be enabled in the application --> | ||
|
||
<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> |
Oops, something went wrong.