各jarのルートレベルにあるプロパティファイル "version.properties"からプロパティ "product.build.number"を読み取る必要があります。私の素朴なアプローチは次のとおりです。jar内のプロパティファイルから特定のプロパティを読み込みます
private static int getProductBuildNumber(File artefactFile) throws FileNotFoundException, IOException
{
try (ZipInputStream zip = new ZipInputStream(new FileInputStream(
artefactFile)))
{
Set<String> possClasses = new HashSet<>();
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip
.getNextEntry())
{
if (!entry.isDirectory() && entry.getName().toLowerCase().equals(
"version.properties"))
{
List<String> lines = IOUtils.readLines(zip, (String) null);
for (String line : lines)
{
if (line.startsWith("product.build.number"))
{
String[] split = line.split("=");
if (split.length == 2)
{
return Integer.parseInt(split[1]);
}
}
}
}
}
}
throw new IOException("product.build.number not found.");
}
もっとエレガントで信頼できる方法があると思います。何か案は?
あなたのアプローチは正しく見えます – vsminkov