2012-10-31 32 views
6

Çalışmamda kod üretimi için jaxws-maven eklentisi kullanıldı. Ben iki proje ' "ortak" ve' müvekkilimdin var". Yapısı kabaca şöyle:Farklı dizinlerde XSD ve WSDL

app/ 
  common/ 
   resource/ 
    some.xsd 
  client/ 
   resource/ 
    some.wsdl 

nasıl proje içinde wsdl gelen sınıfları oluşturabilir ' '' projesinden xsd kullanarak,' istemci ortak ?

pom.xml.

  <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>jaxws-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>wsimport</goal> 
        </goals> 
        <configuration> 
         <verbose>true</verbose> 
         <bindingFiles> 
          <bindingFile>${project.parent.basedir}/common/resource/some.xsd</bindingFile> 
         </bindingFiles> 
         <wsdlFiles> 
          <wsdlFile>/resource/some.wsdl</wsdlFile> 
         </wsdlFiles> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
Eğer kaynaklar için src/main/resources/ dizinleri kullanmak, maven sözleşmeler tutması gerektiğini Herşeyden

cevap

6

İlk

A fter ardından erişmek common kavanoz dosyasını açmak için maven-dependency-plugin:unpack-dependencies kullanabilirsiniz yapıyor some.xsd:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
     <groupId>com.stackoverflow.Q13155047</groupId> 
     <artifactId>app</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>client</artifactId> 

    <name>${project.artifactId}-${project.version}</name> 

    <properties> 
     <schema.location>${project.build.directory}/schemas</schema.location> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.stackoverflow.Q13155047</groupId> 
      <artifactId>common</artifactId> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.5.1</version> 
       <executions> 
        <execution> 
         <id>unpack-dependencies</id> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>unpack-dependencies</goal> 
         </goals> 
         <configuration> 
          <includes>**/*.xsd</includes> 
          <outputDirectory>${schema.location}</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxws-maven-plugin</artifactId> 
       <executions> 
        <execution> 
         <goals> 
          <goal>wsimport</goal> 
         </goals> 
         <configuration> 
          <verbose>true</verbose> 
          <bindingDirectory>${schema.location}</bindingDirectory> 
          <bindingFiles> 
           <bindingFile>some.xsd</bindingFile> 
          </bindingFiles> 
          <wsdlDirectory>src/main/resources</wsdlDirectory> 
          <wsdlFiles> 
           <wsdlFile>some.wsdl</wsdlFile> 
          </wsdlFiles> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

jaxws-maven-plugin böylece ekleyerek generate-sources faza maven-dependency-pluginjaxws-maven-plugin önce ve aynı faz modellerine wsimport hedefini uygulamadan önce her şeyi açtığından emin olun.

<bindingDirectory/> ve <wsdlDirectory/>'un doğruluğundan emin olun.


Bu, başka bir projede *.xsd dosyanız varsa bunu nasıl olduğunu. Asla göreceli yollarla diğer projelere erişme. Her proje bağımlılık mekanizmasını kullanarak sadece diğer kaynaklara erişmelidir.

+0

Teşekkür ederiz! Sadece tüm göreceli yolları aşmaya çalışıyorum. –

+2

Bu bağlantıya göre - maven wsimport eklentisi tarafından kullanılan varsayılan konum src/wsdl'dir. Ben .wsdl src/main/resources tutulması gerektiğini çıkarsam. https://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html – RuntimeException

+1

$ {schema.location} dizinine açtığınızda WSDL'deki XSD'lere nasıl başvuruyorsunuz? WSDL, XSD'leri nerede bulacağını nasıl biliyor? –