3

I am using shade plugin to create a jar with all its dependencies. Applying this configuration in my pom.xml it has been relatively straightforward:

<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>

However, decompiling the resultant code, I have realized that the content of my String literals have been changed. For example, an string like this: String text = "this-is-a-demo"; It has become String text = "com.company.lib.this-is-a-demo". This change has carried out runtime errors in my application.

Following this article https://jira.codehaus.org/browse/MSHADE-104, I have tried to avoid this adding the element <rawString>true</rawString>. But when I have built the project again, a NullPointerException has happened in maven-shade-plugin.

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

Does anyone know how can I avoid the String literals being changed?

beresfordt
  • 5,088
  • 10
  • 35
  • 43
telle
  • 609
  • 2
  • 6
  • 18

1 Answers1

0

You are missing a <pattern> in your <relocation> configuration.

I'm not sure if that's the cause of the NullPointerException, but you ought to put it in anyway, so the relocation performed will be less surprising.

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
  • I want to get a library with my code and all its dependencies with a prefix. For example, my code: com.company.app and dependencies inside com.company.lib. The only way I have seen to get this is to avoid the element as I have posted in my question. This solution had worked until I added . Do you know another way to solve this? – telle Jan 26 '14 at 19:55