如何从Eclipse将Maven项目的WAR部署到JBoss服务器?

发布于 2024-11-04 22:28:22 字数 631 浏览 5 评论 0原文

我想将Maven项目的WAR部署到JBoss服务器。我知道从 Eclipse Export->War 将 WAR 文件部署到 JBoss。但是我怎样才能为 Maven 项目做到这一点呢?任何一步一步的信息或有用的网站链接都会对我非常有帮助。谢谢。

编辑:我已添加

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
    <jbossHome>/home/tanmoy/Jboss</jbossHome>
    <serverName>all</serverName>
    <fileName>target/LoginExample-1.0.war</fileName>
</configuration>
</plugin>

到我的 pom.xml 并再次导入为 maven 项目,但右键单击 pom.xml 以运行方式时,我没有看到任何部署选项。

I want to deploy WAR of Maven project to JBoss server. I know that from Eclipse Export->War deploy the WAR file to JBoss. But How can I do this for Maven Project. Any step by step information or useful website link will be very helpful to me. Thank you.

Edit: I have added

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
    <jbossHome>/home/tanmoy/Jboss</jbossHome>
    <serverName>all</serverName>
    <fileName>target/LoginExample-1.0.war</fileName>
</configuration>
</plugin>

To my pom.xml and import again as maven project, but on right clicking into pom.xml for Run As I don't see any option for deployment.

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

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

发布评论

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

