jdeprscan引发找不到类错误 [英] jdeprscan throws cannot find class error

查看:121
本文介绍了jdeprscan引发找不到类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在CentOS系统上尝试jdeprscan.这是我正在执行的命令:

I'm trying jdeprscan on my CentOS system. Here are the commands that I'm executing:

export classpath=<PATH/*>:<ANOTHER/PATH/*>:<SOME/OTHER/PATH/*>
jdeprscan --for-removal --verbose --class-path $classpath --release 9 <ANOTHER/PATH>/MyProject.jar

尽管提供了类路径,但我仍然遇到此类错误

In spite of providing the classpath, I'm getting multiple errors of this sort

Processing class <some/class/in/MyProject.jar>...
error: cannot find class <some/class/in/a/different/jar>
error: cannot resolve Methodref <some/class/in/a/different/jar>.<method>:()Ljava/lang/String;

我已经验证了错误消息中提到的类是否在classpath中提供的jar之一中. 奇怪的是,不是我正在扫描的jar中引用的所有其他类都收到此错误.

I've verified that the class mentioned in the error message are pretty much among one of the jars provided in the classpath. Strangely, it's not the case that I'm getting this error for every other classes referred in the jar that I'm scanning.

需要考虑的几点:

  • classpath中提供的路径中有50多个jars
  • 我要扫描的jar驻留在classpath中提到的路径之一中
  • 我尝试了JDK 9&中可用的jdeprscan; JDK 10并出现相同的错误
  • 我尝试用 *.jar 替换classpath中的*,但无济于事!
  • The are 50+ jars in the paths provided in the classpath
  • The jar that I'm trying to scan is residing in one of the paths mentioned in the classpath
  • I've tried jdeprscan available in JDK 9 & JDK 10 and getting the same errors
  • I've tried replacing the * in classpath with *.jar, doesn't help!

我遵循的语法是否有错误,或者这是jdeprscan中的已知错误?

Is there anything wrong in the syntax that I'm following or is this a known bug in jdeprscan?

推荐答案

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...):

  • 使用通配符"path/to/lib/*.jar"(如果没有扩展名".jar",则无法使用)
  • 不支持具有多个路径的通配符(即--class-path dir1/;dir2/*.jar在通配符上引发解析异常)
  • --class-path指定的目录中的
  • JAR被添加到类路径并按字母顺序分析,这可能会导致某些error : cannot find class X消息,因为JAR a.jar可能依赖于尚未加载的JAR b.jar
  • use wildcard "path/to/lib/*.jar" (it will not work without the ".jar" extension)
  • having a wildcard with more than one path is not supported (i.e. --class-path dir1/;dir2/*.jar throws a parse exception on the wildcard)
  • JARs in the directory specified by --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.

  1. 将所有JAR解压缩到特定目录中(忽略已覆盖的文件,例如META-INF/maven/pom.xml),例如mylib(请注意,在此阶段,mylibs目录仅包含由目录包组织的类,而没有JAR).
  2. 运行以下命令:
  1. unzip all JARs in a specific directory (ignore overwritted files such as META-INF/maven/pom.xml), e.g. mylib (note that at this stage, the mylibs directory contains only classes organized by directory packages, and no JARs).
  2. run the following command:

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)

  1. 将所有JAR库复制到单个mylib目录
  2. mylib的JAR文件中提取所有文件(忽略重复的文件),然后将它们重新打包为大的JAR mylib/00lib.jar(重命名为.jar的简单ZIP文件即可解决问题)
  3. mylib/00lib.jar复制到mylib/01lib.jar以确保将其进行分析
  4. 运行以下命令:

  1. copy all JARs libs into a single mylib directory
  2. extract all files from JARs of mylib (ignore duplicate files) and repack them into a big JAR mylib/00lib.jar (a simple ZIP file renamed to .jar makes the trick)
  3. copy the mylib/00lib.jar to mylib/01lib.jar to ensure that it will be analysed
  4. run 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

解决方案3:在类路径中对JAR文件重新排序

  1. 将所有JAR库复制到单个mylib目录
  2. 运行以下命令:

  1. copy all JARs libs into a single mylib directory
  2. run 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,以便它将在.重要的是复制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...).

这篇关于jdeprscan引发找不到类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