Spring + Hibernate + Angular + Maven + Tomcat Project folder structure issues - angularjs

Okay, so I have been trying all day to sort this out. My boss has assigned me a new task: Take this template: https://github.com/DavidKk/ngAdmin , figure out how AngularJS works, figure out how Spring works, how does Hibernate work, how does Maven work for project builds, tests etc, implement a basic CRUD example inside that template on a MySQL database, deploy on Tomcat.
So, first, this is a lot of stuff all at once, stuff that I have not ever worked with, maybe with Hibernate and a bit with JPA, and he wants all this stuff sorted out by the end of the week, when we will talk more about the project with the client, so we can tell him what approach we will take on the development process.
I took a look at Spring, used Spring Initializr: https://start.spring.io/ to make a basic project, used the jar command tool to make a WAR file, deployed it on tomcat, and it worked. I have used these two, because IntelliJ Commuity has none of these implemented, unless you pay for the Ultimate edition.
I took a look at this CRUD example: http://www.concretepage.com/spring-4/spring-mvc-4-rest-angularjs-hibernate-4-integration-crud-tutorial-with-ngresource-example , and made it work, and understood how Spring uses dependency injection, how Hibernate persists objects into the database, and how AngularJS provides the single-page layout that my client has asked for.
Now, my problem is, this template has a whole different directory structure, and if I move files around nothing is going to work. Starting everything from scratch is not an option, we take a front end template, modify it a little bit, develop the back-end stuff for client and server. What I do not understand is how I could ever use this with Spring, which has a whole different directory structure, or with Tomcat, which expects different stuff too, or it will throw me a 404. From what I have seen, this project has been built with Grunt, so I do not know if there is any way to go from Grunt to Maven, and have it still work. I don't really know what to do, and I must finish this by the end of the week. Any help would be appreciated, thanks.

The template you show is only for the front-end.
Create a project with spring initializer.
You'll have {directory}/src/main/java and other stuff.
Create {directory}/client/
Put the ngAdmin stuff in it.
ngAdmin uses grunt to build the client, and generate the site in the dest directory. This will be {directory}/client/dest/
Configure maven-frontend-plugin to install js stuff and run grunt when building with maven.
Add maven-resource-plugin configuration to copy from {directory}/client/dest/ to ${project.build.directory}/client
Configure maven war plugin to include this directory
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<webResources>
<resource>
<directory>${project.build.directory}/client</directory>
</resource>
</webResources>
</configuration>
</plugin>
This way, when you build the war, the client should be in it (unzip the war and check)
Then you will have some config to tell spring-mvc where exactly to find those, but I don't have that on hand.
Hope this help.

Related

Ktor + React project configuration

I'm trying to start my first web project. My experience is with .NET desktop development and I'm very new to the Java/Kotlin world. Client side I want to use React and write the code in Kotlin, then transpile to JavaScript. Server side I would like to use Ktor both to serve the static content (React app + various assets) and REST endpoints for the SPA. I would like to use the Multiplatform feature to be able to share as much code as possible. My IDE is IntelliJ IDEA.
I would like to have auto-reload and be able to debug both React and server code for development and I would like to be able to create a single fat jar with the complete application (frontend+backend).
I started with the template that IntelliJ provides for multiplatform JS+JVM. I have been working on it for more than one day with little success and also haven't been able to find any sample online with all the features, and also haven't been able to combine various samples due to insufficient knowledge. Only thing I got is either running the application without autoreload or creating the jar file by adding "manifest" to the build.gradle file which breaks my run configuration.
I would very much appreciate if someone could provide or point me to an example with these features which I can use as an starting point for my application.
Here is a link to an example to get you started.
https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform/01_Introduction

Structuring frontend and backend (AngularJS, Slim)

