2011-07-15 22 views
6

Tóm tắt nhanh về tình huống của tôi - Tôi đang làm việc trên cơ sở mã có giao diện/lớp chú thích JAX-WS chúng tôi tạo ra các wsdls mã đầu tiên. Chúng tôi đang sử dụng cxf-java2ws-plugin của CXF để tạo các wsdls tại thời gian xây dựng bên trong maven để đưa vào bên trong .jar được tạo cho mỗi mô-đun.

gì chúng tôi muốn làm là triển khai những tập tin này wsdl đến một kho maven từ kho maven thể hoạt động như

  • một kho lưu trữ dịch vụ tạm thời (như mô tả here)
  • cung cấp cho khách hàng một cách dễ dàng cách sử dụng cxf codegen plugin bằng cách chỉ đến maven phối cho một wsdl thay vì quản lý wsdl tập tin bản thân

những gì tôi đã có cho đến nay là một tập tin pom có ​​sử dụng phụ thuộc: giải nén-phụ thuộc để có được tất cả của các tệp wsdl trong dự án vào một thư mục trong mô-đun này $ {project.build.directory} (thường được gọi là target/to everyone out there).

Điều tôi không biết phải làm là lặp qua từng tệp này và gọi deploy:deploy-file mojo trên mỗi wsdl. Các tùy chọn của tôi ở đây là gì vì tôi thực sự muốn tự động hóa quy trình triển khai các tệp wsdl này và không có ai từng triển khai chúng theo cách thủ công?

