1

I've imported Lucene sources and built successfully. But when I'm trying to use any of Lucene classes, I get

A SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene410' does not exist
The current classpath supports the following names: []

I tried to get path to classes by

String path = Lucene410Codec.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();

And got right path, so there is no problem with wrong jar-file.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Nick
  • 138
  • 11

2 Answers2

1

The problem was that I've missed META-INF folder while imported project. I've manually added META-INF/services folder and it's contents - codecs files (which I took from lucene.core.jar) to sources and configured right build path.

add something to resources in eclipse

Now I can work with Lucene.

Community
  • 1
  • 1
Nick
  • 138
  • 11
1

For the ones who is facing such issue I have another solution which seems decent. Main reason for such issue to occur is that some JAR files (Lucene in this case) providing implementations of some interfaces ship with 'META-DATA/service' directory. This directory then maps interfaces to their implementation classes for lookup by the service locator. So the solution will be to relocate the class names of these implementation classes and merge multiple implementations of the same interface into one service entry.

Maven's shade plugin provides a resource transformer called ServiceResourceTransformer which does such relocation. So in practice I would define the plugin as follows:

<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>
        <filters>
          <filter>
            <artifact>*:*</artifact>
            <excludes>
              <exclude>META-INF/*.SF</exclude>
              <exclude>META-INF/*.DSA</exclude>
              <exclude>META-INF/*.RSA</exclude>
            </excludes>
          </filter>
        </filters>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <mainClass>main.class.of.your.app.MainClass</mainClass>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
        </transformers>
      </configuration>
    </execution>
  </executions>
</plugin>
eruslmu
  • 179
  • 1
  • 6
  • Yes, It's also a solution. The difference is, that I've tried to build Lucene from sources (github) in Eclipse (though no maven was needed). – Nick Apr 20 '16 at 12:02
  • I agree with you, but not everybody wants to build Lucene from the sources :) – eruslmu Apr 20 '16 at 19:31