JBossWS - Setup your IDE

Even if you can create, build and deploy your web service application with a simple text editor and a shell console, a properly configured IDE and/or Ant build file might help you and speed up your development.

JBossWS Testsuite Eclipse project

Since 3.0.1 (Native, Metro, CXF)

The JBossWS - Samples testsuite covers the web service functionalities we currently support with every stack. Running its tests is indeed a good idea to start your web service training. Even if the testsuite can be run using the provided Ant scripts, you might want to run the JUnit test and look at their results directly in your IDE. For this reason a testsuite project can be generated and imported in Eclipse (further IDE might be supported in future).

Generating the project

Creating the Eclipse testsuite project is really straightforward: once you have copied/edited your ant.properties configuration file, you just need to run ant eclipse from your binary distribution directory. This will create some files, including a lot of *.launch ones, containing the Eclipse configuration.

Then you just need to import the project into Eclipse: right click in 'Package Explorer -> Import...', select 'General -> Existing Projects into Workspace', then click on 'Next' and set the root directory browsing to your binary distro directory. You'll find the JBossWS Testuite project: import it and note the samples only sources are included.

Running the tests

Once you have imported the project, you need to start the JBoss application server that is configured in your ant.properties file and that you deployed JBossWS to. Then, back in your Eclipse, you open a test case class and use the JUnit plugin to run it.

 

RunAsJUnitTest.png


You'll see the test being executed and finally the results with the runs, errors and failures summary as well as the client side console.

 

TestResults.png

 

Of course you can play with the tests, edit them and instantly run them again. That's easy.

JBossWS user project generator

Since 3.0.1 (Native, Metro, CXF)

In order to increase the web service user productivity, JBossWS native ships with an Ant-based web service project generator. This can be used to automatically create a simple project along with an Ant build file to compile and deploy it as well as a basic Eclipse configuration (further IDEs might be supported in future). The most commonly required libraries are referenced from the user specified JBoss application server home, so that the user simply needs to code its web service provider / consumer application.

Configuring a new project

The JBossWS user project generator is triggered by the main JBossWS build available in every binary release. You just need to run the setup-new-project target and answer to a few questions about the project you'd like to create:

  • project workspace: this is where the generator will create your project directory
  • project name
  • project type: this can be either jar or war depending on your need for EJB3 components support
[alessio@localhost jbossws-native-dist]$ ant setup-new-project
Buildfile: build.xml

tests-prepare:
     [echo] 
     [echo] -----------------------------------------------
     [echo] jboss.home   = /dati/jboss-4.2.2.GA
     [echo] excludesfile = ${excludesfile}
     [echo] java.home    = /usr/java/jdk1.5.0_13/jre
     [echo] jboss.bind   = localhost
     [echo] -----------------------------------------------

tests-classpath-jboss50:

tests-classpath-jboss42:

tests-classpath:

init-project-properties:

setup-new-project:
     [echo] -------------------------------------------------
     [echo]   Welcome to the JBossWS user project generator
     [echo] -------------------------------------------------
     [echo] 
    [input] Enter your Java project workspace (the directory that contains your projects)  [C:/Projects]
/dati/project/ws
    [input] Enter the project name  [myproject]
TestProject
    [input] Is this project deployed as an JAR (with EJB3 components) or a WAR (with no EJB3 support)  ([jar], war)
jar
[propertyfile] Creating new property file: /home/alessio/dati/jbossws/stack/native/trunk/output/jbossws-native-dist/user-project.properties
     [echo] 
     [echo] Your project settings have been saved in file 'user-project.properties'.
     [echo] Please type 'ant create-project' to create the new project.

BUILD SUCCESSFUL
Total time: 32 seconds

Once this has been executed, the generator writes your settings to the user-project.properties file (it creates it during the first run). As you can see the script gets the JBoss installation home and the configuration/instance to use from the current ant.properties file.

[alessio@localhost jbossws-native-dist]$ cat user-project.properties 
#Generated by JBossWS user project setup
#Fri Mar 14 10:05:47 CET 2008
project.name=TestProject
project.jboss.home=/dati/jboss-4.2.2.GA
project.type=jar
workspace.home=/dati/project/ws
project.jboss.conf=default

Creating the project

Given your settings, creating the project is straightforward. You just need to run the create-project target of the JBossWS main build:

[alessio@localhost jbossws-native-dist]$ ant create-project
Buildfile: build.xml

tests-prepare:
     [echo] 
     [echo] -----------------------------------------------
     [echo] jboss.home   = /dati/jboss-4.2.2.GA
     [echo] excludesfile = ${excludesfile}
     [echo] java.home    = /usr/java/jdk1.5.0_13/jre
     [echo] jboss.bind   = localhost
     [echo] -----------------------------------------------

tests-classpath-jboss50:

tests-classpath-jboss42:

tests-classpath:

init-project-properties:

validate-settings:

configure-project:
    [mkdir] Created dir: /dati/project/ws/TestProject/src/main/java
    [mkdir] Created dir: /dati/project/ws/TestProject/src/main/resources
     [copy] Copying 1 file to /dati/project/ws/TestProject
     [copy] Copying 1 file to /dati/project/ws/TestProject

create-project:
     [echo] A basic webservice project named 'TestProject' has been created in the /dati/project/ws directory.
     [echo] It includes a simple Ant build file and references the required libraries.
     [echo] Please refer to http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS for the authoritative documentation.
     [echo] 
     [echo] If you are an Eclipse user, import the project into Eclipse: right click in 
     [echo] 'Package Explorer -> Import...' and select 'General -> Existing Projects into Workspace'.
     [echo] Then click on 'Next' and set the root directory browsing to your workspace directory.

BUILD SUCCESSFUL
Total time: 0 seconds

The generator simply creates a new project according to the settings in the user-project.properties file; the right libraries are referenced from the currently configured JBoss AS installation.

Please note that different AS versions require different sets of libraries, thus it's important to carefully set the jbossws.integration.target properties in the ant.properties file before running this script.

Using the project

The new project comes with a simple Eclipse configuration you might want to import: right click in 'Package Explorer -> Import...', select 'General -> Existing Projects into Workspace', then click on 'Next' and set the root directory browsing to your workspace directory.

An Ant build.xml file is also created and can be used both from command line and from Eclipse; it has the following targets:

  • compile: compiles the Java source code
  • copyclasses: copys the classes that were compiled by Eclipse
  • deploy: deploys to JBoss AS
  • dist: creates the application distribution archive
  • undeploy: undeploys from JBoss AS

You're most probably going to need deploy and undeploy only.

Your new basic project is ready; you can start creating your web service endpoint or client. Of course both the build file and the Eclipse configuration are meant to be the starting point for a common WS-enabled project; you may want to edit them according to your business requirements and/or fine setting preferences. For instance, one of the most common changes you're probably going to do is adding some proprietary libraries to the build: take a look at the generated libraries.xml file that is imported by the generated build.xml.