EE5 Web Service - Maven + Eclipse + JBoss 5
In Eclipse
Create the project:
File : New : Other : Maven Project
Uncheck create a simple project (skip archetype selection)
Click Next
Select Catalog: Internal
Double-click maven-archetype-webapp
Enter Group Id: com.company.xxx
Enter Artifact Id: someName
Click Finish
Set the Java version:
Open the pom.xml
Add the following:
Create the artifacts:
Right click on the project name in Package Explorer
Select New : Source Folder
Enter src/main/java
Click Finish
Right click on the new source folder src/main/java
Select New : Package
Enter a new package name or structure
Right click on the new package name
Select New : Class
Enter the name of your new Web Service java source file
Click Finish
Implement the service:
Annotate the class with @WebService
Add whatever properties and methods are appropriate for your service
Annotate any methods to be exposed via the Web Service with @WebMethod
Configure the service:
In the Package Explorer:
Open the node src/main/webapp/WEB-INF
Double-click to edit web.xml
Add the following:
Save the web.xml file
Configure Maven:
Right click on the project name in Package Explorer
Select Run As : Maven build
Edit the name to indicate what the config is, i.e., SomeService clean compile package
Click the Goals : Select button
Hold Ctrl down to do multiple select
Under Clean Lifecycle Phases select clean
Under Build Lifecycle Phases select compile and package
Click OK
Unfortunately the order isn't correct, so change it to clean compile package
Now click Run
Check to make sure the build was successful
In the Package Explorer under the target node, there should be a project.war file
This is the application file you will copy to the JBoss server deploy directory
Configure the JBoss server:
Download jboss-5.1.0.GA and unzip it wherever you like
In the jboss_home/bin dir create a wstest.sh script and customize it as follows:
Save the file
Make it executable with chmod +x wstest.sh
Deploy the service:
Copy the project.war file created above to /someDir/java/jboss-5.1.0.GA/server/default/deploy/
Start the server:
In the /someDir/java/jboss-5.1.0.GA/bin dir
Execute the new start script created above with ./wstest.sh
Check the service:
Watch for errors starting the server and correct as necessary
Type http://localhost:8080/jbossws/services in a browser to see a list of deployed services
Click on the service URL to see the WSDL
Building EJB3 with Maven 2
An ejb.jar does not require a web.xml with servlet and servlet-mapping deployment descriptors, instead it uses the following annotations on the implementation.
Jboss Repository
.sar Service Archive
Create the project:
File : New : Other : Maven Project
Uncheck create a simple project (skip archetype selection)
Click Next
Select Catalog: Internal
Double-click maven-archetype-webapp
Enter Group Id: com.company.xxx
Enter Artifact Id: someName
Click Finish
Set the Java version:
Open the pom.xml
Add the following:
. . .
<build>
<finalName>someName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Create the artifacts:
Right click on the project name in Package Explorer
Select New : Source Folder
Enter src/main/java
Click Finish
Right click on the new source folder src/main/java
Select New : Package
Enter a new package name or structure
Right click on the new package name
Select New : Class
Enter the name of your new Web Service java source file
Click Finish
Implement the service:
Annotate the class with @WebService
Add whatever properties and methods are appropriate for your service
Annotate any methods to be exposed via the Web Service with @WebMethod
Configure the service:
In the Package Explorer:
Open the node src/main/webapp/WEB-INF
Double-click to edit web.xml
Add the following:
. . .
<web-app>
<display-name>Some Web Service Display Name</display-name>
<servlet>
<servlet-name>SomeServiceName</servlet-name>
<servlet-class>com.someCompany.SomeServiceClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SomeServiceName</servlet-name>
<url-pattern>/someUrlExtension</url-pattern>
</servlet-mapping>
</web-app>
Save the web.xml file
Configure Maven:
Right click on the project name in Package Explorer
Select Run As : Maven build
Edit the name to indicate what the config is, i.e., SomeService clean compile package
Click the Goals : Select button
Hold Ctrl down to do multiple select
Under Clean Lifecycle Phases select clean
Under Build Lifecycle Phases select compile and package
Click OK
Unfortunately the order isn't correct, so change it to clean compile package
Now click Run
Check to make sure the build was successful
In the Package Explorer under the target node, there should be a project.war file
This is the application file you will copy to the JBoss server deploy directory
Configure the JBoss server:
Download jboss-5.1.0.GA and unzip it wherever you like
In the jboss_home/bin dir create a wstest.sh script and customize it as follows:
#!/bin/bash
JAVA_HOME="/someDir/java/jdk1.6.0_13"
export JAVA_HOME
JBOSS_HOME=/someDir/java/jboss-5.1.0.GA
export JBOSS_HOME
./run.sh -c default
Save the file
Make it executable with chmod +x wstest.sh
Deploy the service:
Copy the project.war file created above to /someDir/java/jboss-5.1.0.GA/server/default/deploy/
Start the server:
In the /someDir/java/jboss-5.1.0.GA/bin dir
Execute the new start script created above with ./wstest.sh
Check the service:
Watch for errors starting the server and correct as necessary
Type http://localhost:8080/jbossws/services in a browser to see a list of deployed services
Click on the service URL to see the WSDL
Building EJB3 with Maven 2
An ejb.jar does not require a web.xml with servlet and servlet-mapping deployment descriptors, instead it uses the following annotations on the implementation.
@Statelss
@WebContext(contextRoot="/someContext", urlPattern="/somePattern")
@WebService
Jboss Repository
.sar Service Archive
Comments