Java Android错误上的Lucene 4
在将Lucene 4与Android API 19(4.4.2)一起使用时,我遇到了这个错误Java Android错误上的Lucene 4,java,android,maven,intellij-idea,lucene,Java,Android,Maven,Intellij Idea,Lucene,在将Lucene 4与Android API 19(4.4.2)一起使用时,我遇到了这个错误 原因:java.lang.IllegalArgumentException:不存在名为“Lucene46”的类型为org.apache.lucene.codecs.Codec的SPI类。您需要将支持此SPI的相应JAR文件添加到类路径中。当前类路径支持以下名称:[] 位于org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:10
原因:java.lang.IllegalArgumentException:不存在名为“Lucene46”的类型为org.apache.lucene.codecs.Codec的SPI类。您需要将支持此SPI的相应JAR文件添加到类路径中。当前类路径支持以下名称:[]
位于org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:109)
位于org.apache.lucene.codecs.Codec.forName(Codec.java:95)
在org.apache.lucene.codecs.Codec.(Codec.java:122)在org.apache.lucene.index.LiveIndexWriterConfig.(LiveIndexWriterConfig.java:122)在org.apache.lucene.index.IndexWriterConfig.(IndexWriterConfig.java:165)
这与报告的错误类似
我迁移到IntelliJ上的android maven插件,因为它是我问题的建议解决方案,但我仍然了解这个问题。这是我的Maven pom.xml
<?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>
<groupId>com.johnbohne.chishiki</groupId>
<artifactId>Chishiki</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Chishiki</name>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version>
<configuration>
<source>1.5</source><target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
4.0.0
com.johnbohne.chishiki
知职
1.0-快照
罐子
知职
src
${project.artifactId}
com.jayway.maven.plugins.android.generation2
安卓maven插件
3.8.2
真的
org.apache.maven.pluginsmaven-compiler-plugin2.3.2
1.51.5
我知道在Android上使用Lucene 3.0是可能的,但我不太确定Lucene 4.0。有人知道如何让Lucene 4.0在Android上运行吗?这里有一个运行它的方法(这肯定不是最好的解决方案,但它很有效):
package org.apache.lucene.util;
/*
*根据一个或多个许可证颁发给Apache软件基金会(ASF)
*贡献者许可协议。请参阅随附的通知文件
*本作品提供了有关版权所有权的更多信息。
*ASF根据Apache许可证2.0版将此文件许可给您
*(以下简称“许可证”);除非符合以下要求,否则不得使用此文件
*执照。您可以通过以下方式获得许可证副本:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*除非适用法律要求或书面同意,软件
*根据许可证进行的分发是按“原样”进行分发的,
*无任何明示或暗示的保证或条件。
*请参阅许可证以了解管理权限和权限的特定语言
*许可证下的限制。
*/
导入java.io.BufferedReader;
导入java.io.IOException;
导入java.io.InputStream;
导入java.io.InputStreamReader;
导入java.net.URL;
导入java.util.ArrayList;
导入java.util.array;
导入java.util.Collections;
导入java.util.Enumeration;
导入java.util.Iterator;
导入java.util.Locale;
导入java.util.NoSuchElementException;
导入java.util.ServiceConfigurationError;
/**
*用于从类路径(META-INF文件)加载SPI类的帮助器类。
*这是一个{@link java.util.ServiceLoader}的轻量级impl,但保证
*在类路径顺序方面没有bug,并且不实例化或初始化
*找到的类。
*
*@lucene.internal
*/
公共最终类SPIClassificator实现迭代器直到没有发现错误,但最终使用了Lucene 3.6,它似乎是编译器。我试图使用您正在做的事情,但gradle上显示“已添加:Lorg/apache/Lucene/util/SPIClassificator”build@John61590参见gradle文件,我正在使用pickFirst'org/apache/lucene/util/spiclassisterator.class'@traffer是的,我知道,但它仍然说同样的话。我复制了应用程序中的架构,但它不适用于更高级别的构建。我用的是Lucene 4.7.1
<?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>
<groupId>com.johnbohne.chishiki</groupId>
<artifactId>Chishiki</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Chishiki</name>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version>
<configuration>
<source>1.5</source><target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
package org.apache.lucene.util;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.ServiceConfigurationError;
/**
* Helper class for loading SPI classes from classpath (META-INF files).
* This is a light impl of {@link java.util.ServiceLoader} but is guaranteed to
* be bug-free regarding classpath order and does not instantiate or initialize
* the classes found.
*
* @lucene.internal
*/
public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {
private static final String META_INF_SERVICES = "/assets/META-INF/services/";
private final Class<S> clazz;
private final ClassLoader loader;
private final Enumeration<URL> profilesEnum;
private Iterator<String> linesIterator;
public static <S> SPIClassIterator<S> get(Class<S> clazz) {
return new SPIClassIterator<S>(clazz, Thread.currentThread().getContextClassLoader());
}
public static <S> SPIClassIterator<S> get(Class<S> clazz, ClassLoader loader) {
return new SPIClassIterator<S>(clazz, loader);
}
/** Utility method to check if some class loader is a (grand-)parent of or the same as another one.
* This means the child will be able to load all classes from the parent, too. */
public static boolean isParentClassLoader(final ClassLoader parent, ClassLoader child) {
while (child != null) {
if (child == parent) {
return true;
}
child = child.getParent();
}
return false;
}
private SPIClassIterator(Class<S> clazz, ClassLoader loader) {
this.clazz = clazz;
final String fullName = META_INF_SERVICES + clazz.getName();
this.profilesEnum =
Collections.enumeration(
Arrays.asList(new URL[]{getClass().getResource(fullName)}));
this.loader = (loader == null) ? ClassLoader.getSystemClassLoader() : loader;
this.linesIterator = Collections.<String>emptySet().iterator();
}
private boolean loadNextProfile() {
ArrayList<String> lines = null;
while (profilesEnum.hasMoreElements()) {
if (lines != null) {
lines.clear();
} else {
lines = new ArrayList<String>();
}
final URL url = profilesEnum.nextElement();
try {
final InputStream in = url.openStream();
IOException priorE = null;
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
final int pos = line.indexOf('#');
if (pos >= 0) {
line = line.substring(0, pos);
}
line = line.trim();
if (line.length() > 0) {
lines.add(line);
}
}
} catch (IOException ioe) {
priorE = ioe;
} finally {
IOUtils.closeWhileHandlingException(priorE, in);
}
} catch (IOException ioe) {
throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
}
if (!lines.isEmpty()) {
this.linesIterator = lines.iterator();
return true;
}
}
return false;
}
@Override
public boolean hasNext() {
return linesIterator.hasNext() || loadNextProfile();
}
@Override
public Class<? extends S> next() {
// hasNext() implicitely loads the next profile, so it is essential to call this here!
if (!hasNext()) {
throw new NoSuchElementException();
}
assert linesIterator.hasNext();
final String c = linesIterator.next();
try {
// don't initialize the class (pass false as 2nd parameter):
return Class.forName(c, false, loader).asSubclass(clazz);
} catch (ClassNotFoundException cnfe) {
throw new ServiceConfigurationError(String.format(Locale.ROOT, "A SPI class of type %s with classname %s does not exist, "+
"please fix the file '%s%1$s' in your classpath.", clazz.getName(), c, META_INF_SERVICES));
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}