如何从jar文件中提取所有可用的类,并在一些简单的处理之后将输出转储到txt文件中。
例如,如果我运行jar tf commons-math3-3.1.6.jar
输出的子集将是:
org/apache/commons/math3/analysis/differentiation/UnivariateVectorFunctionDifferentiator.class
org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiator$2.class
org/apache/commons/math3/analysis/differentiation/SparseGradient$1.class
org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator$1.class
org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.class
org/apache/commons/math3/analysis/integration/gauss/BaseRuleFactory.class
org/apache/commons/math3/analysis/integration/gauss/HermiteRuleFactory.class
org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.class
org/apache/commons/math3/analysis/integration/gauss/GaussIntegratorFactory.class
我想全部转换成。
所有的美元。
最后,我还想删除出现在每个字符串末尾的.class。
例如:
org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiator$2.class
会变成
org.apache.commons.math3.analysis.differentiation.FiniteDifferencesDifferentiator.2
最佳答案
String path = "org/apache/commons/math3/analysis/integration/gauss/BaseRuleFactory.class";
path = path.replaceAll("/", ".")
.replaceAll("\\$(\\d+)\\.class", "\\.$1");