2014-01-24 58 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