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
版权声明:本文标题:manifest 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1687426661h101282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论