Skip to content

Instantly share code, notes, and snippets.

@Sythelux
Created September 3, 2015 12:15
Show Gist options
  • Save Sythelux/a8ebd19831d95f675d27 to your computer and use it in GitHub Desktop.
Save Sythelux/a8ebd19831d95f675d27 to your computer and use it in GitHub Desktop.
reads some Information from Manifest File and returns them as String
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
public class BuildInfoBuilder {
public static String buildInfo() {
try {
for (URL url : Collections.list(Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME))) {
try (InputStream is = url.openStream()) {
Manifest manifest = new Manifest(is);
Attributes mainAttribs = manifest.getMainAttributes();
String user = mainAttribs.getValue("Build-User");
String version = mainAttribs.getValue("Build-Label");
String time = mainAttribs.getValue("Build-Time");
if (user != null || version != null || time != null) {
return user + " made " + version + " @ " + time;
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
return "no Info";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment