2

我正在使用 shade 插件来创建一个包含所有依赖项的 jar。在我的 pom.xml 中应用此配置相对简单:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <relocations>
        <relocation>
            <shadedPattern>com.company.lib.</shadedPattern>
            <excludes>
                <exclude>java.**</exclude>
                <exclude>com.company.app.**</exclude>
                <exclude>META-INF/**</exclude>
            </excludes>
        </relocation>
    </relocations>
</configuration>

但是,反编译生成的代码后,我意识到我的 String 文字的内容已更改。例如,这样的字符串: String text = "this-is-a-demo";它已成为String text = "com.company.lib.this-is-a-demo". 此更改在我的应用程序中执行了运行时错误。

在这篇文章https://jira.codehaus.org/browse/MSHADE-104之后,我试图避免添加元素<rawString>true</rawString>。但是当我再次构建项目时,在 maven-shade-plugin 中发生了 NullPointerException。

Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: null
at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:567)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more

有谁知道如何避免更改字符串文字?

4

1 回答 1

0

<pattern>您的配置中缺少 a <relocation>

我不确定这是否是 NullPointerException 的原因,但无论如何你都应该把它放进去,这样执行的重定位就不会那么令人惊讶了。

于 2014-01-24T19:14:00.140 回答