36

Unable to locate NamespaceHandler when using context:annotation-configmaven-assembly-plugin によってアセンブルされ、プロジェクトとそのすべての依存関係を含む jar を実行中 (java -jar)にエラーが発生しました。

他の人が forum.springsource.orgスレッド (メッセージ #7/8)META-INF/spring.handlersで正しく発見したように、ファイルが異なる jar に存在するために問題が発生META-INF/spring.schemasし、maven-assembly-plugin が jar を単一のファイルに再パッケージ化すると上書きされます。 .

2 つの spring-*.jar ファイルの内容を見ると、ファイルがクラスパスに対して相対的に同じ位置にあることがわかります。

$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/oxm/GenericMarshaller.class
...

$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/context/ApplicationContext.class

META-INF フォルダーを特定のパッケージに入れることはできませんか? もしそうなら、私が提案したいアイデアは(それが適用できることを願っています)、それらが参照するパッケージの下にMETA-INF/spring.shemasとファイルを置くことです。META-INF/spring.handlers

$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/oxm/META-INF/spring.schemas
org/springframework/oxm/META-INF/spring.handlers
org/springframework/oxm/GenericMarshaller.class
...

$ jar tf spring-context-3.0.3.RELEASE.jar
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class

この方法では、単一の jar にマージされたときに競合しません。あなたはそれについてどう思いますか?

4

2 に答える 2

87

(バグのある) アセンブラー プラグインの代わりにシェーダー プラグインを使用して、なんとかバグを取り除くことができました。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>at.seresunit.lecturemanager_connector.App</mainClass>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

springsourceフォーラムで解決策を見つけたと思います..調べてからかなり時間が経ちました..作者を本当に思い出せません。とにかく彼に称賛を :p

乾杯

于 2011-04-21T09:51:50.340 に答える