ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java – spring boot proguard警告:错误命名的文件中有184个类

2019-07-10 17:11:34  阅读:1495  来源: 互联网

标签:java spring obfuscation proguard spring-boot-2


[proguard] Warning: there were 184 classes in incorrectly named files.
 [proguard]          You should make sure all file names correspond to their class names.
 [proguard]          The directory hierarchies must correspond to the package hierarchies.
 [proguard]          (http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass)
 [proguard]          If you don't mind the mentioned classes not being written out,
 [proguard]          you could try your luck using the '-ignorewarnings' option.
 [proguard] Error: Please correct the above warnings first.

Spring启动似乎将我的类文件编译到一个名为的文件夹中
BOOT-INF / classes目录
这与原始目录结构有关.纠正这个问题的最佳方法是什么?

解决方法:

我有同样的问题,这个问题是第一个结果.所以可能值得链接到原始解决方案. here解释了这种行为的原因:

ProGuard requires that the names of the class files in a jar file correspond directly to the names of the classes, without a prefix like “BOOT-INF/classes”.

解决这个问题的方法是提取jar,在其上应用Proguard,然后将混淆的类打包到一个新的jar中.

同一篇文章继续:

Spring Boot basically requires three directories, BOOT-INF, META-INF and org. Obfuscation of your own classes and repacking to a fat jar can be roughly done the following way:

# Extract the unobfuscated fat jar from Spring Boot
jar xvf input.jar

# Execute ProGuard, as input for ProGuard use
# -injars BOOT-INF/classes/
java -jar proguard.jar @ proguard.conf

# If you also want to obfuscate the libs, add
# -injars BOOT-INF/lib
# Be aware, probably needs filtering, if some but not all libs should be obfuscated. I have not tested, but I believe the Spring Framwork libraries should not be obfuscated because they would require a lot of keep exceptions in the ProGuard configuration.
# If some of the libs should be used for obfuscation in the copy step below **remove** the libs before copying, otherwise the old files remain in the fat jar.

# Copy the old files excluding the classes to a new directory.
# First, the classes are stored here:
mkdir obfuscated/BOOT-INF
mkdir obfuscated/BOOT-INF/classes

# I assume the output is obfuscated-classes.jar
# It has to be extracted in the new output
cp obfuscated-classes.jar obfuscated/BOOT-INF/classes
pushd obfuscated/BOOT-INF/classes
jar xvf obfuscated-classes.jar
rm obfuscated-classes.jar
popd

# Copy the remaining files
boot_directories=(BOOT-INF/lib META-INF org)
for boot_directory in ${boot_directories[@]}; do
    mkdir -p "./obfuscated/$boot_directory"

    copy_command="cp -R ./$boot_directory/* ./obfuscated/$boot_directory/"
    eval $copy_command
done

# Finally, create a new jar
pushd obfuscated
# Be aware: do not use * as selector, the order of the entries in the resulting jar is important!
jar c0mf ./META-INF/MANIFEST.MF input-obfuscated.jar BOOT-INF/classes/ BOOT-INF/lib/ META-INF/ org/
popd

# Now, there is a jar obfuscated/input-obfuscated.jar that is a Spring Boot fat jar whose BOOT-INF/classes directory is obfuscated.

标签:java,spring,obfuscation,proguard,spring-boot-2
来源: https://codeday.me/bug/20190710/1426245.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有