How to deploy WAR of Maven Project to JBoss server from Eclipse?

94,433

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 4

The correct format is:

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

Solution 5

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. :)

Share:
94,433
Tapas Bose
Author by

Tapas Bose

Java developer.

Updated on July 09, 2022

Comments

  • Tapas Bose
    Tapas Bose almost 2 years

    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.

  • Tapas Bose
    Tapas Bose about 13 years
    Run As->Maven install build the project and place a WAR into the target folder, I can manually copy-paste it into JBoss, but I am talking about auto deployment to JBoss. Is it possible by pom.xml?
  • Mark Pope
    Mark Pope about 13 years
    Sorry, I misunderstood your question. Will edit my answer now
  • Tapas Bose
    Tapas Bose about 13 years
    I edited my question for giving more information about jboss-maven-plugin.
  • TrippLamb
    TrippLamb almost 11 years
    In juno 4-2 becomes select configure->convert to maven project. stackoverflow.com/questions/10362166/…
  • Mr_and_Mrs_D
    Mr_and_Mrs_D almost 10 years
    Select Export->WAR file: anyway I can do this via maven alone ?
  • Tapas Bose
    Tapas Bose almost 10 years
    @Mr_and_Mrs_D you can set target path of your maven build pointed to the server's deployment directory.
  • Mr_and_Mrs_D
    Mr_and_Mrs_D almost 10 years
    Thanks but that's not exactly portable I'm afraid - any other solution ?
  • Tapas Bose
    Tapas Bose almost 10 years
    @Mr_and_Mrs_D if you are using JBoss, please check if maven jboss plugin can help you.
  • Mr_and_Mrs_D
    Mr_and_Mrs_D almost 10 years
  • Mohammad Faisal
    Mohammad Faisal over 8 years
    how will it identify the server (if I have more than one)?