2011-08-31 15 views
14

私は基本的にMavenプラグインを使ってJAXBで注釈を付けたモデルクラスからXSDスキーマを生成しようとしています。私は次のエラーを取得MavenのJAXBタイプからXSDスキーマを生成するには?

<plugin> 
    <groupId>com.sun.tools.jxc.maven2</groupId> 
    <artifactId>maven-jaxb-schemagen-plugin</artifactId> 
    <version>1.2</version> 
    <executions> 
     <execution> 
      <phase>generate-resources</phase> 
      <goals> 
       <goal>generate</goal> 
      </goals> 
     </execution> 
    </executions> 

    <configuration> 
     <project>${project}</project> 
     <destdir>${project.build.directory}/schemas</destdir> 
     <srcdir>${project.build.sourceDirectory}/com/floodstream/wowza/mastercontrol/model</srcdir> 
     <verbose>true</verbose> 
    </configuration> 

    <dependencies> 
     <dependency> 
      <groupId>javax.xml.bind</groupId> 
      <artifactId>jaxb-api</artifactId> 
      <version>2.2</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-xjc</artifactId> 
      <version>2.2</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-impl</artifactId> 
      <version>2.2</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-xjc</artifactId> 
      <version>2.2</version> 
     </dependency> 
    </dependencies> 
</plugin> 

<!-- other stuff omitted for brevity --> 

<pluginRepository> 
    <id>maven-repository.dev.java.net</id> 
    <name>Java.net Maven 2 Repository</name> 
    <url>http://download.java.net/maven/2</url> 
</pluginRepository> 

:ここ

[ERROR] FATAL ERROR 
[INFO] ------------------------------------------------------------------------ 
[INFO] org/apache/tools/ant/taskdefs/Javac 
org.apache.tools.ant.taskdefs.Javac 
[INFO] ------------------------------------------------------------------------ 
[INFO] Trace 
java.lang.NoClassDefFoundError: org/apache/tools/ant/taskdefs/Javac 
     at java.lang.ClassLoader.defineClass1(Native Method) 
     at java.lang.ClassLoader.defineClass(ClassLoader.java:634) 
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) 
     at java.net.URLClassLoader.access$000(URLClassLoader.java:73) 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:212) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:205) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:321) 
     at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195) 
     at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255) 
     at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:266) 
     at java.lang.ClassLoader.defineClass1(Native Method) 
     at java.lang.ClassLoader.defineClass(ClassLoader.java:634) 
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) 
     at java.net.URLClassLoader.access$000(URLClassLoader.java:73) 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:212) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:205) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:321) 
     at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195) 
     at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255) 
     at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:266) 
     at java.lang.ClassLoader.defineClass1(Native Method) 
     at java.lang.ClassLoader.defineClass(ClassLoader.java:634) 
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) 
     at java.net.URLClassLoader.access$000(URLClassLoader.java:73) 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:212) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:205) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:321) 
     at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195) 
     at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255) 
     at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:266) 
     at com.sun.tools.jxc.maven2.SchemaGenMojo.execute(SchemaGenMojo.java:143) 
     at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) 
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) 
     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) 
     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) 
     at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) 
     at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:616) 
     at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) 
     at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) 
     at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) 
     at org.codehaus.classworlds.Launcher.main(Launcher.java:375) 
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.taskdefs.Javac 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:217) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:205) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:321) 
     at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195) 
     at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255) 
     at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274) 
     at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:266) 
     ... 59 more 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 4 seconds 
[INFO] Finished at: Tue Aug 30 17:40:29 PDT 2011 
[INFO] Final Memory: 16M/170M 
[INFO] ------------------------------------------------------------------------ 
+1

関連する投稿を確認してください。 Jaxbには2つのプラグインがあると思います。そのうちの1つは他のプラグインよりはるかに優れています(控えめな記述)。私は右のものがアーティファクトIDに "jaxb2"を持っていると思う。 –

答えて

25

を勝利だ:ここに私のPOMの関連するコードだ

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxb2-maven-plugin</artifactId> 
    <version>1.3.1</version> 
    <executions> 
     <execution> 
      <goals> 
       <goal>schemagen</goal> 
      </goals> 
      <phase>generate-resources</phase> 
      <configuration> 
       <includes> 
        <include>com/myproject/model/*.java</include> 
       </includes> 
       <outputDirectory>${project.build.directory}/schemas</outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
+1

'schemagen'の機能が' javac'に置き換えられているので、そこには何がありますか?目標に対応するフラグを付けたjavacを追加するだけですか? – mike

0

Naftuli Tzvi Kay's answerに改善、私はそれがより便利に使用することが判明しましたこのサンプルのような現在のバージョン2.2のjaxb2-maven-pluginは、(わずかに異なる構成を必要とするため、2.xのように)

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxb2-maven-plugin</artifactId> 
    <version>2.2</version> 
    <executions> 
     <execution> 
      <goals> 
       <goal>schemagen</goal> 
      </goals> 
      <phase>generate-resources</phase> 
      <configuration> 
       <sources> 
        <source>src/main/java/com/foo/model/xml</source> 
       </sources> 
       <outputDirectory>${project.build.directory}/schemas</outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

詳細はplugin documentationを参照してください。

関連する問題