-2

Webサービスを含むMavenプロジェクトであるOSGiバンドルを構築しようとしています。@WebService使用しているWebサービスを指定するために、すべてのアノテーションを含むJAX-WSを使用しています。これらのWebサービスを通常使用しているクライアントの場所にロードし、wsgenWSDLwsimportファイルをエクスポート/インポートします。jaxws-maven-pluginを使用してこれを行う予定ですが、ここに問題があります。

バンドルは、サーバーとクライアントとして同時に機能できます。同じバンドルの親ノード(別のJVM /ホストで実行)にクライアントとして登録できます。したがって、このMavenプロジェクト/バンドルは、Webサービスのインターフェースを定義し、このインターフェースを実装する実装クラスを定義します。インターフェイスとクラスの両方@WebServiceが通常どおりアノテーションを使用します。

@WebService
public interface Example {
    public void callMe();
}

@WebService
public class ExampleImpl implements Example {
    public void callMe() {};
}

そして、私のコードのどこかに:

Endpoint p = Endpoint.publish(
                 "http://localhost:8080/example",
                 new ExampleImpl());    

jaxws :wsgenゴールは注釈を読み取り、出力ファイル(.classファイル、.javaファイル、WSDLファイル、構成に応じて...)を作成します。しかし、同じ実行のjaxws:wsimportゴール中にこれらのファイルを使用するにはどうすればよいですか?mvn package同じMavenプロジェクトで、このWebサービスを使用したいので、次のように記述する必要があります。

ExampleImplService service = new ExampleImplService();
Example port = service.getExampleImplPort();
port.callMe();

jaxws:gen目標は、process-classesコンパイルされたクラスを読み取る必要があるため、フェーズで実行されますが、コンパイルのためにすべてを準備するjaxws:importには、フェーズで実行する必要があります。generate-sourcesそして今、私は鶏が先か卵が先かという問題に直面しています。を介して出力ファイルを生成するには、コンパイルされたクラスが必要ですが、Mavenのフェーズでのforwsgenの出力ファイルが必要です。私の最初の試みは、目標をフェーズにも割り当てることでしたが、クラスが欠落しているか、まだコンパイルされていないため、もちろん機能しません。wsgenwsimportgenerate-sourcesjaxws:wsgengenerate-sources

この問題を解決するための私のオプションは何ですか?フェーズの前にいくつかのクラス(つまり、アノテーション付きのクラスのみ)antrunをコンパイルして、それを(そのフェーズで)使用できるようにするという目標を実行し、フェーズで使用される出力ファイルを作成する必要がありますか?この鶏が先か卵が先かという問題を解決する他の方法はありますか?同じMavenプロジェクトでWebサービスのサーバーとクライアントの部分をコンパイルするための他の「Mavenの方法」はありますか?ところで、それはすべきです。クリーンビルドから実行するので、「 2回実行して最初にWebサービスファイルを生成し、次に他のすべてをコンパイルする」などのソリューションは必要ありません。言い換えると、mavenプロジェクト/osgiバンドル全体をコンパイルする必要があります。@WebServicegenerate-sourcesjaxws:wsgenjaxws:wsimportgenerate-sourcesmvn cleanmvn packagemvn clean package

4

1 に答える 1

1

jaxsw:wsgen目標をgenerate-sourcesフェーズに移すことで、この問題を解決することができました。次の手順を使用します。

  1. まず、クラスのコンパイルに使用する実行@WebServiceを介して、アノテーション付きのクラスをコンパイルします。結果の.classファイルを一時ディレクトリに保存します。この一時ディレクトリは、クライアントスタブを作成した後に削除されます。antrun<javac>
  2. コンパイルされた.classファイルからWSDLファイルを作成しますjaxws:wsgen
  3. 一時ディレクトリから、通常のjaxws:wsimport目標でクライアントスタブを作成します。
  4. antrun2回目の実行で一時ディレクトリを削除します。

結果のpom.xmlファイルは次のようになります(関連する部分のみ)

<properties>
    <tmpdirectory>${java.io.tmpdir}${file.separator}${user.name}-${project.groupId}-${project.artifactId}</tmpdirectory>
</properties>
...
        <plugin>
            <!-- clean tmp directory at every "mvn clean" -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>${tmpdirectory}</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <dependencies>
                  <dependency>
                      <groupId>com.sun</groupId>
                      <artifactId>tools</artifactId>
                      <version>1.6.0</version>
                      <scope>system</scope>
                      <systemPath>${java.home}/../lib/tools.jar</systemPath>
                  </dependency>
            </dependencies>  
            <executions>
                <execution>
                    <!-- compile webservice classes into tmp directory -->
                    <id>mini compile of webservices</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <property name="compile_classpath" refid="maven.compile.classpath"/>
                            <mkdir dir="${tmpdirectory}" />
                            <javac includeAntRuntime="false"
                                   classpath="${compile_classpath}"
                                   destdir="${tmpdirectory}">
                                <src path="${project.build.sourceDirectory}" />
                                <include name="org/example/project/*/webservice/*.java" />
                            </javac>
                        </target>
                    </configuration>
                </execution>
                <execution>
                    <!-- delete temporary directory (in case mvn clean is not called) -->
                    <id>clean up tmp dir</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <delete dir="${tmpdirectory}" />
                        </target>
                    </configuration>
                </execution>
            </executions>  
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>1.10</version>
            <executions>
                <execution>
                    <!-- generate WSDL file from the compiled classes in tmp directory -->
                    <id>generate wsdl file</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsgen</goal>
                    </goals>
                    <configuration>
                        <sei><!-- service endpoint implementation  --></sei>
                        <destDir>${tmpdirectory}</destDir>
                        <genWsdl>true</genWsdl>
                        <resourceDestDir>${tmpdirectory}</resourceDestDir>
                    </configuration>
                </execution>
                <execution>
                    <!-- create client stub files -->
                    <id>create client files from wsdl file</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <keep>true</keep>
                        <wsdlDirectory>${tmpdirectory}</wsdlDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
于 2011-02-18T20:14:42.917 に答える