How do I package multiple WAR files in one Maven project? - java

I am writing an application that integrates Geoserver with a custom component, intended to be hosted on a single servlet engine. Both are Maven based projects, and I would like to stay in Maven land to package it all into a nice distributable. The general idea I have is to add another module to my application that packages the application itself, Geoserver and all dependencies into one nice archive.
I am aware of the maven-assembly-plugin and its capability of storing all dependencies in a target folder, but I am not sure what would be the best way to create a package that it easy to deploy. Googling for any examples has not been successful.
Extra bonus points if the module can be started via mvn jetty:run.

Have you considered packaging them into an EAR project. It will bundle a set of WARs (and jars), and allows you to specify or generate a deployment descriptor.

Related

standalone application classpath entry using maven

We are using maven for our standalone applications.currently we have two standalone application for new project and going forward it would increase. So I've deployment approach for all standalone application with dependency jars.
All application will have common jars like(spring and other open source jars), third party jars like proprietary mq,sybase and proprietary own jars and am planning to use different classpath prefix in jar plugin and came across customClasspathLayout tag in jar plugin but am not able to configure based on my above deployment structure.
For example, project 1 with below classpath entries
/jars/thirdparty/opensource/ (spring and other open source jars)
/jars/thirdparty/proprietary/ (mq and sybase and product jars)
/jars/company/ (all our company based api jars from internal nexus repository)
If required we will use application prefix before jars, I can add manual entry in jar plugin to add in manifest but i would like to configure based the source repository or some other standard approach, so that i can execute assembly plugin for profile like ( only opensource or only proprietary or only company or only application or entire dependency and application). I need to have fine control on jar location.
I though of this approach for two reasons,
I need to differentiate classpath location for different set of jars
Reduce the packaging based on need (mostly we will have application change rarely with product proprietary jars or sometimes with opensource up-gradation which could be based on stable opensource release.
Please suggest me is this possible and also welcome the feedback for different or better approach for classpath and deployment structure.

Differences between Intellij project and module

I followed dropwizard tutorial and build a simple API project( or maybe I should call it a module). Can I make it a module? Since there is a main method in it, is it allowed to have main method, pom.xml and yml file in a module? If so, when import several modules to a project, how to use the service it provides?
What is the folder structure difference between a project and a module? I notice in the Project Settings of Intellij, I can either add my application to the module, or artifacts.
Should I package my restful API project as a jar to use it?
1.
A project can contain one or more related modules.Each module is a separate library, application and can be a jar, ear or war.Also modules aren't just Java either. You can have modules for ruby, scala, or something else as well.A project is a convenient way to develop related, interdependent applications, libraries in concert.2. Module folders are subfolders of the project folder. An artifact is an assembly of your project assets that you put together to test, deploy or distribute your software solution or its part.see https://www.jetbrains.com/help/idea/working-with-artifacts.html
3. Your REST API most likely will be a web app. So it should be a war/ear.for a sample see https://www.jetbrains.com/help/idea/creating-and-running-your-first-restful-web-service.html

how to split a web application in different wars as modules?

I have a web application with different features such as map view, dashboard, report etc. But now, we are planning to split the application in different modules such as map module, dashboard module, etc. to make plug-gable as per the requirement. As all the modules will have their respective htmls, js, controllers, dao layers, how can be these divided as independent modules? Will it be a war or a jar files?
Need a suggestion or example which can help me move forward.
Thanks.
If you have different modules, with independent features. Its possible.
I recommend you, to first, find what features are common to all web-modules, so this common-module, should be installed (as a jar for example) in the library folder of your server.
Then, all the modules could be installed in the webapps of your server (in tomcat is called as webapps).
Important:
You must be careful not to duplicate libraries in each web-module, beacause this would generate conflicts. All your common jars (libraries or your own modules should be installed in the libs folder).
If you are using maven I recommend you to have a parent maven project with all your dependencies included, and then all the modules which needs these dependencies can import it as provided.
Microservices might be your best approach given the requirement you are sharing here. Each module i.e reporting, dashboard etc will be a separate microservice. If you use spring boot, you will end up creating multiple jar files and each jar file can be booted on the VM as a separate process and each one comes with its own container (tomcat). Makes things simple.
If all sub modules of your project are tightly coupled it is very difficult to split it. I suggest you to develop new different projects using reference of your old project. There is no technique to split existing project to different war files.
if you use Maven, you can create a parent with all common dependencies, and in its pom.xml you should define all your modules in <modules> </modules> tag. Be careful about the version of the artifacts, it should be the same version when you reference it in child pom.xml, in the parent tag.
About microservices, they are independent services and on every server is just running a single service. So, if you have multiple modules or if you more than one service on each server, it will be in conflict with MS concept.

How can I define a different target folder for some dependencies in Maven

I run many instances of the same web application under Tomcat and to save memory I copy some of the libraries to Tomcat's lib (tomcat\lib) and shared (tomcat\shared) folders. Libraries that go under lib can be found by both Tomcat and web applications, libraries that go under the shared-folder can only be used by web applications. My web application also need some libraries on the web application level so those libraries goes under WEB-INF\lib.
I have defined in my pom.xml that most libraries have a scope of provided so that they're not copied to WEB-INF\lib, however is there any way to define that I would like some libraries to go under a custom-defined folder; e.g. WEB-INF\lib\tomcat\shared and WEB-INF\lib\tomcat\lib, from where I could mover them manually to Tomcat's corresponding folders on the server?
That is not really the recommended way to package dependencies, as usually the web application would be deployed without furhter modification of the war file.
I think you can archieve what you want using the dependency:copy-dependencies goal, but it would require some configuration. You would have to set includeScope to provided, set the correct outputDirectory and then define the artifacts with the includeGroupIds or includeArtifactIds options.
Make a separate maven project which contains the war file and define the dependencies which should be located in the share-folder as scope: provided. Furthermore create an other separate module which has these dependencies and create an appropriate archive from it via maven-assembly-plugin...

Building a Java EE 6 project, with a swing client using Maven

I am trying to recreate an existing project with Maven (any IDE is ok, but mainly Netbeans), and I'm a bit confused about the best way to do this, so any help is greatly appreciated.
Currently I have an Enterprise application with the following components:
Web application (some jsps, servlets).
Ejb project
Client project (Swing application / applet)
Common project (Contains common files used by the applet and the Web app).
The problem is the packaging and dependencies, currently the Client (Applet) jar is packaged within the Web application, so that when the web app is deployed, the users can access the applet via their browser.
Is there any similar existing archetype for this, or does it require heavy customization ?
Oh, and I am using Glassfish 3.1
Thanks in advance.
So first of all, for me it looks like you need multi module maven project. In that case there will be no single archetype that will fulfill your needs.
When it comes to "the Client (Applet) jar is packaged within the Web application" you can use maven-dependency-plugin (http://maven.apache.org/plugins/maven-dependency-plugin/) and its goal:
dependency:copy - takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in local.

Categories

Resources