How to use divided projects in Spring Boot - java

Welcome,
I'm begginer in Spring (also in Spring Boot). I create four maven projects in Eclipse:
my-persistance
my-presentation
my-webservices
my-main
I have assumed every part of program will be store in one of these special projects. For example: html, jsp files will be store in "my-presentation", also like Spring #Controller files. Projects that aren't "my-main" should be build earlier and store in local maven repository [via 'mvn clean install']to add them to "my-main" war package.
I just read one Spring Boot guide:
http://spring.io/guides/gs/serving-web-content/
It works when all elements are in one project. I want move Web Controller to "my-presentation" and class Application to "my-main". Of course it isn't working. Could it be possible to do this?

You can check how to work with Maven and multiple module.
Basically, you create parent pom.xml, and in each submodule (my-persistance, my-presentation, etc.) you create submodule pom.xml, that refer to parent pom.xml.
I have a similar configuration in my example project, you can check pom.xml files

Related

How to create a Spring MVC project in IntelliJIdea 2019.1?

When I create a Spring MVC project in IntelliJIdea 2019.1, There is no sub-checkbox Spring MVC in spring checkbox.
Have you tested how your project has been created with just Spring checkbox marked? I mean, Spring MVC almost always appears in Spring projects, so It maybe is already added. Take a look at you config files (pom.xml or gradle.build) for something like this:
https://mvnrepository.com/artifact/org.springframework/spring-webmvc/5.1.6.RELEASE
I would recommend you to use this page for creating a Spring project:
https://start.spring.io/
Or instead, use Spring Tools 4: https://spring.io/tools
Both are official released by Pivotal and make some configurations for you in your pom.xml, if using Maven, or in your gradle.build, if using Gradle. Also, both provide the basic project structure.
If you further want to add some dependency, you can go to the repository (most times Maven repository, even if dealing with Gradle project) and then add to your pom.xml or gradle.build file. This one works for me 90% of the times: https://mvnrepository.com/
Please make sure the corresponding Spring MVC plug-in is enabled.
You should get this option after enabling the plug-in and restarting the IDE.
Note that it's a legacy way of creating Spring projects in IntelliJ IDEA and it will use rather old Spring version, it's recommended to use the Spring Initializr instead. Web dependency is for MVC projects.

How to work with multiple sub-projects using IntelliJ, maven and spring-data-rest?

I have two projects based on Spring Framework that share some common code. The common code consists of the models and rest repositories.
I want to do split the projects so that I can manage the common code from a single location. I also want to be able to work on the common code (in IntelliJ ) when I develop features for one of the two projects, without the need to compile, upload to a maven repository or something like that.
From my understanding so far I need to use maven modules but I don't quite understand how they all fit together. I am also concerned about the entity scan annotations in spring
#EnableJpaRepositories(basePackages = "com.company.project1.repositories")
#EntityScan(basePackages = "com.company.project1.models")
I am worried that if I create a maven module, or a sub-project that will act as a library for the other two projects, Spring won't know how to pick up those repositories and models.
How can I split the two projects in three projects such that:
Any changes to the common project reflect automatically in both main projects
If I work on a main project and I need to change the common project, I can do that from IntelliJ without the need to open another project, edit, compile, push to a maven repository, etc
Spring picks up the rest repositories
It sounds like you would want to use this sort of maven structure:
features
common
feature-1
feature-2
where features is the top level maven project and the others are sub-modules, and feature-1 and feature-2 have a dependency on the jar produced by common.
I'm not familiar with IntelliJ so I'm assuming that IDE supports this type of structure. In Eclipse, when code changes in common, feature-1 and feature-2 can usually see it without having to do a maven build. Sometimes Eclipse doesn't recognize a change and a maven build is required to update the cache.

How to add and use one project in another project?

I have a project based on Spring which is running successfully. Now I have created another project based on Jersey which I want to integrate with spring project in Jersey.
I have gone through internet and I added spring project in the build-path of the Jersey project.
Here the problem is whenever I run my Jersey project, it has to execute the Spring project first.
How to configure spring project in Jersey?
You should consider using a dependency management/build tool such as Maven or Gradle.
This way each of your projects will be a module, which can be referenced from the other project as a dependency. You can still use the first project alone and the two-dependent projects alone as wall. Then the tool lets you just simply package the resulting project in a artifact such as WAR with all the dependencies.
Here is a quick maven tutorial - Maven in 5 Minutes
It is a good idea to use such a tool in any case as it has many additional advantages:
Lets you manage also your third party dependencies without needing to manually download the libraries and add them to the classpath
It is much easier to use such a project in cases like continuous integration.
You can run all your tests automatically during the build process to make sure everything works
It resolves transitive dependencies (dependencies of your dependencies)
It builds resulting archive file for you
You can have multiple profiles for different environments
...
Make both of your projects modules of one Maven parent pom project. This way you can build them both at the same time.

To create Java project with Spring persistence using Maven?

Is it good idea to create Java project with Spring persistence using Maven?
What maven archetype to use?
AppFuse is seemed to be freezed.
You an use Spring ROO to create a Spring project based on Maven.
The principle of a Maven archetype is to create a skeleton of an application based on some specificities (for example the usage of Spring in your case).
This skeleton will generate the root pom.xml, the basic directories structure (src/main/resources, src/main/java, and so on), as well as some other files, which are specific to the archetype used, such as the applicationContext.xml in the Spring case.
Of course, this is only a skeleton (which is however generally runnable to get some Hello World stuff), so you will have to adapt it to your precise requirements: change the pom.xml content (for example the versions of third libraries), add or remove some configuration files...
Maybe you can give a try to any AppFuse archetype (what do you mean by freezed by the way?), and then remove everything that is not needed in your case.
If you r using Netbeans 6.8 then follow below one
New Project->Maven->Maven PRoject->Default Archetype Catalog-> A simple J2EE Java application
Remove Other unused modules and modify it as per ur requirement...

JIBX MAVEN Problem

I am trying to use JIBX maven plugin in my Spring Web Service project,
My project has diferent layers (API-DAO-SERVICE vsvs..)
these layers are individual projects and has maven dependency each other.
In my WEB project's POM, I add other project as dependencies, and my mapping
classes are all in API project.
Even in my web project's POM includes dependencies of API project I could
not use that class'es in JIBX
BUT IF I put that class'es in WEB project's src/main/java directory there is
NO PROBLEM,
How can I use mapping classes that are other maven dependent projects.
Any help is really appreciated;
Thanks.
Generated sources are supposed to be compiled and packaged in the artifact at the end. The classes should thus be visible from your webapp.
Did you setup the maven-jixb-plugin as shown in Generate Java Sources from Schemas? If not, then maybe update your setup first and try again.
And if you are still facing problems, please show the relevant parts of your POM(s).

Categories

Resources