Đối với đầy đủ lợi ích, đây là tập tin pom:

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
     xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <artifactId>rice</artifactId> 
     <groupId>org.kuali.rice</groupId> 
     <version>2.0.0-m7-SNAPSHOT</version> 
    </parent> 
    <artifactId>rice-dist-wsdl</artifactId> 
    <name>Rice WSDL Distributions</name> 
    <packaging>pom</packaging> 

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


    <!-- Depends on all API modules and modules that generate or contain wsdls --> 
    <dependencies> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-core-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-kew-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-kim-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-krms-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-ksb-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-shareddata-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>unpack-wsdls</id> 
         <phase>generate-resources</phase> 
         <goals> 
          <goal>unpack-dependencies</goal> 
         </goals> 
         <configuration> 
          <includes>**\/*.wsdl</includes> 
          <outputDirectory>${project.build.directory}</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

nào dìm các WSDLs trong mục tiêu/wsdl (họ được chứa trong wsdl/bên trong mỗi .jar bị phụ thuộc vào):

[[email protected] ~/Repositories/Kuali/rice/dist-wsdl] 
> find . -iname '*.wsdl' | head -3 
./target/wsdl/CampusService.wsdl 
./target/wsdl/CountryService.wsdl 
./target/wsdl/CountyService.wsdl 

giải pháp

tưởng wha Tôi đã thực hiện khác với câu trả lời được chấp nhận do Ryan Steward cung cấp, tôi chấp nhận câu trả lời của anh ấy vì nó đã dẫn tôi viết câu trả lời của riêng tôi.

Về cơ bản, đây là một maven pom đó là một submodule trong dự án đa mô-đun được mô tả ở trên. Tôi đang sử dụng sự phụ thuộc: unpack-dependencies và sau đó sử dụng một kịch bản lệnh groovy trực tuyến để gọi deploy: deploy-file trên từng tệp wsdl đó. Đó là một chút của một hackjob, nhưng tôi không thể nghĩ ra một cách tốt hơn để làm điều này mà không cần hardcoding đường dẫn đến các tập tin wsdl trong mô-đun và gọi một số thực thi triển khai: triển khai tập tin mojo trên chúng, dẫn đến một rất tiết pom.

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
     xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <artifactId>rice</artifactId> 
     <groupId>org.kuali.rice</groupId> 
     <version>2.0.0-m7-SNAPSHOT</version> 
    </parent> 
    <artifactId>rice-dist-wsdl</artifactId> 
    <name>Rice WSDL Distributions</name> 
    <packaging>pom</packaging> 

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


    <!-- Depends on all API modules and modules that generate or contain wsdls --> 
    <dependencies> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-core-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-kew-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-kim-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-krms-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-ksb-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>rice-shareddata-api</artifactId> 
      <version>${project.version}</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>unpack-wsdls</id> 
         <phase>generate-resources</phase> 
         <goals> 
          <goal>unpack-dependencies</goal> 
         </goals> 
         <configuration> 
          <includes>**\/*.wsdl</includes> 
          <outputDirectory>${project.build.directory}</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.gmaven</groupId> 
       <artifactId>gmaven-plugin</artifactId> 
       <executions> 
        <execution> 
         <phase>deploy</phase> 
         <goals> 
          <goal>execute</goal> 
         </goals> 
         <configuration> 
          <source> 
           def repo_url 
           def repo_id 
           if ("${project.version}".endsWith("SNAPSHOT")) { 
            repo_url = "${kuali.repository.snapshot.url}" 
            repo_id = "${kuali.repository.snapshot.id}" 
           } else { 
            repo_url = "${kuali.repository.release.url}" 
            repo_id = "${kuali.repository.release.id}" 
           } 

           def wsdlGroupId = "${project.groupId}.wsdl" 
           new File("${wsdl.location}").eachFile() { file -> 
            serviceName = file.name.split("\\.")[0] 

            log.info("Deploying ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}") 

            execString = "mvn deploy:deploy-file -Dfile=${file} -Durl=${repo_url} -DrepositoryId=${repo_id} " 
            execString += "-DgroupId=${wsdlGroupId} -DartifactId=${serviceName} " 
            execString += "-Dversion=${project.version} -Dpackaging=wsdl -Dclassifier=wsdl" 

            def proc = execString.execute() 
            proc.waitFor() 

            err = proc.err.text 
            if (err != null &amp;&amp; err.length() > 0) { 
             log.error(err) 
             fail("Deployment failed for ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}. \n Run in verbose mode for full error.") 
            } else { 
             log.info("Successfully deployed ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}") 
            } 
           } 
          </source> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

</project> 
+0

Tôi thích điều này rất nhiều. Tôi cần phải làm một cái gì đó tương tự. –

Trả lời

2

Một khả năng khác: nhiệm vụ Ant Maven có thể deploy files. Tôi đã không bao giờ sử dụng nó, nhưng tôi sẽ đặt cược bạn có thể sử dụng một cấu hình antrun và một số mô hình phù hợp với kiến ​​để nhận và triển khai tất cả các WSDLs.

+1

Tôi đã làm một cái gì đó tương tự như thế này, nhưng với GMaven (plugin maven groovy) bằng cách in-lót một kịch bản vòng lặp các tên tập tin wsdl và gọi 'mvn deploy: deploy-file trên mỗi người trong số họ. Cảm ơn câu trả lời của bạn và làm cho tôi nghĩ để làm điều đó. – whaley

2

Plugin Trình trợ giúp xây dựng có thể giúp bạn. Bạn có thể làm cho nó xuất bản các WSDL, nhưng bạn sẽ phải liệt kê từng cái một cách rõ ràng, và tất cả chúng sẽ có artifactId của pom của bạn trong tên của chúng. Chỉ có trình phân loại mới có thể thay đổi. Ví dụ:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>1.7</version> 
    <executions> 
     <execution> 
      <id>attach-WSDLs</id> 
      <phase>package</phase> 
      <goals> 
       <goal>attach-artifact</goal> 
      </goals> 
      <configuration> 
       <artifacts> 
        <artifact> 
         <file>${project.build.directory}/foo.wsdl</file> 
         <classifier>foo</classifier> 
         <type>wsdl</type> 
        </artifact> 
        <artifact> 
         <file>${project.build.directory}/bar.wsdl</file> 
         <classifier>bar</classifier> 
         <type>wsdl</type> 
        </artifact> 
       </artifacts> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

Nếu của phối hợp là myGroupId pom của bạn: myArtifactId: 1.1.1, sau đó các đồ tạo tác cài đặt và triển khai sử dụng cấu hình này sẽ được đặt tên myArtifactId-1.1.1-foo.wsdl và myArtifactId-1.1.1 -bar.wsdl. Đó là điều tốt nhất tôi biết.

+1

Tôi có thể làm điều đó ... nhưng tôi đang xử lý số lượng tệp .wsdl có khả năng biến có tên tôi có thể không biết trước. – whaley

Các vấn đề liên quan