The META-INF method is not as concise as the Project.CURRENT_PROJECT_VERSION method, but it appears to be more correct.
You had a mistake in your code. Here is the corrected version. Properties props = new Properties(); String path = "META-INF/maven/org.apache.cayenne/cayenne-server/pom.properties"; try(InputStream in = ObjectContext.class.getClassLoader().getResourceAsStream(path)) { props.load(in); } String cayenneServerVersion = props.getProperty("version"); This results in the string: 4.0.M2 This is adequate for a system health-check, thanks. Joe > On Jul 27, 2015, at 9:57 AM, Andrus Adamchik <and...@objectstyle.org> wrote: > > >> On Jul 27, 2015, at 4:21 PM, Joe Baldwin <jfbald...@earthlink.net> wrote: >> >> 1. My goal is to display the version of cayenne server jar I have added to >> the project with Cayenne 4.0. > > As it happens, Project.CURRENT_PROJECT_VERSION (or its 4.0 alternative) is > not the same as the version of cayenne server jar. It denotes the version of > the XML mapping format, which does not align with the .jar version. > > If you need the version of the jar, here is another approach. While you are > not using Maven, Cayenne is assembled with Maven, so each Cayenne jar has > some extra metadata that you get for free. Namely there's a "pom.properties" > file that you can read and get the version: > > Properties props = new Properties(); > String path = > "META-INF/maven/org.apache.cayenne/cayenne-server/pom.properties"; > try(InputStream in : > ObjectContext.class.getClassLoader().getResourceAsStream(path)) { > props.load(in); > } > > String version = props.getProperty("version"); > > Andrus > >