如何从 Eclipse 中的动态 Web 项目构建 EAR 文件?

发布于 2024-11-14 10:39:58 字数 225 浏览 3 评论 0原文

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

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

I'm looking at deploying a web service which I've written in Eclipse to an EAR file. I'm able to export it as a WAR and deploy it on Tomcat all fine and dandy, but the final product won't be on Tomcat, and won't be a WAR file. I'll need to use Websphere as a server, which I have access to and can deploy valid EAR files... if I had an EAR file to deploy.

So long story short, how do I export an EAR file from a Dynamic Web Project in Eclipse?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生寂 2024-11-21 10:39:58

您需要在 Eclipse 中创建一个企业应用程序项目(基本上是一个 EAR),将动态 Web 项目添加到 EAR 项目中,然后导出整个项目。

You need to create an Enterprise Application Project (basically, an EAR) in Eclipse, add the Dynamic Web Project to the EAR project, and then export the whole thing.

没有心的人 2024-11-21 10:39:58

为此,我使用 Ant 构建脚本(您可以在 Eclipse 中创建一个新的 Ant 文件,将其存储在动态 Web 项目根目录中,然后当您想从 Eclipse 运行它时右键单击 > 运行它。如下所示。基本上将您的 war 复制到目录中,${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>

那里的 ids 应该没问题,我相信它们需要对每个 EAR 是唯一的(或者是服务器无法记住)。

我希望这有帮助。

for this I use an Ant build script, (you can create a new Ant file in Eclipse, store it in your dynamic web project root and then right click > run on it when you want to run it from eclipse. Something like below. Basically copy your war to a directory, ${earDir} in the script below, and build that to an EAR (an EAR is just a type of 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>

Your was.policy file will be something like this (not good to give all permissions but you can change it later once you have it up and running):

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

Your application.xml file will be something like this:

<?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>

The ids there should be ok they need to be unique per EAR I believe (or is it server cant remember).

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文