Add version to Jar packaging
来源:互联网 发布:php 中文变量名 编辑:程序博客网 时间:2024/06/07 00:52
1.
Add version to Jar packagingTag(s): Environment
Let's say we have the following class (package is mandatory)package com.rgagnon;public class Hello { public static void main(String[] args) { new Hello().say("Hello World!"); } public void say(String s) { System.out.println(s); }}
Manifest-Version: 1.0Main-Class: com.rgagnon.Hello
>jar cvfm hello.jar MANIFEST.MF com\rgagnon\Hello.class>java -jar hello.jarHello World!
Manifest-Version: 1.0Main-Class: com.rgagnon.HelloSpecification-Version: 2.1Implementation-Version: 1.1
package com.rgagnon;public class Hello { public static void main(String[] args) { new Hello().say("Hello World!"); } Hello() { Package p = this.getClass().getPackage(); System.out.println("Hello Specification Version : " + p.getSpecificationVersion()); System.out.println("Hello Implementation Version : " + p.getImplementationVersion()); } public void say(String s) { System.out.println(s); }}
> jar cvfm hello.jar MANIFEST.MF com\rgagnon\Hello.class> java -jar hello.jarSpecification Version : 2.1Implementation Version : 1.1Hello World!
See also this Howto.
This example opens a given Jar and outputs its version information.
package com.rgagnon.howto;import java.util.jar.*;public class JarUtils { public static String getJarImplementationVersion(String jar) throws java.io.IOException { JarFile jarfile = new JarFile(jar); Manifest manifest = jarfile.getManifest(); Attributes att = manifest.getMainAttributes(); return att.getValue("Implementation-Version"); } public static String getJarSpecificationVersion(String jar) throws java.io.IOException { JarFile jarfile = new JarFile(jar); Manifest manifest = jarfile.getManifest(); Attributes att = manifest.getMainAttributes(); return att.getValue("Specification-Version"); } public static void main(String[] args) throws java.io.IOException{ String javaMailJar = "C:/Program Files/Java/jre1.5.0/lib/mail.jar"; System.out.println("Specification-Version: " + JarUtils.getJarSpecificationVersion(javaMailJar)); System.out.println("Implementation-Version: " + JarUtils.getJarImplementationVersion(javaMailJar)); /* * output : * Specification-Version: 1.3 * Implementation-Version: 1.3.1 */ }}
2.
- Add version to Jar packaging
- Unable to add module to the current project as it is not of packaging type 'pom'
- Tomcat -- add project jar to tomcat.
- Packaging Programs in JAR Files
- 错误整理:Unable to add module to the current project as it is not of packaging type 'pom'
- Unable to add module to the current project as it is not of packaging type 'pom' 问题解决
- pom文件中<packaging>jar</packaging>的真实含义
- ImportError: No module named packaging.version
- ImportError: No module named packaging.version
- 执行 maven 命令 报错Unable to add module to the current project as it is not of packaging type 'pom'
- How to add local jar into your local maven repository
- 如何给Visual Studio的Win32 工程添加Version信息(how to add version information of win32 project)
- Unable to add plugins. Perhaps your version of Cordova is too old
- svn add 报错 is too old (format 10) to work with client version '1.8.8
- Maven:the way to add third-party jar-package to Local Maven Repository for using conveniently
- Unable to add the resource at [*/*/*.jar] to the cache because there
- Difference between maven scope compile and provided for JAR packaging
- add jar的意思
- ubuntu下source、sh、bash、./执行脚本的区别
- cascade="save-update" 级连的作用
- oracle客户端连接服务器基本教程
- 驱动开发博客(待更新)
- Spring的核心机制依赖注入简介
- Add version to Jar packaging
- Mysql的源码安装
- Hibernate之 Criteria查询
- Linux设备驱动开发环境的搭建(转)
- hibernate 方言的作用
- Android图形---OpenGL(一)
- Ubuntu 12.04--Eclipse subclipse error
- 免费GB网络硬盘|网盘|网络U盘|最好的免费网络硬盘|赚钱网盘
- 在64位服务器上安装oracle 32位客户端只能被编译为x86的程序连接