Starting in 4.0.M3, you will be able to use object.getClass().getPackage().getImplementationVersion() to get the build version which will be stored in the jar's WEB-INF/MANIFEST.MF where object can be any class in the jar.
I'm guessing something like ObjectContext.class will work in place of "object.getClass()" or you can set object to "new CayenneRuntimeException()" On Mon, Jul 27, 2015 at 10:41 AM, Mike Kienenberger <mkien...@gmail.com> wrote: > Our jar MANIFEST file also contains: > > Bundle-Version: 4.0.0.M2 > > But shouldn't we also be supplying this information as > > Implementation-Version: 4.0.0.M2 > > so it's in a standardized place? > > I'd guess that's a simple maven build change -- I know how to do it > under ant, but not under maven. > > > Once we do that, then we can use the standard java libraries to > provide the information: > > Object object = new CayenneRuntimeException(); > Package objPackage = object.getClass().getPackage(); > System.out.println("Implementation Version: " + > objPackage.getImplementationVersion()); > > produces > > Implementation Version: 4.0.0.M2 > > when I add an Implementation-Version: line to the MANIFEST in > cayenne-server-4.0.M2.jar > > ===== > Manifest-Version: 1.0 > + Implementation-Version: 4.0.0.M2 > Export-Package: org.apache.cayenne;uses:="org.apache.cayenne.reflect,o > ===== > > On Mon, 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 >> >>