Question

In: Computer Science

Using Maven and Web Programming Basics 1. Build a program using maven 75 pts A. Create...

Using Maven and Web Programming Basics

1. Build a program using maven 75 pts

A. Create file structure

Create a file structure for your program like the following:

web_app
→ src
→ main
→ java
→ resources
→ webapp
→ target

make sure you have in src/main/ the directories java, resources, and webapp.

In most Java IDEs (Eclipse, IntelliJ, etc.) you can make a maven project, which will have this structure by default (without the webapp directory), you can use that IDE tools then add the webapp directory.

B. Make pom.xml

Apache maven is a build automation tool that can compile and build your program as well as download any .jar dependencies you need. I’ll provide you with a pom.xml file with the parameters set to download the .jar files you need to make a web server in java. Put this file at the top level of your program file structure (same level as the the src and target directories). To verify you examined the file, change the value in the <name> tag from YOUR_WEB_APP to the name of your program. You can see all the jar files that are needed in <dependencies> and where the program is named in

<build>
<plugin>

<programs>

<program>

the file that sets up the tomcat program is in webDriver.Main (which I will describe later) and the program name is web (if you are doing the extra credit don’t change this)

C. Add tomcat driver

For this program we’ll be using the Apache Tomcat web framework (another popular one for java is Glassfish). In IDE you can use the Web Application projects to form your web program, but for this class I want you to build the web app driver so you can more easily publish your software and so you can see what is need to make a java web server.

To start make a package in src/main/java called webDriver (same as the name above), then add the provided Main.java file into that package (web_app/src/main/java/webDriver). If you see errors in your IDE your package names do not match (package webDriver) or you set up the pom.xml file incorrectly. Otherwise it should not have any errors. This class when run talks to the operating system to make your computer into a web server.

D. Create web.xml file

To help out your web server with some piping of traffic you need to setup a web.xml file. In your src/main/webapp directory create a folder called WEB-INF. In there put the provided web.xml file. This file helps direct traffic for the server, but it’s really simple for this homework, but we’ll build on it, in later assignments. To verify you have looked at the file, change the <display-name> value in the file, to your program name. The <welcome-file-list> gives the search order for the server’s default landing page.

E. Generate index.html

Finally you should have a working server to check if it works put an index.html page in src/main/webapp. I provided one, but you can put your own one in there.

To test if everything work, you’ll need to build the maven package. For windows users, open powershell or cmd, osX users open console, and terminal for Linux users, navigate to your project and type
mvn package

you should get a bunch of messages where the last five lines are similar to:

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 1.862 s

[INFO] Finished at: 2020-01-12T13:01:55-07:00

[INFO] ------------------------------------------------------------------------

Solutions

Expert Solution

Here is my solution:

I have build it in eclipse with maven plugin installed.

pom.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.proj</groupId>
  <artifactId>gontu</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>gontu 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>
    
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>
    
   <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>
   
   <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>
   
   <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>
   
   <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>
   
   
  </dependencies>
  <build>
    <finalName>gontu</finalName>
  </build>
</project>

index.jsp

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

build success screenshot:

You can build your project on this setup.


Related Solutions

Programming assignment (75 pts): The Lab 1 development assignment was largely an exercise in completing an...
Programming assignment (75 pts): The Lab 1 development assignment was largely an exercise in completing an already started implementation. The Lab 2 development assignment will call on you to implement a program from scratch. It’s an exercise in learning more about Java basics, core Java Classes and Class/ method-level modularity. Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented. NumericAnalyzer will accept a list of 1 or more numbers as command line arguments. These numeric...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts...
USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts from multiple classrooms to accumulate total cookie sales.   Once all receipts have been processed, the program must show what classroom is won and the total amount of cookies they sold. The classrooms that are participating are from the:                 2nd Floor: 201, 202, 203, 204, 205, 206, 207, 208                 3rd Floor: 301,302, 303, 304, 305, 306, 307, 308, 309                 4th Floor: 401,...
Assembly Language Programming Exercise. Problem # 1: 1. Integer Expression Calculation( 5 pts ) Using the...
Assembly Language Programming Exercise. Problem # 1: 1. Integer Expression Calculation( 5 pts ) Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) − (C + D). Assign integer values to the EAX, EBX, ECX, and EDX registers.
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any of the following: • Your hobbies, likes/dislikes, career aspirations, dream job, favorite animals/ pets, favorite superhero, etc. • You do not have to share personal information that you are uncomfortable with sharing. Follow these guidelines when creating your page: • Include at least one heading (h1, h2, etc.) in your web page. • Provide a quote from a book, movie, etc. • Include at...
C PROGRAMMING Build a hotel management program. The user will register their name and put their...
C PROGRAMMING Build a hotel management program. The user will register their name and put their check-in time and check-out time. They can choose their type of room they stay (Deluxe room, junior suite room, suite room, presidential suite room). Then, the program will determine the total price. *NOTE - Using modular, user-friendly, and array usage programming. Please don't use struct/structure and pointer. - Please give explanation about the code.
Project 1 - OO Programming Create a program that simulates cars racing and allows users to...
Project 1 - OO Programming Create a program that simulates cars racing and allows users to bet on the races ( start users with $100 ) In main, prompt the user to enter details needed to create 2 instances of the Car class you create. Ask the user to bet on which car will win the race ( use the overridden << method to display car details ), ensure the bet is between 1 and the amount of money the...
Create a web page using PHP that allows the users to create an account (a username...
Create a web page using PHP that allows the users to create an account (a username and a password). There should be a login page that allows users to create an account by entering their preferred username and password. The same page should also let users login if they already have an account. If a user is logged in successfully , they should be able to enter a comment and also read the comments entered by others previously.
JAVA PROGRAMMING 1)BuildLists: Write a program to create an ArrayList<Integer>. Fill it with numbers from 1...
JAVA PROGRAMMING 1)BuildLists: Write a program to create an ArrayList<Integer>. Fill it with numbers from 1 to 1000. Then remove every even number. Then remove every multiple of 3 remaining Then remove every multiple of 5 Then remove every multiple of 7 Then sum the array, and print.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT