我使用了jBoss4.2.2到最新版本。我使用了java开发工具包1.5到1.7的最新版本,所有j版本都在get所有java开发工具包中。如何在java代码中获得java版本。
发布于 2013-09-03 07:01:28
对于5,有一个属性文件: /org/jboss/version.properties,其中键version.major和version.minor查找您的情况。将文件加载到“属性”并读取。见下面的链接:
http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.jbossas/jboss-as-main/5.0.0.CR2/org/jboss/version.properties
此文件也保存在jboss6.1中。
http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.jbossas/jboss-as-main/6.1.0.Final/org/jboss/version.properties?av=f
我意识到你要找jboss7..。但是,我留下了我所做的工作,以防对jboss7有用(不管怎么说,这是一种对5和6版本有效的方法),我找到了两种方法:
方法1
查看github I的代码,就无法在源代码中找到这个Versoin.properties了。但是我可以找到一个Version.class,它将版本和发布代码名存储为属性;您可以使用Version.AS_VERSION获取您想要的东西,正如您从源代码中看到的那样:
public class Version {
public static final String AS_VERSION;
public static final String AS_RELEASE_CODENAME;
public static final int MANAGEMENT_MAJOR_VERSION = 1;
public static final int MANAGEMENT_MINOR_VERSION = 4;
public static final int MANAGEMENT_MICRO_VERSION = 0;
static {
InputStream stream = Version.class.getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF");
Manifest manifest = null;
try {
if (stream != null)
manifest = new Manifest(stream);
} catch (Exception e) {
}
String version = null, code = version;
if (manifest != null) {
version = manifest.getMainAttributes().getValue("JBossAS-Release- Version");
code = manifest.getMainAttributes().getValue("JBossAS-Release-Codename");
}
if (version == null) {
version = "Unknown";
}
if (code == null) {
code = "Unknown";
}
AS_VERSION = version;
AS_RELEASE_CODENAME = code;
}}
WAY2
我在googling中找到的另一个选项是通过JMX (也许您更喜欢这种方法),但我并没有亲自验证:
ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
ModelNode op = new ModelNode();
op.get(ClientConstants.OP).set("read-resource");
ModelNode returnVal = client.execute(op);
logger.info("release-version: " + returnVal.get("result").get("release-version").asString());
logger.info("release-codename: " + returnVal.get("result").get("release-codename").asString()); 从jboss命令行界面,您可以从以下命令获得信息:/:read-attribute(name=release)
/:read-属性(name=)
注意:
源代码现在在git克隆https://github.com/wildfly/wildfly.git ( jboss网站仍然发送到一个过时的链接)下。
发布于 2013-09-03 06:45:33
https://stackoverflow.com/questions/18585748
复制相似问题