Questions: What is the correct / proper structure of Frontend and Backend together? How do I publish whole project after It's done? Will it just work if I copy it all to some host? (I know I have to modify DB paths and stuff, I'm worried about all the updating that composer does.. or am I understanding it all wrong)?
Short explanation of how I got here: I'm a student developing a Time management web application (Projects, Tasks..). I have knowledge of PHP (Slim), JS (JQuery, Angular), HTML, CSS (Bootstrap), SQL. My development flow was first creating a database and setting up an Apache server (Linux). After that I started coding by simply creating a folder, adding sub-folders for backend (DB operations..) and frontend (js, css, view, images...) when I needed them. All the includes were downloaded when I needed them (jquery, bootstrap etc.). I never used composer/ npm /bower.. Which brings me to this:
Current situation: I was about to upgrade form Slim 2 to Slim 3. In the last 6 hours of googling I've completely lost motivation and at the moment I feel like I have no idea what I'm doing. Almost every article/tutorial I read gives me different information: Composer? Bower? npm? Yo?... I feel like I'm doing it all wrong. I tried few of those seeds that create a clean project for you.. WHAT ARE ALL THOSE FILES. I even tried one that creates clean structure of Angular and Slim in one project. Needlessly to say I'm completely lost. I feel like I did all those 100 hours of coding while I should be studying for nothing, since i have no idea how to properly use it.
I'd really appreciate any tip, suggestion, links to stuff that'll help. I feel like all the knowledge of coding I have is just useless since I have no idea how to use it properly. Thank you
This is very simple to work with composer and npm for Slim3 and Angular2
both are different files and main folders
For Slim you will use composer to download all files in vendor folder
For Angular you will use npm to install all files in node_modules
folder
Even the required file is different composer.json for slim and package.json for Angular.
I use Slim with Angular 4 now inaa project and every thing is going smoothly
I don't know what kind of problems you faced, but I'm sure both can work together

What is the best practice to make components created by JHipster available to other projects?

I'm exploring JHipster, the Spring Boot + AngularJS application generator based on Yeoman.
So far, it's been quite interesting and fun. I've been able to get a vanilla webapp up and running without too much trouble.
Now I want to take a step further, moving the entities, repositories, and services away from the original webapp project.
The webapp project generated by JHipster declares spring-boot-parent as its parent project:
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.3.1.RELEASE</version>
<relativePath />
</parent>
So I changed it to my own parent project, which looks something like:
<parent>
<groupId>br.net.neuromancer.bigpolis</groupId>
<artifactId>bigpolis-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Immediately, I was swamped with Maven build exceptions. :(
I then followed the steps described on Spring Boot - parent pom when you already have a parent pom
I could get to the point where the project builds ok, but errors still showed up while running mvn spring:boot. I was just getting too much trouble for little gain, so I decided to rollback the changes.
Instead I declared spring-boot-parent as the parent of my own parent.
Though this strategy seems to work both for building and running, now I have two major questions.
First, what are the implications of declaring spring-boot-parent as the main parent for all my sub-projects ? Not that I dislike the idea so much, since most (if not all) of the sub-projects do depend on Spring Boot anyway.
But are there any side effects to this strategy that I should be aware?
The second question regards JHipster more closely.
What would be the best practices to make certain components available to non-JHipster projects? Entities, repositories, and services seldom belong exclusively to the webapp, and should be shared with other non-frontend components.
Could I move them to a separate project, perhaps losing the refactoring functionality provided by Yeoman?
Or should I declare the JHipster project as a regular dependency, just letting all the Angular stuff gets packed along the WAR? Somehow that doesn't seem too efficient.
Any pointers, thoughts or comments on what I've just described will be really appreciated. Thanks for reading this far... :)
Follow up a few days later...
I'd like to apologize for asking unrelated questions in the same post. Making JHipster modules available elsewhere is a topic which deserves a post of its own.
That said, here is some follow-up about the Maven parenting issue.
I finally decided against making spring-boot-starter-parent the parent of my own parent:
I prefer to avoid the introduction of too many unnecessary dependencies to other modules, which might rightfully not even care about spring-boot-starter at all.
So I rolled back the earlier changes, then ran the Maven dependency:resolve target to get a list of transitive dependencies for the original setup.
I then added this section to my JHipster pom.xml:
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
I had to explicitly declare missing version tags, until the builds within and outside Eclipse were happy.
Only then I ran again mvn dependency:resolution.
The comparison with the previous transitive dependencies list gave me good hints on the causes for errors I was getting on my first attempt.
I patiently fixed each mismatch, declaring variables and dependencies on my POM, until I had exactly the same versions for all dependencies on both setups.
After this manual labor, I was able to get the spring-boot:run target alive again. :)
Contrary to what was stated elsewhere, I did not have to re-configure plugins. But I guess it was only my good luck. I can see why the advice stands.
The downside is that the new POM ended up much larger (and more complex) than before.
https://github.com/javayuga/BigPolis/blob/master/bigpolis-parent/tserd14Browser/pom.xml
I'm pretty sure I can still do more cleanup, but results are enough to let me move on.
I'd like to thank everyone who responded, giving me some food for thought. :)
As for your first question, are all of your creations going to be Spring-Boot projects? That defines whether the parent needs to be Spring-Boot. The parent is there to save you the trouble of specifying dependencies.
Your second question is about unknown side-effects. If you specify the parent, you should look at it and understand it.
For your third question, it sounds like you need to learn how to create your own generators. I'm doing about the same thing as you. I first created a JHipster app to learn on. I've created a bunch now. I have one I delete and re-create, hack, overwrite, etc. called "goof". Every time I want to test something, I mkdir goof, cd goof, and yo jhipster. I have already written a Mule component (REST client) that talks to the API that's described in the Swagger API rendering using the admin login. I'm going to make a stripped down JHipster that's loses all the Angular stuff and only hosts the API. But, it won't be JHipster anymore, it will be my thing. I'm going to learn how to create a Yeoman generator and it will be my creation not JHipster's. Use JHipster because it's there, do your thing (using Spring-Boot parent if needed) but make your own generator for each thing you make. It sound's like you want your own generator to me. JHipster is complex and it's open source. Hack it up and learn from it. But go learn more about Yeoman generators.
Question1: Well it really depends. If you keep as your main parent, spring-boot-parent that means that all your sub-module will inherit from it. So is this OK? Is there any case that a submodule is not spring related at all? You need to think about that cases. If they are all spring related, most probably you will be alright, and I am saying most probably since this particular parent even in spring related projects- might fit 100% where you might need to do something very specific (corner cases). The cleanest solution would be to import this parent as 'BOM' as the previous topic suggests. The reason that does not work is that you need to configure the plugins on your own.

