Java 如何在ejb-jar.xml中放置版本和内部版本号

Java 如何在ejb-jar.xml中放置版本和内部版本号,java,xml,jakarta-ee,netbeans,glassfish,Java,Xml,Jakarta Ee,Netbeans,Glassfish,我正在使用Netbeans 8.0.2和Glassfish 4.0(和4.1)构建一个消息驱动bean。我没有使用Maven(我的选择是使用它) 有一篇文章将修订版和内部版本号放在build.xml文件()中。这是针对SE应用程序的,我不确定它是否适用于EJB以及如何工作 我有一个固定的版本号,但需要增加版本号 在哪里以及如何为EJB输入版本号(加上内部版本号)?(它应该类似于1.0.0。buildNumber)(搜索“ejb jar.xml”加上版本会得到很多ejb版本2.x、3.x的结果)

我正在使用Netbeans 8.0.2和Glassfish 4.0(和4.1)构建一个消息驱动bean。我没有使用Maven(我的选择是使用它)

有一篇文章将修订版和内部版本号放在build.xml文件()中。这是针对SE应用程序的,我不确定它是否适用于EJB以及如何工作

我有一个固定的版本号,但需要增加版本号

  • 在哪里以及如何为EJB输入版本号(加上内部版本号)?(它应该类似于1.0.0。buildNumber)(搜索“ejb jar.xml”加上版本会得到很多ejb版本2.x、3.x的结果)
  • 如何在EJB中访问此号码?(我想把它作为我班上的一种资源?)
  • 好吧,我想起来了: 对于
    build.xml
    文件中的jar(库、SE等),在关闭
    标记之前插入以下内容:;基于:注意:清单文件具有非常特定的格式

    <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>
    
    注意:目标名称和
    MANIFEST.MF
    文件位置的差异

    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 "--";
            }
        }