【问题标题】:How can I build an EAR file from a Dynamic Web Project in Eclipse?如何在 Eclipse 中从动态 Web 项目构建 EAR 文件?
【发布时间】:2011-09-10 05:12:55
【问题描述】:

我正在考虑将我在 Eclipse 中编写的 Web 服务部署到 EAR 文件中。我可以将它导出为 WAR 并将其部署在 Tomcat 上,一切都很好,但最终产品不会在 Tomcat 上,也不会是 WAR 文件。我需要使用 Websphere 作为服务器,我可以访问它并且可以部署有效的 EAR 文件...如果我有要部署的 EAR 文件。

长话短说,如何从 Eclipse 中的动态 Web 项目中导出 EAR 文件?

【问题讨论】:

    标签: java eclipse websphere ear


    【解决方案1】:

    为此,我使用了一个 Ant 构建脚本,(您可以在 Eclipse 中创建一个新的 Ant 文件,将其存储在您的动态 Web 项目根目录中,然后在您想从 Eclipse 中运行它时右键单击 > 运行它。类似于下面。基本上将您的战争复制到一个目录,${earDir} 在下面的脚本中,然后将其构建到 EAR(EAR 只是一种 JAR):

        <target name="buildEar" depends="init">
        <copy tofile="${earDir}/" file="yourWarFile"/>
        <copy tofile="${earDir}/META-INF/application.xml" file="localDirectory/application.xml"/>
        <copy todir="${earDir}/META-INF">
            <fileset dir="localDirectory" includes="was.policy" />
        </copy>
        <jar jarfile="localDir/something.ear" basedir="${earDir}">
            <!-- Define the properties for the Manifest file. -->
            <manifest>
                <attribute name="Implementation-Vendor"  value="Company name"/>
                <attribute name="Implementation-Title"   value="Application Title"/>
                <attribute name="Implementation-Version" value="version and build number"/>
            </manifest>     
        </jar>
    </target>
    

    您的 was.policy 文件将是这样的(不提供所有权限,但您可以在启动并运行后更改它):

        //
    // Template policy file for enterprise application.
    // Extra permissions can be added if required by the enterprise application.
    //
    // NOTE: Syntax errors in the policy files will cause the enterprise application FAIL to start.
    //       Extreme care should be taken when editing these policy files. It is advised to use
    //       the policytool provided by the JDK for editing the policy files
    //       (WAS_HOME/java/jre/bin/policytool). 
    //
    
    grant codeBase "file:${jars}" {
    };
    
    grant codeBase "file:${connectorComponent}" {
    };
    
    grant codeBase "file:${webComponent}" {
    };
    
    grant codeBase "file:${ejbComponent}" {
    };
    
    grant codeBase "file:${application}" {
      permission java.security.AllPermission;
    };
    

    您的 application.xml 文件将如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
        <display-name>yourAppName</display-name>
        <module id="WebModule_1240219352859">
            <web>
                <web-uri>yourWarFile.war</web-uri>
                <context-root>urlToApplication</context-root>
            </web>
        </module>
    </application>
    

    那里的 id 应该没问题,我相信它们需要每个 EAR 都是唯一的(或者服务器不记得了)。

    我希望这会有所帮助。

    【讨论】:

    • 嘿@gurnard,我也有类似的问题,除了我需要在weblogic 上部署我的.ear。在 oracle 管理员控制台上安装项目后,我在访问项目时遇到了一些问题。我似乎无法弄清楚如何访问我的项目拥有的 index.jsp 页面。知道可能出了什么问题吗?
    • 这里也是我发布的问题,请看一下,它会帮助你知道我到底在哪里卡住了。 @gurnard stackoverflow.com/questions/34086464/…
    【解决方案2】:

    您需要在 Eclipse 中创建一个 Enterprise Application Project(基本上是一个 EAR),将 Dynamic Web Project 添加到 EAR 项目中,然后将整个项目导出。

    【讨论】:

    • @Matt-出于某种原因,在我执行此操作后,websphere 给了我一个错误:The EAR file could be corrupt and/or incomplete. Make sure that the application is at a compatible Java 2 Platform, Enterprise Edition (J2EE) Level for WebSphere Application Server. 也许我缺少配置设置?
    • 我遗漏了很多配置设置,如我的其他一些帖子所示。因此,一旦我的语言版本正确,我就能够创建依赖于我的项目的 EAP,并确保包含 application.xml,然后将其导出为 EAR 文件。
    • 抱歉,我在解决错误方面没有多大用处,但我很高兴你能正常工作。
    • 如何“将动态 Web 项目添加到 EAR 项目中”?
    • 为了将 DW 项目添加到 EAR,我需要将它放在 EarContent 文件夹中吗?
    猜你喜欢
    • 2018-04-13
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多