2015-12-22 32 views
0

我試圖讀取應用程序的Solr的版本4個指標,我用Java寫的,我說這個依賴關係到我的ivy.xml文件:無法加載編解碼器「Lucene410」

<dependency org="org.apache.lucene" name="lucene-core" rev="5.2.1"> 

</dependency> 
<dependency org="org.apache.hadoop" name="hadoop-hdfs" rev="2.7.1"/> 
<dependency org="org.slf4j" name="slf4j-jdk14" rev="1.7.7"/> 
<dependency org="log4j" name="log4j" rev="1.2.17"/> 
<dependency org="org.apache.lucene" name="lucene-backward-codecs" rev="5.2.1"/> 

我創建的我的應用程序的jar文件,當我想要運行的應用程序,它給我這個錯誤:

java.lang.IllegalArgumentException: Could not load codec 'Lucene410'. Did you forget to add lucene-backward-codecs.jar? 

Caused by: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene410' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names: [Lucene50] 

我使用這行代碼:

System.out.println("codec path:" + Lucene410Codec.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); 

它給我的jar文件的解碼器jar的路徑,所以它存在。

更新: 也,在Eclipse中,我可以用這行代碼:

Codec.availableCodecs() 

,這讓我的編解碼器的列表,並lucene410編解碼器在列表中顯示出來,而不是當我嘗試運行jar文件。

我讀的地方,我應該爲此編解碼器jar文件到我的build.xml添加服務,但它不工作,這是螞蟻(build.xml文件)我的罐子部分:

<target name="jar" depends="compile" description="Creates the JAR file with a Main-Class."> 
    <mkdir dir="${jar.dir}" /> 
    <copy file="conf/log4j.properties" todir="${classes.dir}" /> 

    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"> 
     <exclude name="**/org.apache.lucene.codecs.Codec"/> 
     <zipgroupfileset dir="lib" includes="*.jar" /> 
     <manifest> 
      <attribute name="Main-Class" value="${Main-Class}" /> 
      <attribute name="Class-Path" value=". ${jar.classpath}" /> 
     </manifest> 
     <service type="org.apache.lucene.codecs.Codec"> 
      <provider classname="org.apache.lucene.codecs.lucene40.Lucene40Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene41.Lucene41Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene42.Lucene42Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene45.Lucene45Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene46.Lucene46Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene49.Lucene49Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene410.Lucene410Codec" /> 
      <provider classname="org.apache.lucene.codecs.lucene50.Lucene50Codec" /> 
     </service> 
    </jar> 
</target> 

這是我曾經在我的lib文件夾中添加jar文件到類路徑中class.path:

<path id="class.path"> 
    <fileset dir="lib"> 
     <include name="**/*.jar" /> 
    </fileset> 

的問題是,Lucene的核心包有它自己的「org.apache.lucene.codecs.Codec 「META-INF/services中的文件,並且覆蓋了我嘗試在bu目標中的jar目標的'service'部分中創建的文件ild文件。排除可在build.xml中看到的標記不起作用,zipgroupfileset上的exclude屬性也不起作用。任何幫助將非常感激。

+0

您是否正在從ANT推出java程序?如果是這樣,Java任務如何設置類路徑? –

+0

@ MarkO'Connor是的,我使用ant,並將Java任務部分添加到我的問題中。 –

+0

我認爲你應該停止嘗試重新包裝第三方罐子。嘗試使用嵌入式類路徑創建可執行jar,如下所示。 –

回答

0

不知道是什麼問題。您可以嘗試以下操作,創建一個具有對類路徑的依賴關係的jar。

<target name="jar" depends="compile" description="Creates the JAR file with a Main-Class."> 
    <mkdir dir="${jar.dir}" /> 
    <copy file="conf/log4j.properties" todir="${classes.dir}" /> 

    <!-- Copy dependencies into the distribution directory --> 
    <ivy:retrieve pattern="${jar.dir}/[artifact]-[revision](-[classifier]).[ext]"/> 

    <!-- Create a manifest classpath property --> 
    <manifestclasspath property="jar.classpath" jarfile="${jar.dir}/${ant.project.name}.jar"> 
     <classpath> 
      <fileset dir="${jar.dir}" includes="*.jar"/> 
     </classpath> 
    </manifestclasspath> 

    <!-- Create an executable jar --> 
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"> 
     <manifest> 
      <attribute name="Main-Class" value="${Main-Class}" /> 
      <attribute name="Class-Path" value="${jar.classpath}" /> 
     </manifest> 
    </jar> 
</target> 
+0

我更新了這個問題,以更好地解釋究竟是什麼問題。 –

相關問題