add a new component to java maven project - java

I have a maven project that contains many components. I need to add a new one called "Component" witch has one module like described in the list below:
Component
com.module
src
main
java
resources
META-INF
module
test
java
Thanks

When you need to add a new component as a maven module with many packages, maybe this would be a suitable approach. The module itself is then part of a multi module project (see Maven by Example):
Component [Name of the maven module]
src
main
java
com.module.a
com.module.b
...
resources
META-INF
module
test
java
resources

Related

Reuse a Spring-boot submodule in another non Spring project

I'm working on a multi module spring-boot project to build a REST API. Here is my project structure:
Parent project (packaging is pom)
core module (#SpringBootApplication + handle path like / or /status)
restControllerA module (Handle path like /routeA/*)
restControllerB module (Handle path like /routeB/*)
Everything is working in this project :)
In another non Spring project I would like to reuse a service of restControllerB. This service return the result of the request body validation.
First I try to add the restControllerB.jar as a dependency to this new project... But this jar does not contain its depedencies (who are in the fatJAR "core.jar"). When I run the project, I get a lot of ClassNotFoundException.
How can I manage to reuse this service as a dependency ? I thought to create a validator module which implements the validatorService interface, but I'm not sure if it is the best solution.
After few hours googling, It seems that creating an external librairy is the right choice. I create an external module and add it as a dependecy to restControllerB.

Maven Plugin: accessing resources accross multiple modules

I'm currently writing a custom maven plugin for generating a XML file in a multi-module maven project.
My maven structure is pretty standard: one parent project and a module by project components in the parent project folder:
-- Parent
-- module A
-- module B
-- module C
I need to list, by module, a set of classes flagged by a custom annotation.
I already wrote a set of custom annotations and an annocation processor to create a XML file at compile time in the corresponding module output directory (${project.build.outputDirectory}) .
Now i need to merge each module XML into one file, but i don't know how to access each modules from within my maven plugin except having each path set as parameters (i don't like this method).
Any idea on how to do this ?
Does maven plugins can traverse project modules ?
Thank you in advance.
To get the list list of all projects you can use:
List<MavenProject> projectList = MavenSession.getProjectDependencyGraph().getSortedProjects()
If one of your goals is correctly executed you will get everything you need. Every MavenProject contains a getBaseDir() etc.
After some researches, it seems that MavenProject.getCollectedProjects() will return the list of projects beeing manipulated by a goal execution in a multi-module project.

Class not found in project sources or resources GWT

I'm building GWT application with Maven. My application uses some custom UI forms instead of standard ones. I have files with custom UI forms, packed in .jar file.
My .ui.xml file has this:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:nc='custompackage.gwt.fields.client.widgets.reference'
>
...
<nc:UIReferenceField width="100%" text = "123" nc:field="rf"/>
...
My module .gwt.xml file inherits custom class:
...
<inherits name="custompackage.gwt.fields.Fields"/>
...
When I build Maven module I get:
Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.6.0:compile (default)
on project geographical-view-for-osp-gwt-2: GWT Module
com.netcracker.platform.ui.toolkit.gwt.i18n.i18n not found in project sources or resources.
I've looked into similar problem questions, but their resolution didn't help me at all. Can you help me?
P.S.: My module builds fine without custom fields.
I didnt add some dependencies to my .pom file. My inherited module depended on them and it didnt compile.

Put resources in a modular project maven

I split my java web application in a few modules. I have five modules: model, services, util, rest and web-app. Now each of these modules use resources, for example in the web-app module there are a few images, in the service module there are a jasper files ....
I want to ask you what is the best place to put these resources? I saw a few plugin like maven-shared-resources
maven-shared-resources
Is this a used strategy to manage different kind of resources in a maven modular project?
I ask you this why I'm not able not get a few resources from a model
I use a few resource contained in the util module for the login . My trouble is that when i call the class contained also it in the util module from the web-app module i get a FileNotFoundException why it try to get a resource from the util-module.jar.
I use the following line code to try to get a resource
InputStream inStr = getClass().getResourceAsStream( "/myFile.jks");

Maven Assembly: config files best practice

I have a multi-module maven project, including a seperate assembly-project. As i develop and run my application from eclipse (during development), i have specific configuration-files (e.g. log4j or other property-files) in my main-module (which contains the main-class). These files contain development-time-specific information. The assembly-project contains each of the config-files for production. The assembled product then should use these configs instead. This is my current setup:
MainModule/src/main/resources
+configA.properties
+log4j.properties
Module1/src/main/resources
+configB.properties
AssemblyProj/src/main/resources
+configA.properties
+configB.properties
+log4j.properties
And the generated project has this structure:
libs/
+MainModule.jar
+Module1.jar
configs/
+configA.properties
+configB.properties
+log4j.properties
the config-directory overlays the config-files in each *.jar because of the classpath, i.e.
java -cp configs/;libs/* My.Main.Class
Now the problem that i have, is that there are still all dev-configs included in each jar. Also i have kind of a bad feeling about using that overlay-classpath-method. Is there any practice on how to do this in a better manner?
Extract these resources into classifier-based dependencies for each of the mentioned modules. Then define <profiles/> that trigger their usage. In your assembly use the classifiers as necessary.

Categories