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.
I found the solution and I am sharing as it might be helpful to someone.
My configuration is:
- Fedora 14
- Eclipse Helios for Java EE
- JBoss 4.2.0-GA
You also need to
- Install maven in your system
- Install m2eclipse plug-in in your Eclipse
Now you are ready to start to create project.
- Open Eclipse->Choose your Workspace
- Set-up server. To set-up server
- Got to Window->Show View->Servers
- Right click on server pane, select New->Server
- Select JBoss->JBoss v4.2 from the window opened
- Click Next
- Browse Application Server Directory, i.e., the location in your file system where JBoss resides.
- Click Finish
- Create a new Dynamic Web Project, to create the project
- Go to File->New->Project, select Dynamic Web Project under the Web node
- Click Next
- Give a project name
- Select JBoss v4.2 from Target runtime
- Click Next twice
- You will need web.xml so make sure "Generate web.xml deployment descriptor" is checked in the last page.
- Click Finish and Eclipse will create a Dynamic Web Project for you
- Now you need to enable Maven Dependency Management for created project. To do this
- Right click on the Project name
- Select Maven->Enable Dependency Management
- A window will be opened for POM creation
- Select war from Packaging drop-down menu
- Click Finish and your pom.xml will be created
- It will messed up your build path. To fix it
- Right click on the Project name and go to Properties
- Choose Java Build Path from the left pane
- Go to Libraries tab
- Edit JRE System Library. To edit system library
- Select JRE System Library and click Edit button in the right
- Choose Execution Environment JavaSE-1.6 from the drop-down menu
- Click Finish
- Go to Source tab
- Click Add Folder
- Select src
- Click Ok and your project is ready
- Now add some source files, configure web.xml and pom.xml and export it to JBoss server as WAR. To deploy it
- First copy all required jars to the lib folder in WEB-INF
- 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.
- Now right click on Project name
- Select Export->WAR file
- In Destination browse the path to your server
- 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.
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
The correct format is:
<fileName>${basedir}/target/webapp.war</fileName>
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.
Step 2:Create a new Maven Build
Step 3:Update build details as shown.
More option can be found at
https://docs.jboss.org/jbossas/7/plugins/maven/latest/examples/deployment-example.html
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
Go to Run --> Run Configurations..
Add new Maven Build
Name the Process, Select the Base directory that will be deployed as war
set the Goal --> jboss:start
By following the steps you can deploy every thing via Eclipse.
Have fun. :)
<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
Well http://cargo.codehaus.org/Maven2+plugin could be a nice alternative, too.
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
Use the following goals to deploy your war in Jboss folder
clean install jboss:hard-deploy