评论(9

清眉祭 2024-11-11 22:28:27

如果它是一个 Maven 应用程序(EAR)或(JAR)或其他什么,您只需添加到您的 pom.xml:

        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <configuration>
                <filename>${artifactId}-${project.version}.ear</filename>
                <port>9999</port> <!-- you change it following what you have on your server config -->
            </configuration>
        </plugin>

并在您的 Eclipse 中运行您为目标所做的配置:jboss-as:deploy

当然我是在和她谈论 Jboss AS7 或 EAP6

If it is a maven application (EAR) or (JAR) or what ever, you have just to add to your pom.xml:

        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <configuration>
                <filename>${artifactId}-${project.version}.ear</filename>
                <port>9999</port> <!-- you change it following what you have on your server config -->
            </configuration>
        </plugin>

And in your eclipse run configurations you make for the goals : jboss-as:deploy

Of course i am talking her about Jboss AS7 or EAP6

乖乖 2024-11-11 22:28:27

使用以下目标在 Jboss 文件夹中部署您的 war

clean install jboss:hard-deploy

Use the following goals to deploy your war in Jboss folder

clean install jboss:hard-deploy
能怎样 2024-11-11 22:28:26

我找到了解决方案并分享,因为它可能对某人有帮助。
我的配置是:

  1. Fedora 14
  2. Eclipse Helios for Java EE
  3. JBoss 4.2.0-GA

您还需要

  1. 在系统中安装 maven
  2. 在 Eclipse 中安装 m2eclipse 插件

现在您已准备好开始创建项目。

  1. 打开 Eclipse-> 选择您的工作区
  2. 设置服务器。设置服务器
    1. 进入窗口 -> 显示视图 -> 服务器
    2. 右键单击服务器窗格,选择“新建”->“服务器”
    3. 从打开的窗口中选择 JBoss->JBoss v4.2
    4. 点击“下一步”
    5. 浏览应用程序服务器目录,即文件系统中 JBoss 所在的位置。
    6. 点击“完成”
  3. Create a new Dynamic Web Project,创建项目
    1. 转到“文件”->“新建”->“项目”,选择“Web”节点下的“Dynamic Web Project”
    2. 点击“下一步”
    3. 给出项目名称
    4. 从目标运行时选择 JBoss v4.2
    5. 点击“下一步”两次
    6. 您将需要 web.xml,因此请确保在最后一页中选中“生成 web.xml 部署描述符”。
    7. 单击“完成”,Eclipse 将为您创建一个动态 Web 项目
  4. 现在您需要为创建的项目启用 Maven 依赖管理。要做到这一点
    1. 右键单击项目名称
    2. 选择 Maven -> 启用依赖管理
    3. 将打开一个用于创建 POM 的窗口
    4. 从“打包”下拉菜单中选择“war”
    5. 单击“完成”,您的 pom.xml 将被创建
  5. 它会弄乱您的构建小路。修复它
    1. 右键单击项目名称并转到“属性”
    2. 从左侧窗格中选择 Java 构建路径
    3. 转到“库”选项卡
    4. 编辑 JRE 系统库。编辑系统库
      1. 选择JRE System Library,然后单击右侧的“编辑”按钮
      2. 从下拉菜单中选择执行环境 JavaSE-1.6
      3. 点击“完成”
    5. 转到“源”选项卡
      1. 点击“添加文件夹”
      2. 选择源
      3. 点击“确定”,您的项目已准备就绪
  6. 现在添加一些源文件,配置 web.xml 和 pom.xml 并将其作为 WAR 导出到 JBoss 服务器。部署它
    1. 首先将所有需要的jar复制到WEB-INF中的lib文件夹
    2. 每当您向 pom.xml 添加依赖项时,Mavan 都会下载所需的 jar 并添加到您的项目中。您可以通过展开节点“项目”->“Java 资源”->“库”->“Maven 依赖项”来查看这些 jar。每个 jar 文件旁边都给出了 jar 的路径。它通常驻留在/.m2/repository 中。您可以将这些文件复制到上述 lib 文件夹中。
    3. 现在右键单击项目名称
    4. 选择“导出”->“WAR 文件”
    5. 在“目标”中浏览服务器的路径
    6. 单击 Finish,它将把 WAR 文件部署到 JBoss 服务器中。

注意:您的 WAR 的 jar 与 JBoss 的 lib 的 jar 有一些重叠的可能性。那么你应该采取适当的行动。例如,从 WAR 中删除 jar(如果您的 jar 版本与 JBoss 的版本相同或低于 JBoss 的版本),或者替换 JBoss 的 jar 并从 WAR 中删除该 jar(如果你的 jar 版本高于 JBoss 的版本)。我应该小心这一点,并在做任何事情之前收集良好的知识。

谢谢。

I found the solution and I am sharing as it might be helpful to someone.
My configuration is:

  1. Fedora 14
  2. Eclipse Helios for Java EE
  3. JBoss 4.2.0-GA

You also need to

  1. Install maven in your system
  2. Install m2eclipse plug-in in your Eclipse

Now you are ready to start to create project.

  1. Open Eclipse->Choose your Workspace
  2. Set-up server. To set-up server
    1. Got to Window->Show View->Servers
    2. Right click on server pane, select New->Server
    3. Select JBoss->JBoss v4.2 from the window opened
    4. Click Next
    5. Browse Application Server Directory, i.e., the location in your file system where JBoss resides.
    6. Click Finish
  3. Create a new Dynamic Web Project, to create the project
    1. Go to File->New->Project, select Dynamic Web Project under the Web node
    2. Click Next
    3. Give a project name
    4. Select JBoss v4.2 from Target runtime
    5. Click Next twice
    6. You will need web.xml so make sure "Generate web.xml deployment descriptor" is checked in the last page.
    7. Click Finish and Eclipse will create a Dynamic Web Project for you
  4. Now you need to enable Maven Dependency Management for created project. To do this
    1. Right click on the Project name
    2. Select Maven->Enable Dependency Management
    3. A window will be opened for POM creation
    4. Select war from Packaging drop-down menu
    5. Click Finish and your pom.xml will be created
  5. It will messed up your build path. To fix it
    1. Right click on the Project name and go to Properties
    2. Choose Java Build Path from the left pane
    3. Go to Libraries tab
    4. Edit JRE System Library. To edit system library
      1. Select JRE System Library and click Edit button in the right
      2. Choose Execution Environment JavaSE-1.6 from the drop-down menu
      3. Click Finish
    5. Go to Source tab
      1. Click Add Folder
      2. Select src
      3. Click Ok and your project is ready
  6. Now add some source files, configure web.xml and pom.xml and export it to JBoss server as WAR. To deploy it
    1. First copy all required jars to the lib folder in WEB-INF
    2. Whenever you add dependency to pom.xml Mavan will download required jar and add to your project. You can see these jars by expanding nodes Project->Java Resource->Libraries->Maven Dependencies. The path-to-jars are given beside each jar file. It is usually resides in /.m2/repository. You can copy those files into the aforesaid lib folder.
    3. Now right click on Project name
    4. Select Export->WAR file
    5. In Destination browse the path to your server
    6. Click Finish and it will deploy the WAR file into JBoss server.

Note: there are some possibilities of overlapping jar(s) of your WAR with the jar(s) of JBoss's lib. Then you should take appropriate action. Like remove the jar(s) from your WAR (in case the version of your jar is same or lower than that of JBoss's) or replace the jar(s) of JBoss and remove that jar(s) from your WAR(in case the version of your jar is higher than that of JBoss's). I should be careful about this and gather well knowledge before doing anything.

Thank you.

北城半夏 2024-11-11 22:28:26

您可以右键单击 pom.xml 文件并选择 Run As -> Maven 构建。将构建目标设置为清理包。完成后,进入项目的目标目录,右键单击战争并导出,就像您当前正在做的那样。

编辑:

要从 pom.xml 中执行此操作,请使用 jboss maven 插件: http://mojo.codehaus.org/jboss-maven-plugin/examples/deploy-undeploy-examples.html

You can right click on the pom.xml file and choose Run As -> Maven Build. Set the build goals to clean package. When that completes go into the target directory of your project, right click on the war and export as you are currently doing.

EDIT:

To do this from within your pom.xml use the jboss maven plugin: http://mojo.codehaus.org/jboss-maven-plugin/examples/deploy-undeploy-examples.html

九八野马 2024-11-11 22:28:26

正确的格式是:

<fileName>${basedir}/target/webapp.war</fileName>

The correct format is:

<fileName>${basedir}/target/webapp.war</fileName>
月光色 2024-11-11 22:28:26

只需将以下插件添加到 POM.xml 对我来说很有效。

<build>
    ...
    <plugins>
        ...
        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>7.9.Final</version>
        </plugin>
        ...
    </plugins>
    ...
</build>

使用命令提示符可以部署或取消部署工件。

  mvn jboss-as:redeploy
  mvn jboss-as:undeploy

注意:上述选项使用 http://localhost:9999 url 将工件部署到服务器。在执行命令之前,Jboss 服务器应该在后台运行。

也可以使用eclipse来执行上述目标。

步骤1:点击运行配置。
输入图片此处描述

第 2 步:创建新的 Maven 构建
输入图片此处描述

步骤 3:更新构建详细信息,如图所示。
输入图片此处描述

找到

更多选项可以在https://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/deployment-example.html

Simply adding below plugin to POM.xml worked for me.

<build>
    ...
    <plugins>
        ...
        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>7.9.Final</version>
        </plugin>
        ...
    </plugins>
    ...
</build>

Using command prompt one can deploy or undeploy the artifact.

  mvn jboss-as:redeploy
  mvn jboss-as:undeploy

Note: The above option uses http://localhost:9999 url to deploy the artifact to server. The Jboss server should be running in background before the command is executed.

Also one can use eclipse to execute above goals.

Step 1: Click on run configuration.
enter image description here

Step 2:Create a new Maven Build
enter image description here

Step 3:Update build details as shown.
enter image description here

More option can be found at

https://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/deployment-example.html

灯角 2024-11-11 22:28:26

假设

我假设您已经安装了 Eclipse 的 Maven 插件。

安装

在项目资源管理器中选择项目时选择
运行-->运行方式 --> Maven 安装

运行 Jboss

  1. 转到运行 -->运行配置..

  2. 添加新的 Maven 构建

  3. 命名进程,选择将部署为 war 的基目录

  4. 设定目标 --> jboss:start

按照以下步骤,您可以通过 Eclipse 部署所有内容。

玩得开心。 :)

