简体   繁体   English

如何使用Maven Shade插件?

[英]How to use Maven Shade plugin?

In my project I want to avoid version conflict of neo4j lucene indexer (which uses lucene version - 3.6.2) and apache lucene (lucene version - 5.3.0). 在我的项目中,我想避免neo4j lucene indexer (使用lucene版本neo4j lucene indexer )和apache lucene (lucene版本neo4j lucene indexer版本冲突。 For this I want to use Maven shade plugin. 为此,我想使用Maven阴影插件。 Actually, I added plugin to my projects 'pom.xml' file but problem wasn't solved. 实际上,我在项目的“ pom.xml”文件中添加了插件,但问题仍未解决。 I get exception - 我例外-

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.lucene.analysis.standard.StandardAnalyzer: method <init>()V not found
    at com.sessa.col.spr.act.dictionary.DictionaryConfiguration.writerConfiguration(DictionaryConfiguration.java:124)
    at com.sessa.col.spr.act.process_flow.Flow.startProcess(Flow.java:59)
    at com.sessa.col.spr.act.process_flow.FlowHandler.main(FlowHandler.java:17)

It seems that it is caused by version conflict again. 似乎又是由版本冲突引起的。 I guess, I don't use Maven Shade plugin in a correct way. 我想,我没有以正确的方式使用Maven Shade插件。 How should it be used? 应该如何使用?

pom.xml pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.sessa.col.spr.act</groupId>
<artifactId>Color-Spreading-Activation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Color-Spreading-Activation</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <neo4j-version>2.2.5</neo4j-version>
</properties>



<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.4</version>
    </dependency>

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j</artifactId>
        <version>${neo4j-version}</version>
    </dependency>

    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-corenlp</artifactId>
        <version>3.5.2</version>
    </dependency>

    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-parser</artifactId>
        <version>3.5.2</version>
    </dependency>

    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-corenlp</artifactId>
        <version>3.5.2</version>
        <classifier>models</classifier>
    </dependency>

    <dependency>
        <groupId>com.sparsity</groupId>
        <artifactId>sparkseejava</artifactId>
        <version>5.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>jena-tdb</artifactId>
        <version>1.1.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.opennlp</groupId>
        <artifactId>opennlp-tools</artifactId>
        <version>1.5.3</version>
    </dependency>

    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>5.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-analyzers-common</artifactId>
        <version>5.3.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queryparser</artifactId>
        <version>5.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queries</artifactId>
        <version>5.3.0</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <relocations>
                            <relocation>
                                <pattern>org.apache.lucene</pattern>
                                <shadedPattern>shaded_lucene_3_6_2.org.apache.lucene</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>neo4j-repo</id>
        <name>Neo4j Repository</name>
        <url>http://m2.neo4j.org/content/repositories/releases</url>
    </repository>
</repositories> 

I doubt that maven-shade will help you here. 我怀疑行家阴影会在这里为您提供帮助。 You basically want to have multiple versions of the same jar - lucene 3.6.2 and 5.xy used at the same time. 基本上,您希望同时使用多个jar版本-lucene 3.6.2和5.xy。

The only solution I'm aware of here is using classloader separation. 我在这里知道的唯一解决方案是使用类加载器分隔。

However it might be worth refactoring the architecture to prevent that problem by separating Neo4j and your code into separate JVMs. 但是,通过将Neo4j和您的代码分离到单独的JVM中来重构体系结构以防止该问题可能是值得的。

  1. Add this project to eclipse -> https://github.com/lagodiuk/neo4j-uber-jar . 将此项目添加到eclipse-> https://github.com/lagodiuk/neo4j-uber-jar
  2. Use mvn-install and create ~SNAPSHOT.jar 使用mvn-install并创建〜SNAPSHOT.jar
  3. Add that .jar to your project (which has conflict) 将该.jar添加到您的项目中(有冲突)
  4. Remove neo4j maven dependency from that project. 从该项目中删除neo4j maven依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM