更新时间:2022-03-03 06:47:14
Windows下来自Oracle JDK 11的jdeprscsan
的一些初步说明(我知道与CentOS上的JDK 9有关的问题,但以下内容同样适用. ..):
Some preliminary notes on jdeprscsan
from Oracle JDK 11 under Windows (I know the question related to JDK 9 on CentOS, but maybe the following applies as well...):
--class-path dir1/;dir2/*.jar
在通配符上引发解析异常)--class-path
指定的目录中的error : cannot find class X
消息,因为JAR a.jar
可能依赖于尚未加载的JAR b.jar
--class-path dir1/;dir2/*.jar
throws a parse exception on the wildcard)--class-path
are added to the classpath and analyzed in alphabetical order, which may cause some error : cannot find class X
messages because a JAR a.jar
may depend on a JAR b.jar
which is not yet loaded.基于上述发现,我找到了以下3个解决方案.请注意,我对Oracle JDK 12.0.2中的jdeprscan
做了相同的实验,没有任何改进.
Based on the above, I found the 3 solutions below. Note that I did the same experiment with jdeprscan
from the Oracle JDK 12.0.2 without any improvement.
mylib
(请注意,在此阶段,mylibs目录仅包含由目录包组织的类,而没有JAR).mylib
(note that at this stage, the mylibs directory contains only classes organized by directory packages, and no JARs). jdeprscan --for-removal --class-path /path/to/mylib /path/to/my-application.jar
优势:快速(非常手动操作)
Advantage: fast (very manual operations)
缺点:仅分析在命令行(my-application.jar
)中指定的JAR文件
Drawback: only analyses the JAR file that has been specified on the command line (my-application.jar
)
mylib
目录mylib
的JAR文件中提取所有文件(忽略重复的文件),然后将它们重新打包为大的JAR mylib/00lib.jar
(重命名为.jar
的简单ZIP文件即可解决问题)mylib/00lib.jar
复制到mylib/01lib.jar
以确保将其进行分析运行以下命令:
mylib
directorymylib
(ignore duplicate files) and repack them into a big JAR mylib/00lib.jar
(a simple ZIP file renamed to .jar
makes the trick)mylib/00lib.jar
to mylib/01lib.jar
to ensure that it will be analysedrun the following command:
jdeprscan --for-removal --verbose --class-path path/to/mylib/*.jar path/to/my-application.jar
优点:快速(仅需执行一些手动操作)+分析mylib
Advantage: fast (only a few manual operations) + analyses the JARs from mylib
缺点:某些jdeprscan
消息将与胖JAR 00lib.jar
相关,因此您将无法立即确定哪个库使用的Java 9中已弃用或删除的类或11,但您可以通过查看类名来间接实现,例如(com.atomikos
库中的类需要缺少的类javax.jms.JMSException
):
Drawback: some of the jdeprscan
messages will be related to the fat JAR 00lib.jar
so you will not be able to determine immediately which library uses classes that are deprecated or removed from Java 9 or 11, but you can do it indirectly by looking at the class name, e.g. (a class from the com.atomikos
library requires the missing class javax.jms.JMSException
):
Processing class com/atomikos/datasource/xa/jms/JmsTransactionalResource...
error: cannot find class javax/jms/JMSException
mylib
目录运行以下命令:
mylib
directoryrun the following command:
jdeprscan --for-removal --class-path path/to/mylib/*.jar path/to/my-application.jar
检查日志以查看由于lib目录中存在JAR而不应引发的error: cannot find class
消息.对于每个此类库,请复制一个库名称,该名称应位于按字母顺序引用该库名称的库名称之前.例如,我在lib目录alpha.jar
中有一个JAR,它依赖于commons-lang-3.0.jar
(尚未在类路径中加载),因此我将commons-lang-3.0.jar
复制到a0commons-lang-3.0.jar
,以便它将在jdeprscan
分析(并非在每个JAR上都发生).完成后,请返回第2步,直到没有库依赖项产生的错误消息发生为止.
inspect the log to see error: cannot find class
messages that are not supposed to be raised because the JAR exists in the lib directory. For each such library, copy the library with a name that is before the library name which reference it alphabetically speaking. For example, I have a JAR in the lib dir alpha.jar
which depends on commons-lang-3.0.jar
(which is not yet loaded in the classpath), so I copy commons-lang-3.0.jar
to a0commons-lang-3.0.jar
so that it will be loaded before alpha.jar
. It is important to copy the JAR and not to rename it otherwise it may not be analyzed by jdeprscan
(does not occur on every JAR). Once done, go back to step 2 until no error messages produced by library dependencies occurs.
优点:清晰地显示哪些JAR使用了不推荐使用/已删除的类.
Advantage: gives a clear view of which JAR uses deprecated/removed classes.
缺点:需要很多时间(导致类加载问题的每个JAR的手动副本).
Drawback: takes a lot time (manual copy of each individual JARs which cause a classloading issue).
我在解决方案2 中使用jdeprscan
.应该将其视为一种解决方法(它是不完整的工具文档还是错误,我不知道...).
I use jdeprscan
with Solution 2. This should be considered as a workaround (is it an incomplete tool documentation or a bug, I don't know...).