Assumption

I am assuming that you have already installed the plugins for Maven for eclipse.

Installation

While selecting the project in project explorer select
Run --> Run As --> Maven Install

Running Jboss

  1. Go to Run --> Run Configurations..

  2. Add new Maven Build

  3. Name the Process, Select the Base directory that will be deployed as war

  4. set the Goal --> jboss:start

By following the steps you can deploy every thing via Eclipse.

Have fun. :)

骑趴 2024-11-11 22:28:26
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-war</id>
                <phase>install</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <type>${project.packaging}</type>
                            <overWrite>true</overWrite>
                            <outputDirectory>C:\jboss-as-7.1.1.Final_AMGEN\jboss-as-7.1.1.Final\standalone\deployments</outputDirectory>
                            <destFileName>${project.build.finalName}.${project.packaging}</destFileName>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>

这里“包含Jboss中部署文件夹的地址”
将给定的代码相应地放入 pom.xml

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-war</id>
                <phase>install</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <type>${project.packaging}</type>
                            <overWrite>true</overWrite>
                            <outputDirectory>C:\jboss-as-7.1.1.Final_AMGEN\jboss-as-7.1.1.Final\standalone\deployments</outputDirectory>
                            <destFileName>${project.build.finalName}.${project.packaging}</destFileName>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>

here <outputDirectory>"containes address of deployment folder in Jboss"</outputDirectory>
put the given code accordingly in pom.xml

久随 2024-11-11 22:28:26

那么 http://cargo.codehaus.org/Maven2+plugin 也可能是一个不错的选择。

Well http://cargo.codehaus.org/Maven2+plugin could be a nice alternative, too.

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