Build a Java App with Maven On FreeBSD

In this article, we will create a simple web application to manage Java web projects. You can create a java web application using the maven-archetype-webapp plugin. We can create using IDE tools as well as command line console. In the end, we will create a Spring MVC web application, displaying the current date on a JSP page.

1. FreeBSD Prerequisites

OS: FreeBSD 13.2 or later
Hostname: ns7
IP Server:
Java Version: openjdk version "17.0.9" 2023-10-17
Mvaen version: Apache Maven 3.9.6

2. Create a Java Project With Maven

As a first step, we will create a Java project, namely a Web App, using the Maven template. Run the command below to create a web project from the Maven template maven-archetype. We will place the Java Web App project in the "/var" folder
root@ns7:~ # cd /var
root@ns7:/var # mvn archetype:generate -DgroupId=site.unixwinbsd.blogapp -DartifactId=blogapp_project -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
root@ns7:/var # cd blogapp_project
The above command will create the Generated Web Project directory structure.

The web.xml, index.jsp and pom.xml files are project specific files generated by the Maven command line, these files you can change as needed.

Please open the pom.xml file. delete the script and replace it with the script below.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

    <name>java-web-project Maven Webapp</name>

        <!-- -->




        <!-- logging , spring 5 no more bridge, thanks spring-jcl -->

        <!-- junit 5, unit test -->

        <!-- unit test -->

        <!-- for web servlet -->

        <!-- Some containers like Tomcat don't have jstl library -->

            <!-- -->

            <!-- Default is too old, update to latest to run the latest Spring 5 + jUnit 5 -->

            <!-- Default 2.2 is too old, update to latest -->



In your Maven project create a Java folder, with the following command.
root@ns7:~ # cd /var/blogapp_project/src/main
root@ns7:/var/blogapp_project/src/main # mkdir -p java/site/unixwinbsd/blogapp
root@ns7:/var/blogapp_project/src/main # cd java/site/unixwinbsd/blogapp
root@ns7:/var/blogapp_project/src/main/java/site/unixwinbsd/blogapp # mkdir -p config
root@ns7:/var/blogapp_project/src/main/java/site/unixwinbsd/blogapp # mkdir -p controller
Create a Web App file in the Maven project we are creating:
  1. /var/blogapp_project/src/main/java/site/unixwinbsd/blogapp/
  2. /var/blogapp_project/src/main/java/site/unixwinbsd/blogapp/config/
  3. /var/blogapp_project/src/main/java/site/unixwinbsd/blogapp/controller/
root@ns7:/var/blogapp_project/src/main/java/site/unixwinbsd/blogapp # touch /var/blogapp_project/src/main/java/site/unixwinbsd/blogapp/
root@ns7:/var/blogapp_project/src/main/java/site/unixwinbsd/blogapp # touch /var/blogapp_project/src/main/java/site/unixwinbsd/blogapp/config/
root@ns7:/var/blogapp_project/src/main/java/site/unixwinbsd/blogapp # touch /var/blogapp_project/src/main/java/site/unixwinbsd/blogapp/controller/
Then create a "views" folder.
root@ns7:/var/blogapp_project/src/main/java/site/unixwinbsd/blogapp # cd /var/blogapp_project/src/main/webapp/WEB-INF
root@ns7:/var/blogapp_project/src/main/webapp/WEB-INF # mkdir -p views
Delete the "web.xml" file and move the "index.jsp" file.
root@ns7:/var/blogapp_project/src/main/webapp/WEB-INF # rm web.xml
root@ns7:/var/blogapp_project/src/main/webapp/WEB-INF # cd /var/blogapp_project/src/main/webapp
root@ns7:/var/blogapp_project/src/main/webapp # mv index.jsp WEB-INF/views
Create a Log file to the console.
root@ns7:/var/blogapp_project/src/main/webapp # cd /var/blogapp_project/src/main/resources
root@ns7:/var/blogapp_project/src/main/resources # touch logback.xml
After that we create a "test" folder.
root@ns7:/var/blogapp_project/src/main/resources # cd /var/blogapp_project/src
root@ns7:/var/blogapp_project/src # mkdir -p test/java/site/unixwinbsd/blogapp
The next step, create a "" file.
root@ns7:/var/blogapp_project/src # cd test/java/site/unixwinbsd/blogapp
root@ns7:/var/blogapp_project/src/test/java/site/unixwinbsd/blogapp # touch
You can download all the script contents from this file on Github:

After you download the script from Github, insert the script into each appropriate file. The final job is to compile the Maven project, with the commands mvn compile, mvn package and mvn install
root@ns7:/var/blogapp_project/src/test/java/site/unixwinbsd/blogapp # cd /var/blogapp_project
root@ns7:/var/blogapp_project # mvn compile && mvn package && mvn install
Run your Maven project.
root@ns7:/var/blogapp_project # mvn jetty:run
To see the results, access via http://localhost:8080/ via Google web browser.

In this article, we have learned how to create a simple maven based web application with FreeBSD server and we have run this web application in a Servlet container called jetty.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post