2011-10-29 18 views
2

gmavenプラグインを使用しましょう -org.codehaus.groovy.control.MultipleCompilationErrorsExceptionが、それは私にコンパイルエラーがスローされますMVNを使用してコンパイルしながら、私はExpandoMetaClassを使用して静的メソッドを追加しようとしている、これは私のサンプルプログラムです

@Singleton 
     class ThrowError { 
      def parse() 
      { 
       println "Anish" 
      } 

     } 
     ThrowError.metaClass.static.getMap = {m_var -> ThrowError.instance.parse(m_var) } 
発行MVNは ..........

[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.2:generateStubs (default) on project TestExpandoMetaClass: startup failed: 
[ERROR] /C:/groovy/ThrowError.groovy: 4 
: Invalid duplicate class definition of class ThrowError : The source /C:/groovy/ThrowError.groovy contains at least two definitions of the class ThrowError. 
**[ERROR] One of the classes is a explicit generated class using the class statement, the other is a class generated from the s 
cript body based on the file name. Solutions are to change the file name or to change the class name.** 
[ERROR] @ line 4, column 1. 
[ERROR] @Singleton 
[ERROR]^
[ERROR] 
[ERROR] 1 error 
[ERROR] -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.2:generate 
Stubs (default) on project TestExpandoMetaClass: startup failed: 
/C:/groovyThrowError.groovy: 4: Invali 
d duplicate class definition of class ThrowError : The source /groovy/ThrowError.groovy contains at least two definitions of the class ThrowError 

をコンパイルしながら、

私は、プロジェクトをコンパイルするgmavenプラグインを、これは私のpom.xmlエントリープラグインgmavenビルドエントリー

される使用しています
<project> 
............ 
............ 
    <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <configuration> 
         <source>1.6</source> 
         <target>1.6</target> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>exec-maven-plugin</artifactId> 
        <version>1.1</version> 
        <executions> 
         <execution> 
          <goals> 
           <goal>java</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
       <plugin> 
        <groupId>org.codehaus.gmaven</groupId> 
        <artifactId>gmaven-plugin</artifactId> 
        <version>1.2</version> 
        <configuration> 
         <providerSelection>1.7</providerSelection> 
        </configuration> 
        <dependencies> 
         <dependency> 
          <groupId>org.codehaus.gmaven.runtime</groupId> 
          <artifactId>gmaven-runtime-1.7</artifactId> 
          <version>1.2</version> 
         </dependency> 
         <dependency> 
          <groupId>org.codehaus.groovy</groupId> 
          <artifactId>groovy-all</artifactId> 
          <version>1.7.2</version> 
         </dependency> 
        </dependencies> 
        <executions> 
         <execution> 
          <goals> 
           <goal>generateStubs</goal> 
           <goal>compile</goal> 
           <goal>generateTestStubs</goal> 
           <goal>testCompile</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
.......... 
.......... 
    </project> 

答えて

7

Groovyのメーリングリストと同じ回答ですが、もう少し詳しく説明します... Groovyにはスクリプトとクラスがあります。クラスは、Javaのようなクラス構造を持つすべてです。たとえば、クラスB {}はクラス構造であり、クラスBを定義します。スクリプトもクラスですが、そのような構造にはありません。あなたが "class B {}; def b = new B()"を持っていれば、Bのクラス構造だけでなく "def b = new B()"という内容のスクリプトもあります。私はこれもクラスだと言ったように、そのクラスの名前は何ですか?名前は、スクリプトが定義されているファイルの名前で定義されます(ファイルがない場合は、script1456のような名前が選択されます)。今度は、コンテンツ "class B {}; def b = new B()"を持つB.groovyを作成することができます。 Bという名前のクラスと、まったく同じ名前のスクリプトがあります。これは紛争です。

ファイルに別の名前を付けても問題ありません。

+0

この種類のクラス、スクリプトクラスをインポートすると、そのコンテンツはどのように実行されますか? –

+0

スクリプトはrunメソッドを持っています。もちろん、定義したものに依存します。 – blackdrag

+0

インポート時にエラーが発生した場合、誤って解釈してスクリプトクラス定義を生成してから定義クラスを生成します。 – user2782001

関連する問題