Tika API的Maven重定位

时间:2018-09-05 06:44:26

标签: java maven apache-tika maven-shade-plugin

我正尝试使用maven-shade-plugin将所有与Tika相关的类重新定位到一个新类中,如以下示例所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
               <goal>shade</goal>
            </goals>
            <configuration>
              <relocations>
                  <relocation>
                    <pattern>org.apache.tika</pattern>
                    <shadedPattern>shaded.org.apache.tika</shadedPattern>
                  </relocation> 
              </relocations>
            </configuration>
        </execution>
    </executions>
<plugin>

POM中的依赖性:

<dependency>
   <groupId>org.apache.tika</groupId>
   <artifactId>tika-core</artifactId>
   <version>1.18</version>
</dependency>
<dependency>
   <groupId>org.apache.tika</groupId>
   <artifactId>tika-parsers</artifactId>
   <version>1.18</version>
</dependency>

当我尝试在新项目中使用带阴影的jar读取文件时,没有例外,并且控制台上也找不到任何内容。我想念什么吗?请帮助!

示例代码:

import shaded.org.apache.tika.Tika;

Tika tika = new Tika();
tika.setMaxStringLength(1000);
System.out.println(tika.parseToString(file));

0 个答案:

没有答案