xmlbeans , 특히 inst2xsd . Maven을 통해 실행할 수 있도록 script를 패키징하고 싶습니다.Maven을 사용하여 xmlbeans를 설치할 때 inst2xsd를 실행하는 방법에 대한 문서를 찾을 수 없습니다.지금까지 내 pom.xml
입니다.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>de.wolkenarchitekt</groupId>
<artifactId>xml-to-xsd</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
mvn install
을 통해 설치하면 작동합니다. 참고 용으로-대답에는 중요하지 않습니다-Docker를 통해 구축 중이므로 OpenJDK14를 사용하고 있습니다.
FROM maven:3.6.3-openjdk-14-slim
RUN mkdir -p /opt/workspace
WORKDIR /opt/workspace
COPY pom.xml .
RUN mvn install
이제 Maven을 통해 xmlbeans를 설치 한 후 inst2xsd
에 대한 실행 파일을 어떻게 실행합니까?
Exec Maven 플러그인 을 사용하여 class를 호출 할 수 있습니다. Inst2Xsd
. 이 class는 inst2xsd
쉘 script에서 실제로 호출되는 class입니다.
프로젝트에 xmlbeans
가 필요하지 않은 경우 (XSD가 생성되면) 해당 작업에 대해서만이 종속성을 이벤트 정의 할 수 있습니다.
다음 XML 문서를 고려하십시오.
<?xml version="1.0" encoding="UTF-8" ?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
이 예에서는 이름을 food-menu.xml
로 지정하고 src / main / resources
에 저장합니다.
다음과 같이 XML 스키마를 생성 할 수 있습니다 (다음 예제는 플러그인 문서 ) :
<project>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.apache.xmlbeans.impl.inst2xsd.Inst2Xsd</mainClass>
<arguments>
<!-- Add as many arguments as you need -->
<argument>-outDir</argument>
<argument>${project.build.outputDirectory}</argument>
<argument>-validate</argument>
<argument>${project.basedir}/src/main/resources/food-menu.xml</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<!-- ... -->
</project>
터미널이나 명령 줄에서 mvn exec : java
를 실행하면 Inst2Xsd
에 전달 된 인수에 따라 스키마가 생성됩니다.
도커 사용은 문제가되지 않습니다.