To have development environment with JBOSS and Eclipse, need to install JBOSS Tools.
Installing JBOSS Tools plugin
In Eclipse, Help -> Install New Software. In “Work With” box, give http://download.jboss.org/jbosstools/updates/development/mars/ Select ‘Abridged JBOSS Tools’. Click Next and Finish.
Setup JBOSS Server in Eclipse
In Eclipse Java EE perspective, right click on Server tab. New->Server. Select WildFly 9.x.
Click Next. In Java Runtime Home Directory, give JBOSS install directory (In my case, it is C:\tvi\Software\Installs\wildfly-9.0.2.Final).
Verify by accessing http://localhost:8180/ from browser.
Web App using Maven
Now, let us create a demo web app that will use deployment to JBOSS.
Maven Archetype
Use Maven webapp Archetype to create application structure/skeleton:
cd C:\tvi\Software\workspace_mars
mvn archetype:generate -DgroupId=com.techvalueinsight -DartifactId=JBossSetupDemoWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
Update web.xml
Update src\main\webapp\WEB-INF\web.xml to desired servlet version. In the below example, Servlet 3.1 and Java EE 7 XML Schema, namespace is used.
<web-app xmlns=”http://xmlns.jcp.org/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd”
version=”3.1″>
</web-app>
Update pom.xml
Update pom.xml to add servlet-api dependency:
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
Also add plugin specifying java version (as desired) inside <build>:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Create Folders
Create folders src/main/java, src/test/java and src/test/resources.
Import Maven project to Eclipse
cd C:\tvi\Software\workspace_mars\JBossSetupDemoWebApp
mvn eclipse:clean eclipse:eclipse
Open Eclipse with C:\tvi\Software\workspace_mars as workspace directory. File –> Import –> Existing Maven Projects. Root Directory C:\tvi\Software\workspace_mars. Select JBossSetupDemoWebApp
Note: If there are any changes are done to maven configuration after import to eclipse, right-click on the project in eclipse and select Maven -> Update Project.
Deploy web application to JBOSS
Start JBOSS server from eclipse. Right click Add the project JBossSetupDemoWebApp
http://localhost:8180/JBossSetupDemoWebApp (displays the index.jsp file that that got created by maven archetype)
Add Servlet
Let us add a sample servlet: File-> New –> Servlet
http://localhost:8180/JBossSetupDemoWebApp/DemoServlet
Create war file
To create a war file under target directory (to copy to another location etc.):
cd C:\tvi\Software\workspace_mars\JBossSetupDemoWebApp
mvn package
Accessing JBOSS Admin console
Need to add an user:
cd C:\tvi\Software\Installs\wildfly-9.0.2.Final\bin
.\add-user.bat
Type of user: Management User
Realm: ManagementRealm
Username: <user name of your choice>
Password: <password of your choice>
group : none
Access Admin console using: http://localhost:10090/console (port 9990 is the default. Due to the offset of 100 , it is 10090.
Click on Deployments to see deployed apps (JBossSetupDemoWebApp in this case).