Nice Git architecture for server / client?

I'm about to start a pretty huge project.
This project is a website.
The backend will be made with Node
The frontend will be made mostly with Angular
Backend is going to be an API (which is cool with Angular) but also (later) for an Android app.
Frontend is going to be a fork of this repo : https://github.com/maxime1992/webTemplate and I want to be able to pull from upstream to keep the fork up to date.
I am wondering. How should I manage it?
Should I create only one repo, containing back and frontend with Git submodule or subtree.
Should I create two separated repos, one for the frontend, one for the backend and then use symlink to have them together? But if someone wants to run it on Windows ... Too bad.
I want this project to be open source on GitHub so I would like to have something clear and easy for everyone :)
Tell me how you would do it, what's good, what's wrong ... I'm really curious!
As indicated in the comments, Git submodules (or Git subtrees) are not the right solution for this. Use a dependency management tool for this, which will work cross-platform (Linux, Mac, Windows), and is the standard way of doing this.
Separating your backend and frontend into separate projects is a good idea, as it will allow you to manage projects independently and add functionality or additional client applications later without bloating your application.
Since you're already using Angular for the frontend, I suggest you take a look at Bower, which is the de-facto standard dependency management tool for frontend projects. It allows you to define a bower.json file to define your dependencies, e.g. Angular and other frontend libraries, allowing you to assemble your frontend project without having to download and store libraries manually.
In your backend project, you would then also add a bower.json file which declares your frontend project as a dependency by pointing to its Git location and branch. Bower will then take care of downloading your frontend project and adding it into your backend project.
Check out some of the popular Bower tutorials for more info on this...
You can use bower link to automatically create symlinks between your projects - this will work across operating systems as well.
Some other tools that you might want to check out:
Yeoman for scaffolding a base project. There are some nice generators for scaffolding Angular projects, including things like LESS/SASS and Bootstrap (https://github.com/yeoman/generator-angular)
Wiredep for automatically wiring your Bower dependencies into your index.html file.
Getting your initial project setup right will be important. You can start small and grow things to a more advanced configuration later.

How do I configure Setup And Deployment Project to use transformed app config?

I've been using SlowCheetah to transform my app.config files and this part is all working fine. The correct transforms are applied to AppName.exe.config when I build the windows client application.
The problem I have is that the S&D Project always looks for app.config which obviously does not contain the updated values.
How can I configure the S&D project to look for AppName.exe.config and package that instead?
After some lengthy research it seems this is not possible when building an MSI using VS 2010 Setup & Deployment.
It may be possible to do with MSBUILD as this is more powerful and flexible but I currently don't have the time to explore that avenue in detail.
So for the time being as a temporary workaround I have entered the values in app.config for the production environment as this is what the MSI will use.
My transforms are still in place for other environments. But seeing as I don't deploy to other environments with MSI it doesn't really matter.
At some stage I will sort this all out with a build server and CI.
Hope this helps someone, someday.

Resources