---
# System prepended metadata

title: Full Java Project Starter Notes
tags: [Starter, Java, Notes, CheatSheet]

---

###### tags: `CheatSheet` `Notes` `Java` `Starter` 

# Full Java Project Starter Notes
---
- - All imports are not included in the below code don't forget to import them

## Open Spring Suite
- Start workspace in the default folder where we save the project will be different

## If needed install the following first

### JSP
- Help -> Install New Software
- Start typing spring in the work with section and double click the Spring Tool Suite 4 - https......
- Scroll to bottom and click Web, XML 
- Follow prompts to install.
- Spring will need to restart let it

### Market Place Packages
- Help -> Eclipse Marketplase
- Search for packages you might use below are common ones

#### Packages
- Emmet - it will need a restart
    - then go to Preferences
    - Click on Emmet
    - Add jsp to the list of files

## Create Starter project
- Name - (PascalCase)
- Location - uncheck default and put it where you want it
- Type - Mavan
- Java Version - 8
- Packaging - War
- Language - Java
- Group com.codingdojo.(lowercase)
- Artifact - (PascalCase)
- Description - 
- Package - com.codingdojo.(lowercase)
![](https://i.imgur.com/dnHCm3n.png)
- Chose the Dependencies
![](https://i.imgur.com/1sOza2H.png)


## Add Dependencies to pom file
![](https://i.imgur.com/83wJHn5.png)


```
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>webjars-locator</artifactId>
    <version>0.30</version>
</dependency>

<!-- BOOTSTRAP DEPENDENCIES -->
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>bootstrap</artifactId>
    <version>5.0.1</version>
</dependency>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.6.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<!-- Bcrypt -->
<dependency>
    <groupId>org.mindrot</groupId>
    <artifactId>jbcrypt</artifactId>
    <version>0.4</version>
</dependency>
```

## Java Server Page folder (JSP files)
- Next create the folder for the pages
- src/main/webapp/WEB-INF
![](https://i.imgur.com/iAZOT3Q.png)


### The following gets added to all JSP files
- Create the 1st jsp file by right clicking choseing other, type jsp, then give it a name.  Recommend 1st one is template.jsp
```
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!-- for forms -->
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<!-- for validation -->
<%@ page isErrorPage="true" %>


<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap CSS -->
<!-- <link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css"> -->
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!-- My CSS -->
<link rel='stylesheet' href='/css/styles.css'>
<!-- JS for Bootstrap / jQuery -->
<script src='/webjars/jquery/jquery.min.js'></script>
<!-- <script src='/webjars/bootstrap/js/boostrap.min.js'></script> -->
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
<!-- My JS -->
<script type = "text/javascript" src='/js/scripts.js'></script>
<meta charset="UTF-8">
<title>Our Family Pets</title>
</head>
<body>
	<header>
		<h1>Testing</h1>
		<nav>
		
		</nav>
	</header>
	<main>
	
	</main>
	<footer>
	
	</footer>
</body>
</html>
```


## Update the application.properties file
- src/main/resources/application.properties
- right after or before finishing to edit this file be sure to manually create an empty database and insert that name here
```
spring.mvc.view.prefix=/WEB-INF/
spring.datasource.url=jdbc:mysql://localhost:3306/(schema_name_here)
spring.datasource.username=root
spring.datasource.password=rootroot
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.mvc.hiddenmethod.filter.enabled=true
```

## Static Folder
- src/main/resoures/static/css
    - put styles.css in here. 
- src/main/resoures/static/js
    - add scripts.js
- src/main/resources/static/images
    - Any images you want to have here






