2014-01-24 76 views
1

我正在使用阴影插件创建一个具有所有依赖关系的jar。在我的pom.xml运用这一配置就已经相对比较简单:Maven Shade插件+原始字符串

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

有谁知道我该如何避免字符串文字被改变?

回答

0

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

我不确定这是否是NullPointerException的原因,但是您应该将其放入,因此执行的重定位并不会令人惊讶。

+0

我想用我的代码和它的所有依赖项都带有前缀的库。例如,我的代码:com.company.app和com.company.lib中的依赖关系。我见过得到这个的唯一方法是避免元素,因为我在我的问题中发布了。此解决方案一直工作,直到我加入。你知道解决这个问题的另一种方法吗? – telle