SORU
18 Mayıs 2010, Salı


Nasıl jaxb söyle / birden çok şema paketleri oluşturmak için Maven miyim?

Örnek:

</plugin>       
       <plugin>
           <groupId>org.jvnet.jaxb2.maven2</groupId>
           <artifactId>maven-jaxb2-plugin</artifactId>
           <version>0.7.1</version>
           <executions>
             <execution>
               <goals>
                 <goal>generate</goal>
               </goals>
             </execution>
           </executions>
            <configuration>
             <schemaDirectory>src/main/resources/dir1</schemaDirectory>
              <schemaIncludes>
                  <include>schema1.xsd</include>
              </schemaIncludes>
              <generatePackage>schema1.package</generatePackage>
           </configuration>
         </plugin>
          <plugin>
           <groupId>org.jvnet.jaxb2.maven2</groupId>
           <artifactId>maven-jaxb2-plugin</artifactId>
           <version>0.7.1</version>
           <executions>
             <execution>
               <goals>
                 <goal>generate</goal>
               </goals>
             </execution>
           </executions>
            <configuration>
             <schemaDirectory>src/main/resources/dir2</schemaDirectory>
              <schemaIncludes>
                  <include>schema2.xsd</include>
              </schemaIncludes>
              <generatePackage>schema2.package</generatePackage>
           </configuration>
         </plugin>
       </plugins>

Ne oldu: Maven ilk eklenti yürütür. Sonra hedef klasörü siler ve sonra görünen ikinci paketi oluşturur.

İlk yapılandırma için hedef/somedir1 set ve ikinci yapılandırma için/somedir2 hedef için çalıştım. Ama bu davranışı değiştirmez değil mi? Herhangi bir fikir? Bu paketler genereated ve el ile oluşturulan sınıflar ile karıştırılmamalıdır, çünkü doğrudan src/main/java klasörünün paketleri oluşturmak istiyorum.

CEVAP
18 Mayıs 2010, Salı


generateDirectory farklı (bu olmadan, eklenti dosyaları güncel olduğunu düşünüyordu ve ikinci yürütme sırasında bir şey üretemiyor) belirtmek zorunda kaldım. Ve en sevdiğiniz IDE otomatik olarak alınır, böylece üretilen kaynaklar için target/generated-sources/<tool> sözleşme takip etmenizi öneririm. Ben de execution birkaç kez eklentisi (configuration execution her öğe içinde taşımak için) ilan yerine ilan etmektedir

<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.7.1</version>
  <executions>
    <execution>
      <id>schema1-generate</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <schemaDirectory>src/main/resources/dir1</schemaDirectory>
        <schemaIncludes>
          <include>shiporder.xsd</include>
        </schemaIncludes>
        <generatePackage>com.stackoverflow.package1</generatePackage>
        <generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
      </configuration>
    </execution>
    <execution>
      <id>schema2-generate</id>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <schemaDirectory>src/main/resources/dir2</schemaDirectory>
        <schemaIncludes>
          <include>books.xsd</include>
        </schemaIncludes>
        <generatePackage>com.stackoverflow.package2</generatePackage>
        <generateDirectory>${project.build.directory}/generated-sources/xjc2</generateDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

Bu kurulum ile, mvn clean compile sonra aşağıdaki sonucu alıyorum

$ tree target/
target/
├── classes
   ├── com
      └── stackoverflow
          ├── App.class
          ├── package1
             ├── ObjectFactory.class
             ├── Shiporder.class
             ├── Shiporder$Item.class
             └── Shiporder$Shipto.class
          └── package2
              ├── BookForm.class
              ├── BooksForm.class
              ├── ObjectFactory.class
              └── package-info.class
   ├── dir1
      └── shiporder.xsd
   └── dir2
       └── books.xsd
└── generated-sources
    ├── xjc
       └── META-INF
           └── sun-jaxb.episode
    ├── xjc1
       └── com
           └── stackoverflow
               └── package1
                   ├── ObjectFactory.java
                   └── Shiporder.java
    └── xjc2
        └── com
            └── stackoverflow
                └── package2
                    ├── BookForm.java
                    ├── BooksForm.java
                    ├── ObjectFactory.java
                    └── package-info.java

Beklenen sonuç gibi görünüyor.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ChasesAndCrashes

    ChasesAndCra

    31 Temmuz 2009
  • Neil Cicierega

    Neil Ciciere

    22 Mart 2006
  • RobertDuskin

    RobertDuskin

    12 HAZİRAN 2008