I have a gradle project where I'm using Tika's AutoDetectParser to extract content. When the project is built into a fat jar, AutoDetectParser returns empty string. I can see this is because Parser is not in the runtime classpath. How do I add Parser to the runtime classpath?
Gradle build file:
dependencies {
compile 'org.apache.tika:tika-parsers:1.20'
testImplementation 'junit:junit:4.12'
}
jar {
manifest {
attributes (
'Main-Class': 'com.superna.tikatest.TikaTestApp'
)
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}
}
Code snippet:
Metadata metadata = new Metadata();
AutoDetectParser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler();
try(FileInputStream fis = new FileInputStream(localPath.toString());
BufferedInputStream bis = new BufferedInputStream(fis);
TikaInputStream stream = TikaInputStream.get(bis)) {
parser.parse(stream, handler, metadata);
System.out.println(handler.toString());
}
使用阴影插件构建我的罐子解决了问题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.