admin 管理员组

文章数量: 887021

manifest

1.maven 配置manifest

在pom文件中 加上 maven-jar-plugin 插件 自定义manifest 属性值

<build><plugins><plugin>  <groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><manifest><addClasspath>true</addClasspath></manifest><manifestEntries><version>${current-version}</version><struts-version>${struts-version}</struts-version><spring-version>${spring-version}</spring-version><hibernate-version>${hibernate-version}</hibernate-version><api-version>${api-version}</api-version><sdk-version>${sdk-version}</sdk-version><environment>${environment}</environment></manifestEntries></archive></configuration></plugin></plugins></build>


2 java读取manifest 文件属性

jar 中提供读取jar 包中的manifest 方法  java 代码如下:

<%@ page import="java.io.File" %>
<%@ page import="java.net.InetAddress" %>
<%@ page import="java.util.jar.JarFile" %>
<%@ page import="java.util.jar.Manifest" %>
<%@ page import="java.util.regex.Pattern" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.jar.Attributes" %>
String path=new java.io.File(application.getRealPath("manifest.jsp")).getParent();
JarFile jar;
try {String packagePath=path+File.separator+"WEB-INF"+File.separator+"lib";File file = new File(packagePath);if (file.isDirectory()) {Pattern pattern = Pattern.compile("mkts-common-{1,}[0-9].{1,}[0-9].jar");String[] filelist = file.list();for (String fileName : filelist) {if (pattern.matcher(fileName).find()) {packagePath = packagePath  +File.separator + fileName;break;}}}jar = new JarFile(packagePath);Attributes attributes = jar.getManifest().getMainAttributes();for (Map.Entry<Object, Object> entry : attributes.entrySet()) {String keyStr = String.valueOf(entry.getKey());if ("Class-Path".equals(keyStr) || "Archiver-Version".equals(keyStr))continue;out.print(entry.getKey() + " : " + entry.getValue());%><br /><%}
} catch (Exception e) {e.printStackTrace();
} 


本文标签: manifest