如何在 ejb-jar.xml 中放置版本号和内部版本号
How to put version and build number in ejb-jar.xml
我正在使用 Netbeans 8.0.2 和 Glassfish 4.0(和 4.1)构建一个消息驱动的 bean。我没有使用 Maven(我的选择是使用它)
有一篇文章将修订版和内部版本号放入 build.xml 文件 (http://dragly.org/2009/10/11/revision-and-build-numbers-for-your-netbeans-apps/)。这是针对 SE 应用程序的,我不确定它是否适用于 EJB 以及如何使用。
我有一个固定的版本号,但需要增加内部版本号。
- 在何处以及如何将 EJB 的版本号(加上内部版本号)放入其中? (应该是像1.0.0.buildNumber)(搜索"ejb-jar.xml" plus version给出了很多EJB版本2.x,3.x的结果)
- 如何在我的 EJB 中访问这个号码? (我想在我的 class 中将其作为资源访问?)
好的,我明白了:
对于 build.xml
文件中的 jar(库、SE 等),就在 </project>
结束标记之前插入以下内容;基于 http://www.jug-muenster.de/versioning-and-signing-jar-files-in-netbeans-775/ :注意: 清单文件具有非常特定的格式!
<target name="-pre-init">
<property name="project.name" value="MySEProject" />
<property name="document.title" value="My SE Project Specification" />
<property name="document.version" value="1.0" />
<property name="version.number" value="1.7.0" />
<buildnumber file="build.num" />
<tstamp>
<format property="NOW" pattern="yyyy-MM-dd HH:mm:ss z" />
</tstamp>
<exec outputproperty="svna.version" executable="svnversion">
<arg value="-c" />
<redirector>
<outputfilterchain>
<tokenfilter>
<replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
<replaceregex pattern="M" replace="" flags="g"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<!-- Add the version information to the manifest file -->
<manifest file="${manifest.file}">
<attribute name="Package-Title" value="MyCompany/${project.name}" />
<attribute name="Specification-Title" value="${document.title}" />
<attribute name="Specification-Version" value="${document.version}" />
<attribute name="Specification-Vendor" value="MyCompany" />
<attribute name="Implementation-Title" value="${project.name}" />
<attribute name="Implementation-Version" value="${halo.version.number}.${build.number}" />
<attribute name="Implementation-Vendor" value="MyCompany" />
<attribute name="Revision" value="${svna.version}" />
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-Date" value="${NOW}" />
</manifest>
</target>
<target name="-post-jar">
<delete file="${manifest.file}" />
</target>
对于 EJB。在 (ABC) Enterprise Application 文件夹中,同上编辑 build.xml
文件,目标标签名称更改为 pre-dist
以及 清单标签 <manifest file="${meta.inf}/MANIFEST.MF">
.
此外,对于 EJB,要能够通过编程读取版本号,请编辑 ABC-ejb 文件夹中的 build.xml
文件(其中 ABC 是 ejb 项目名称)。目标名称更改为 -post-init
.
读取它的代码(您从包含的所有库中获取所有清单文件,因此您必须寻找您的清单文件 - 也许更好的方法是查看 URL? ):
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author TungstenX
*/
public class VersionInfo {
private static final Logger LOG = Logger.getLogger(VersionInfo.class.getName());
private static final String PROJECT = "MySEProject";
private static final String COMPANY = "MyCompany";
private static Manifest MANIFEST;
/**
* Get the version number from the manifest file
* @return The version number or '--'
*/
public static String GetVersionNumber() {
if (MANIFEST == null) {
try {
Enumeration<URL> resources = VersionInfo.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
try(InputStream is = url.openStream()) {
Manifest tmpManifest = new Manifest(is);
for (Object o : tmpManifest.getMainAttributes().keySet()) {
if (o.toString().equals("Package-Title")
&& tmpManifest.getMainAttributes().getValue(o.toString()).startsWith(COMPANY)
&& tmpManifest.getMainAttributes().getValue(o.toString()).endsWith(PROJECT)) {
MANIFEST = tmpManifest;
}
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "Error while reading manifest files: {0}", e.toString());
}
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "Error while reading manifest files: {0}", e.toString());
}
}
if(MANIFEST != null) {
return MANIFEST.getMainAttributes().getValue("Implementation-Version");
} else {
return "--";
}
}
注意:MANIFEST.MF
文件的目标名称和位置的区别!
我正在使用 Netbeans 8.0.2 和 Glassfish 4.0(和 4.1)构建一个消息驱动的 bean。我没有使用 Maven(我的选择是使用它)
有一篇文章将修订版和内部版本号放入 build.xml 文件 (http://dragly.org/2009/10/11/revision-and-build-numbers-for-your-netbeans-apps/)。这是针对 SE 应用程序的,我不确定它是否适用于 EJB 以及如何使用。
我有一个固定的版本号,但需要增加内部版本号。
- 在何处以及如何将 EJB 的版本号(加上内部版本号)放入其中? (应该是像1.0.0.buildNumber)(搜索"ejb-jar.xml" plus version给出了很多EJB版本2.x,3.x的结果)
- 如何在我的 EJB 中访问这个号码? (我想在我的 class 中将其作为资源访问?)
好的,我明白了:
对于 build.xml
文件中的 jar(库、SE 等),就在 </project>
结束标记之前插入以下内容;基于 http://www.jug-muenster.de/versioning-and-signing-jar-files-in-netbeans-775/ :注意: 清单文件具有非常特定的格式!
<target name="-pre-init">
<property name="project.name" value="MySEProject" />
<property name="document.title" value="My SE Project Specification" />
<property name="document.version" value="1.0" />
<property name="version.number" value="1.7.0" />
<buildnumber file="build.num" />
<tstamp>
<format property="NOW" pattern="yyyy-MM-dd HH:mm:ss z" />
</tstamp>
<exec outputproperty="svna.version" executable="svnversion">
<arg value="-c" />
<redirector>
<outputfilterchain>
<tokenfilter>
<replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
<replaceregex pattern="M" replace="" flags="g"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<!-- Add the version information to the manifest file -->
<manifest file="${manifest.file}">
<attribute name="Package-Title" value="MyCompany/${project.name}" />
<attribute name="Specification-Title" value="${document.title}" />
<attribute name="Specification-Version" value="${document.version}" />
<attribute name="Specification-Vendor" value="MyCompany" />
<attribute name="Implementation-Title" value="${project.name}" />
<attribute name="Implementation-Version" value="${halo.version.number}.${build.number}" />
<attribute name="Implementation-Vendor" value="MyCompany" />
<attribute name="Revision" value="${svna.version}" />
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-Date" value="${NOW}" />
</manifest>
</target>
<target name="-post-jar">
<delete file="${manifest.file}" />
</target>
对于 EJB。在 (ABC) Enterprise Application 文件夹中,同上编辑 build.xml
文件,目标标签名称更改为 pre-dist
以及 清单标签 <manifest file="${meta.inf}/MANIFEST.MF">
.
此外,对于 EJB,要能够通过编程读取版本号,请编辑 ABC-ejb 文件夹中的 build.xml
文件(其中 ABC 是 ejb 项目名称)。目标名称更改为 -post-init
.
读取它的代码(您从包含的所有库中获取所有清单文件,因此您必须寻找您的清单文件 - 也许更好的方法是查看 URL? ):
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author TungstenX
*/
public class VersionInfo {
private static final Logger LOG = Logger.getLogger(VersionInfo.class.getName());
private static final String PROJECT = "MySEProject";
private static final String COMPANY = "MyCompany";
private static Manifest MANIFEST;
/**
* Get the version number from the manifest file
* @return The version number or '--'
*/
public static String GetVersionNumber() {
if (MANIFEST == null) {
try {
Enumeration<URL> resources = VersionInfo.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
try(InputStream is = url.openStream()) {
Manifest tmpManifest = new Manifest(is);
for (Object o : tmpManifest.getMainAttributes().keySet()) {
if (o.toString().equals("Package-Title")
&& tmpManifest.getMainAttributes().getValue(o.toString()).startsWith(COMPANY)
&& tmpManifest.getMainAttributes().getValue(o.toString()).endsWith(PROJECT)) {
MANIFEST = tmpManifest;
}
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "Error while reading manifest files: {0}", e.toString());
}
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "Error while reading manifest files: {0}", e.toString());
}
}
if(MANIFEST != null) {
return MANIFEST.getMainAttributes().getValue("Implementation-Version");
} else {
return "--";
}
}
注意:MANIFEST.MF
文件的目标名称和位置的区别!