How to test multiple maven project? - maven

I have created multiple maven modules (e.g.: entity, service, repository, facade) , those jar contain all my business logic and I will package them as jar. Then I create a projectA which will depend on all jar file and package as war file. Everything is okay, but question is : How to test my individual jar component as there is not persistence.mxl in jar. PThe persistence.xml is only located in projectA. Please help...

Related

can we build controller and model classes into seperate jar file and add that jar file as a dependency to another project

Normally in our spring MVC projects, we have atleast config, model, controller packages.my problem is can we build these model and controller directories separately as a jar file and add the resulted jar file to any another project.so that we can get rid of some coding and simplify it
Can we use #ComponantScan annotation to make it work
For this you can use Maven .(
If you are not familiar wtih maven read this , its quite simple- https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html )
Follow below steps
Create a Maven main project with packaging pom in pom.xml file
Then create a maven module for this main project with packaging
JAR where your model is placed.
Create another module with packaging war and add dependency of
module we have created in second step to this project.
Now you build the war project module and jar of first module will automatically added into war
For the component scan question , while creating the different maven modules keep a common structure for packages
For example , You can use com.app as base package name and scan this com.app for beans using componentscan. packages in maven modules could be like this com.app.controller, com.app.model etc
Yes you can add the jar files to another project. You just need to add the jar files in the classpath. First create the jar file of the required package with help of eclipse export option:
Right click on the package and select export.
Go to Java and select JAR file
Give a name to your jar file and continue to click next until the jar is created.
Then make a new folder under the other project in eclipse. Copy and paste that jar file in this folder. Right click on that jar file -> Build Path -> Add to build path. Now you should be able to use those controllers. Just give the correct full package name that you have exported in the #ComponantScan annotation. Let me know if any issue.

Gradle gather all jar dependencies in multi project and build a ear

I am pretty new to gradle and I am trying to achieve the following
I have setup a multi project build, with the following structure
root:
:commonjar (java-library)
:war1 (war)
:war2 (war)
:externaljars (local repository for unmanaged jars)
:libs (ear)
I would like to automatically gather all runtime dependencies for commonjar, war1 and war2 and generate a deployable ear (libs) where all jars are stored inside libs.ear/lib
I have kind found a way to gather all jar using taks definition like this:
task copyDeps(type: Copy) {
from(subprojects.configurations.runtime)
into project.file(libDirName)
}
But no matter where I store the jars, the get not picked up by the "ear" task.
Just to explain, I need to make a dummy ear, with only jars to do remote deployment and create shared library definitions on IBM Websphere application server.
Any good suggestion to have an ear gather and package all jars (transitive as well) used in the entire project?
Thanks
You can simply configure the ear task to include the dependencies you want to have in there with something like
ear {
duplicateStrategy = DuplicateStrategy.EXCLUDE
lib {
from rootProject.subprojects.configurations.runtime
}
}

Compile a jar during Maven build then package as ear from single pom.xml?

I have a maven project currently structured that has to build a jar first from some source files, then create an ear file containing that jar along with some other xml resources. The way I do it at the moment is by building the jar seperate in a 'child' pom.xml then at the root of the project folder I have a parent pom that does the ear packaging.
I know it isn't ideal, but I what to be able to compile the jar and then package it into an ear all with just one pom.xml file. Any ideas on how to do this?

Building/deploying a EJB .jar with its dependencies

I am new to Java EE. I use Maven, Eclipse and jBoss/WildFly.
I have a war project. When I build the project all its dependencies are packaged inside the war file in WEB-INF/lib.
Now I am trying to create a ejb project (I have <packaging>ejb</packaging> in the pom.xml). I want to deploy it as a separate project (not as a part of the war). When I build the ejb project Maven does not package any dependencies in the jar.
How can I package/deploy a ejb .jar with its dependencies?
UPDATE: I'd like to avoid packaging EJBs in an .ear if it is possible. (I do not want to create one more Maven project).
The best solution is package your project as ear. But if don't want use ear, maven assembly plugin can help you to package all needed jars in one file. This solution is only for "proof of concept" variant, and cannot be used in production mode, by licences limitation for example.

how to make maven war:explode do not pack a jar file

I'm new to maven.
I'm now working on a multi module maven project, when i use maven war:exploded ,it will packaging classes files to WEB-INF/lib/***SNAPSHOT.jar.
Is there any way to leave the classes files under WEB-INF/classes , for when java file changes, there is no need to replace the whole jar file?
Thanks

Resources