create Maven project in Jenkins and deploy to Jboss

  1. in Jenkins select create new item, give name as "java-web-project", type as "Maven Project". Keep all default value, only add "wildfly:deploy" in "Build => Goals and options" then apply and save.
  2. in /var/lib/jenkins/workspace/, run maven command to create webapp:
    mvn archetype:generate -DgroupId=com.pythondesign.web -DartifactId=java-web-project -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
    you will get files:

    
    (base) ubuntu@ubunu2004:/var/lib/jenkins/workspace/java-web-project$ tree
    .
    ├── pom.xml
    ├── src
    │   └── main
    │       ├── resources
    │       └── webapp
    │           ├── index.jsp
    │           └── WEB-INF
    │               └── web.xml
3. update pom.xml as below:
```xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mkyong.web</groupId>
  <artifactId>java-web-project</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>java-web-project Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>java-web-project</finalName>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
         <plugins>
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>2.1.0.Beta1</version>
            <configuration>
                <hostname>localhost</hostname>
                <port>9990</port>
                <username>admin</username>
                <password>pas8word@</password>
            </configuration>
        </plugin>
         </plugins>
        </pluginManagement>
  </build>
</project>
  1. you can test it with command:
    mvn package
    mvn wildfly:deploy
  2. now we can click "Build Now" in Jenkins, check the console, you will get:
    BUILD SUCCESS! and verify the webapp on jboss:
    http://192.168.0.43:8090/java-web-project/index.jsp

Leave a Reply

Your email address will not be published. Required fields are marked *