gpt4 book ai didi

java - spring boot proguard 警告 : there were 184 classes in incorrectly named files

转载 作者:搜寻专家 更新时间:2023-11-01 03:46:47 24 4
gpt4 key购买 nike

[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 似乎将我的类文件编译到一个名为BOOT-INF/类这与原始目录结构不同。纠正此问题的最佳方法是什么?

最佳答案

我有同样的问题,这个SO问题是第一个出现的结果。因此可能值得链接到原始解决方案。 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 boot proguard 警告 : there were 184 classes in incorrectly named files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48256186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com