Skip to content

Maven archetype that allows quick creation and deployment of a webapp with a TomEE server and a MySQL database.

Notifications You must be signed in to change notification settings

thibseisel/tomee-webapp-archetype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tomee-webapp-archetype

Maven archetype that allows quick creation and deployment of a webapp with a TomEE server and a MySQL database. In addition to the server-side sample code, this archetype also setups the development environment of an Angular 4.0 front-end project.

Prerequisites

  • Maven
  • Docker
  • NodeJS v6.9.0 or newer

Note that if you're using Windows, you need to install a virtualization tool such as VirtualBox to run Docker in a Linux virtual machine.

Using this archetype

Clone this repository and copy this Maven archetype to your local repository, located under homedir/.m2/repository.

cd tomee-webapp-archetype  
mvn install

You can now generate a new project using this archetype.

mvn archetype:generate -DarchetypeGroupId=fr.nihilus -DarchetypeArtifactId=tomee-webapp-archetype

You will be prompted to specify your groupId, artifactId, version and package name. Before accepting the setup by typing Y, check that the value of the following properties are correct :

  • dbName : the name you want to give to your MySQL database
  • dbUser : the name of your MySQL user. This will be used by your application to connect via JPA.
  • dbPassword : the password for your user.
  • dbRootPassword : the password for the root user.

If not, type N and set their value to match your expectations.

Your project is now fully generated !

Running the generated project

Windows

Copy the content of the folder docker/DEV of your generated project to your Linux virtual machine. In order to do that, you can use WinSCP or type the following command in a Git Bash :

scp -r docker/DEV/* username@localhost:~

Where username is the name of your user in virtual machine.

When done, create the MySQL and TomEE docker images with the provided scripts.

./build-images.sh  
./run-images.sh  

Check that TomEE is working correctly by opening your browser with the following url address : http://localhost:8080. You can now build the Angular part of this sample project and then upload the whole project to the running TomEE container. Navigate to the root folder of the project and run those commands :

cd angular  
npm install  
npm run build  
cd ..  
mvn tomcat7:deploy

Finally, open a browser at http://localhost:8080/myapp, where myapp is the artifactId you gave when generating your project. If a success message appear, then your project and development environment are now all set !

Linux

You don't have to install a virtual machine to run Docker. Navigate to the docker/DEV directory of your generated project., and run the following scripts to create your MySQL and TomEE docker images :

./build-images.sh  
./run-images.sh  

Check that TomEE is working correctly by navigating to the following url address : http://localhost:8080. You can now build the Angular part of this sample project and then upload the whole project to the running TomEE container. Navigate to the root folder of the project and run those commands :

cd angular  
npm run build  
cd ..  
mvn tomcat7:deploy

Finally, open a browser at http://localhost:8080/myapp, where myapp is the artifactId you gave when generating your project. If a success message appear, then your project and development environment are now all set !

Generated directory structure

The generated project follows the Maven standard directory structure.

.
+-- _angular
+-- _docker
+--	_src
	+-- _main
		+-- _java
		+-- _resources
		+-- _webapp
	+-- _test
		+-- java	
  • The src/main/java folder contains the code for your Java server application
  • The src/main/resources folder mainly contains configuration files (in our case, persistence.xml)
  • The src/main/webapp folder is where you put your HTML and Javascript client code
  • The src/test/java folder replicates the src/main/java package structure and contains all unit tests
  • The angular folder contains an Angular project generated with @angular/cli

In this project, there's an additional docker folder containing script you used to setup your development environment.

Sample code

The generated project features an example of a working RESTful application allowing to store and retrieve books. Note that it only accepts JSON. You can issue the following requests :

  • GET /api/books to get the list of all books from the database,
  • GET /api/books/{id} to get a specific book by its id,
  • POST /api/books to add a new book to the database (body must feature and object with a property "title"),
  • PUT /api/books/{id} to update an existing book (body must feature and object with a property "title"),
  • DELETE /api/books/{id} to delete an existing book.

You are free to modify or delete this code to replace it with your own application logic.

About

Maven archetype that allows quick creation and deployment of a webapp with a TomEE server and a MySQL database.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published