2017-06-16 12 views
0

cxf-codegen-pluginを使用してSOAPクライアントを作成するMaven jarプロジェクトがあります。でcxf-codegen-pluginで生成されたクラスの永続化を可能にする

単にデータクラス(いくつかSOAPレスポンス)のインスタンスを永続化するために必要とされるクライアントを使用して別のMavenプロジェクト - CXF-codegenを、プラグインによって生成された - JPA (現在OpenJPAの使用)。

クライアントのコンパイル/強化とインストールの前に、@Entityアノテーションをデータクラスに追加するために、各クライアントソースコードを生成した後など、いくつかの設定が必要な可能性がありますが、この段階を取り除きたいクライアントを可能な限り包括的に保ちます。クライアントを使用するプロジェクトは、そのクラスが永続化可能であると安全に仮定できるだけでなければなりません。

クライアントプロジェクトの設定では、(現在はopenjpa-maven-pluginを使用してデータクラスを拡張しています)を使用して、目的のクラスを検出して永続化することができます。

可能であれば、beans.xmlを維持するようなものをスキップしてアノテーションに固執しますが、それもオプションです。

答えて

0

誰かが同じものを必要とする場合は、私が現在使っている方法を説明します。これは、idimportsなどのフィールドを追加することに基づいています。com.google.code.maven-replacer-pluginを使用します。

まもなく:私はうまくすべてのインデントを書式設定し、ラインフィードは<replacement>秒で必要とされているコードを維持するために、私のpom.xml

<plugin> 
    <groupId>com.google.code.maven-replacer-plugin</groupId> 
    <artifactId>replacer</artifactId> 
    <version>1.5.3</version> 
    <executions> 
     <execution> 
      <phase>process-sources</phase> 
      <goals> 
       <goal>replace</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <!-- dir where cxf-codegen-plugin has generated model classes --> 
     <basedir>src/generated/java/org/example/service</basedir> 
     <includes> 
      <include>NamedEntity.java</include> 
     </includes> 
     <regex>false</regex> 
     <replacements> 
      <replacement> 
       <token>package org.example.service.service;</token> 
       <value>package org.example.service.service; 

        import javax.persistence.Id; 
        import javax.persistence.Entity; 
        import javax.persistence.Inheritance; 
        import javax.persistence.GeneratedValue; 
        import javax.persistence.InheritanceType; 

       </value> 
      </replacement> 
      <replacement> 
       <token>public class</token> 
       <value>@Entity 
        @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 
        public class</value> 
      </replacement> 
      <replacement> 
       <token>protected String name; 
       </token> 
       <value>protected String name; 

        @Id 
        @GeneratedValue 
        @Getter 
        private Long id; 

       </value> 
      </replacement> 
     </replacements> 
    </configuration> 
</plugin> 

に次のものを追加しています。 regexpsを使用するともっとスタイリッシュになるかもしれませんが、これで十分です。

関連する問題