2017-08-10 73 views
0

我試圖在JAR文件中運行我的Java Maven項目。它在IntelliJ IDEA 2017上運行,但是,通過JAR文件運行時,它不會運行。顯示以下錯誤:JAR文件中的Lucene 6錯誤(無法實例化SPI類)

Exception in thread "main" java.util.ServiceConfigurationError: Cannot instantiate SPI class: org.apache.lucene.codecs.lucene62.Lucene62Codec 
    at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:82) 
    at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:51) 
    at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:38) 
    at org.apache.lucene.codecs.Codec$Holder.<clinit>(Codec.java:47) 
    at org.apache.lucene.codecs.Codec.getDefault(Codec.java:143) 
    at org.apache.lucene.index.LiveIndexWriterConfig.<init>(LiveIndexWriterConfig.java:121) 
    at org.apache.lucene.index.IndexWriterConfig.<init>(IndexWriterConfig.java:151) 
    at com.hrforecast.skillextraction.LuceneIndexManager.buildLuceneIndex(LuceneIndexManager.java:54) 
    at com.hrforecast.skillextraction.SkillExtractionModule.getJobsSearcher(SkillExtractionModule.java:129) 
    at com.hrforecast.skillextraction.SkillExtractionModule.run(SkillExtractionModule.java:60) 
    at com.hrforecast.skillextraction.Main.main(Main.java:28) 
Caused by: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'Lucene50' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. 
    The current classpath supports the following names: [IDVersion] 
    at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:116) 
    at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112) 
    at org.apache.lucene.codecs.lucene62.Lucene62Codec.<init>(Lucene62Codec.java:167) 
    at org.apache.lucene.codecs.lucene62.Lucene62Codec.<init>(Lucene62Codec.java:82) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at java.lang.Class.newInstance(Unknown Source) 
    at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:72) 
    ... 10 more 

我也有類似的問題,例如What causes err ' A SPI class of type lucene.codecs.Codec name 'Lucene42'其他計算器問題,但這也並沒有解決我的問題。

我的pom.xml如下。正如你所看到的,我也嘗試使用Resource Transformers,但它沒有改變。

<?xml version="1.0" encoding="UTF-8"?> 
<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> 

... 
<dependencies> 

    <!-- Spring framework --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>3.2.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>3.2.2.RELEASE</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver --> 
    <dependency> 
     <groupId>org.mongodb</groupId> 
     <artifactId>mongo-java-driver</artifactId> 
     <version>3.5.0</version> 
    </dependency> 


    <!-- Spring data mongodb --> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-mongodb</artifactId> 
     <version>1.2.0.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2.2</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core --> 
    <dependency> 
     <groupId>org.apache.lucene</groupId> 
     <artifactId>lucene-core</artifactId> 
     <version>6.6.0</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-analyzers-common --> 
    <dependency> 
     <groupId>org.apache.lucene</groupId> 
     <artifactId>lucene-analyzers-common</artifactId> 
     <version>6.6.0</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/junit/junit --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-queryparser --> 
    <dependency> 
     <groupId>org.apache.lucene</groupId> 
     <artifactId>lucene-queryparser</artifactId> 
     <version>6.6.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.7.5</version> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.7.5</version> 
    </dependency> 

    <dependency> 
     <groupId>de.flapdoodle.embed</groupId> 
     <artifactId>de.flapdoodle.embed.mongo</artifactId> 
     <version>1.26</version> 
     <scope>test</scope> 
    </dependency> 

</dependencies> 

<build> 
    <plugins> 
     <!--<plugin>--> 
      <!--<artifactId>maven-compiler-plugin</artifactId>--> 
      <!--<version>3.0</version>--> 
      <!--<configuration>--> 
       <!--<source>1.6</source>--> 
       <!--<target>1.6</target>--> 
      <!--</configuration>--> 
     <!--</plugin>--> 
     <!--<plugin>--> 
      <!--<groupId>org.apache.maven.plugins</groupId>--> 
      <!--<artifactId>maven-eclipse-plugin</artifactId>--> 
      <!--<version>2.9</version>--> 
      <!--<configuration>--> 
       <!--<downloadSources>true</downloadSources>--> 
       <!--<downloadJavadocs>true</downloadJavadocs>--> 
      <!--</configuration>--> 
     <!--</plugin>--> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>2.4.3</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <mainClass>com..Main</mainClass> 
          </transformer> 
          <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> 
         </transformers> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

任何幫助或指導將不勝感激。

回答

0

我的解決方案是使用Maven Shade plugin,因爲我使用IntelliJ,問題在於我如何創建JAR文件。

而不是使用'artifacts'創建它在IntelliJ中構建,我使用終端中的'mvn'工具創建了JAR文件。確保你的JAVA_HOME設置正確。我必須再次使用apt-get來安裝openjdk8。最終,在目標目錄中創建了正確的JAR文件。

有關如何使用Maven Shade創建JAR文件的更多詳細信息,請參閱here

(此解決方案適用於Lucene 6.6.0,Windows 10 bash)。

相關問題