Deploying modules in a web application - java

I have a web application - deployed on Tomcat.
It has two modules
Module A and Module B
Both have java code as well as UI component (struts\JSP etc.)
Functionally, Module A is independent an doesn't depend upon Module B
For ModuleA:
We create a war for Module A and deploy it as ModuleA.war
Now Module B depends upon Module A
We so "merge" the two modules into ModuleB.war
This involves merging the web content directories into one
We were feeling uncomfortable with this whole process of merging and wondering if there is a smart way to do this ?
We are also considering putting all the web content in one of teh modules - say Module A
and just keep the java code in ModuleB
Any suggestions ?

This is one of the java problems.
Say you app A is the public website, say your app B is your admin, but uses same database, same bizlogic classes,etc.
I found this problem all time. My approach might help you.
module A will have classes related only to project A
module B will have classes related only to project B
mod A and B will share a .jar file who contains all related classes, you can deploy it in TOMCAT/lib or if you want maintain it individually, deploy it in each app MYAPP/WEB-INF/lib

Related

How to tell GWT development mode to include files from a module configured as dependency?

I am trying to create a combined GWT application from two existing GWT applications which used to run separately in parallel. The existing applications were module "A" and "B" in the IntelliJ project, resulting in two artifacts a.war and b.war.
I thought the best approach would be to add an additional module "All" that includes both modules as dependencies and will result in a single artifact "all.war".
The problem I have now is that some files (css and third party javascript) that are used by module A and referenced from the host page are not found from development mode: I get 404 status messages for the browser requests for for these files. They are, however, contained in the generated artifact/war file.
In the project settings for module A, they are contained in the directory configured as the web resource directory of module A's web facet. I am not able to configure this directory as web resource directory of module "All" as the IntelliJ UI does not allow me to use any directory outside of module "All"s root directory there. As these files are not needed by module B, I would have hoped I could leave the structure modular, and not move these files to somewhere in module All's directory structure.
As I am using an old version of GWT, this is the classic plugin based development mode, not super dev mode.
Is there any way how I can tell development mode to use these files from a module configured as dependency?

appengine create two modules using same war

I have a 2 modules in a java appengine project (one for front-end and one for back-end).
I want to duplicate the back-end module without duplicating the code.
How can I create a new module that uses the same war of the backend module ?
Thanks for your help.
You can symlink the file(s) (or directories) to be shared inside the respective modules. The deployment utilities know how to replace the symlinks with the actual content of the files/directories they point to.

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.

Reference classes across dynamic web projects on Tomcat

I have two dynamic web projects - A & B. Project B references classes in Project A. Project A runs great on Tomcat locally. Project B runs on Tomcat locally too, but when I run it referencing Project A classes on Tomcat, the classes from Project A are missing in Tomcat and thus throwing a class not found exception.
Since I cannot jar the Project A files, how can I get the classes from Project A to a local Tomcat deployment so that Project B can run when referencing Project A classes?
If two web applications share some common classes then these classes should be refactored out of the web application code base and put into a separate library (jar file). This jar can then be added to your web applications as a dependency.

Using a bean class from a servlet in a Java EE application

I just started to study Java EE and made some examples (Just Hello World and some a bit more complicated). Now I'm doing a small application myself for learning purposes. I made an EAR, an EJB and an WAR just like in this example but, instead of working with interfaces, I'm working with real classes.
In summary, EJB and WAR are in the same package, but I can't instantiate an EJB class from a WAR servlet, because it doesn't seem to find that class implementation. When trying to instantiate a class called "Database" in my servlet, I got the following error from Eclipse:
Database cannot be resolved to a type
It also happens with other classes.
Any idea? Thank you very much.
It sounds like you might not have the module dependencies set. The WAR project needs to have the EJB project as a module dependency.
Right click on the WAR project, click Properties, click Java EE Module Dependencies, and verify that the EJB is selected.
Module dependencies are represented in the MANIFEST.MF file of each Java EE component. That file contains the names of all the components that it depends on, and the Java EE Module Dependencies editor updates that file.

Categories

Resources