이 콘텐츠는 선택한 언어로 제공되지 않습니다.

10.2. Generating and Running a Web Services Bundle


Overview

This section explains how to generate, build, and run a complete Apache CXF example as a bundle in the OSGi container, where the starting point code is generated with the help of a Maven archetype.

Prerequisites

In order to generate a project using a Red Hat JBoss Fuse Maven archetype, you must have the following prerequisites:
  • Maven installation—Maven is an open source build tool from Apache. You can download the latest version from http://maven.apache.org/download.html (minimum is 3.x).
  • Internet connection—whilst performing a build, Maven dynamically searches external repositories and downloads the required artifacts on the fly. In order for this to work, your build machine must be connected to the Internet.
  • fusesource Maven repository is configured—in order to locate the archetypes, Maven's settings.xml file must be configured with the location of the fusesource Maven repository. For details of how to set this up, see the section called “Adding the Red Hat JBoss Fuse repository”.

Generating a Web services bundle

The karaf-soap-archetype archetype creates a project for building a Java-first JAX-WS application that can be deployed into the OSGi container. To generate a Maven project with the coordinates, org.fusesource.example:cxf-code-first-bundle, enter the following command:
mvn archetype:generate \
  -DarchetypeGroupId=io.fabric8.archetypes \
  -DarchetypeArtifactId=karaf-soap-archetype \
  -DarchetypeVersion=1.2.0.redhat-621084 \
  -DgroupId=org.fusesource.example \
  -DartifactId=cxf-code-first-bundle \
  -Dversion=1.0-SNAPSHOT \
  -Dfabric8-profile=cxf-code-first-bundle-profile
Copy to Clipboard Toggle word wrap
Note
The backslash character, \, indicates line continuation on Linux and UNIX operating systems. On Windows platforms, you must omit the backslash character and put all of the arguments on a single line.
The result of this command is a directory, ProjectDir/cxf-code-first-bundle, containing the files for the generated bundle project.

Modifying the bundle instructions

Typically, you will need to modify the instructions for the Maven bundle plug-in in the POM file. In particular, the default Import-Package element generated by the servicemix-cxf-code-first-osgi-bundle archetype is not configured to scan the project's Java source files. In most cases, however, you would want the Maven bundle plug-in to perform this automatic scanning in order to ensure that the bundle imports all of the packages needed by your code.
To enable the Import-Package scanning feature, simply add the wildcard, *, as the last item in the comma-separated list inside the Import-Package element, as shown in the following example:

Example 10.1. Import-Package Instruction with Wildcard

<project ... >
    ...
    <build>
        <plugins>
          <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>${version.maven-bundle-plugin}</version>
            <extensions>true</extensions>
            <configuration>
              <instructions>
                <Import-Package>javax.jws;version="[0,3)",
                  javax.wsdl,
                  javax.xml.namespace,
                  org.apache.cxf.helpers,
                  org.osgi.service.blueprint,
                  io.fabric8.cxf.endpoint,
                  org.apache.cxf.transport.http,
                  *
                </Import-Package>
                <Import-Service>org.apache.aries.blueprint.NamespaceHandler;
                    osgi.service.blueprint.namespace=http://cxf.apache.org/transports/http/configuration</Import-Service>
                <Export-Package>org.fusesource.example</Export-Package>
              </instructions>
            </configuration>
          </plugin>
        </plugins>
    </build>
    ...
</project>
Copy to Clipboard Toggle word wrap

Running the Web services bundle

To install and run the generated cxf-code-first-bundle project, perform the following steps:
  1. Build the project—open a command prompt and change directory to ProjectDir/cxf-code-first-bundle. Use Maven to build the demonstration by entering the following command:
    mvn install
    Copy to Clipboard Toggle word wrap
    If this command runs successfully, the ProjectDir/cxf-code-first-bundle/target directory should contain the bundle file, cxf-code-first-bundle.jar.
  2. Install and start the cxf-code-first-bundle bundle—at the Red Hat JBoss Fuse console, enter the following command to install the bundle from your local Maven repository:
    JBossFuse:karaf@root> osgi:install -s mvn:org.fusesource.example/cxf-code-first-bundle/1.0-SNAPSHOT
    Copy to Clipboard Toggle word wrap
  3. Test the Web serivce—to test the Web service deployed in the previous step, you can use a web browser to query the service's WSDL. Open your favourite web browser and navigate to the following URL:
    http://localhost:8181/cxf/HelloWorld?wsdl
    Copy to Clipboard Toggle word wrap
    When the web service receives the query, ?wsdl, it returns a WSDL description of the running service.
  4. Stop the cxf-code-first-bundle bundle—to stop the cxf-code-first-bundle bundle, you first need to discover the relevant bundle number. To find the bundle number, enter the following console command:
    JBossFuse:karaf@root> osgi:list
    Copy to Clipboard Toggle word wrap
    At the end of the listing, you should see an entry like the following:
    [ 266] [Active     ] [Created     ] [       ] [   80] JBoss Fuse Quickstart: soap (1.0.0.SNAPSHOT)
    Copy to Clipboard Toggle word wrap
    Where, in this example, the bundle number is 266. To stop this bundle, enter the following console command:
    JBossFuse:karaf@root> osgi:stop 266
    Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat