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.
Related
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.
I'm using Google App Engine to create a project consisting of multiple Google Modules. How do I set up my project (using Maven) so that I can share source code such as Objectify object model definitions, shared utility code, and unit test code across the modules?
I'm hoping the answer is simple and that I can just use Maven as suggested in answers such as these:
How do you use Maven to share source code for two projects?
How to create shared source folder across multiple projects in Eclipse?
For test code: Sharing src/test classes between modules in a multi-module maven project
For test code: Share test resources between maven projects
Eclipse Linked Resources: https://stackoverflow.com/a/7585095/2848676. Is this compatible with Maven though?
However, I'm concerned there might be something special about Google App Engine modules that makes them different from Maven modules. And then maybe the approaches above won't work.
As an example of why I'm concerned, notice that Google says "Although Java EE supports WAR files, module configuration uses unpacked WAR directories only." yet some of the solutions given above suggest packaging the shared code into JAR files. I realize WAR and JAR are different but I'm worried I'll waste my time trying to make something work that can't.
Any advice on how to share code among Google App Engine modules?
I have a share directory that contains code I want to share between modules.
Then I can make symlinks from my modules directories to the share directory.
The symlinks can be of a file, sub-directory, or the whole share directory itself.
Hi all i have very rare problem which needs to be solved.
Problem/issue:
I have a dynamic web project which is already built and i have war file of that project.
I need to apply some customizations on top of the war file given to me.
Using maven or ant am able to compile the custom code written by me and able to add produced class files to the war file.
But the this is happening for final war file build.
when i want to test my code in eclipse. the war file build and deployed in jboss plugin contains only the class files produced out of java files written by me..........
Please help me how can i modify the .classpath file of my project so that a jboss publish can build a war file using the dependent war file which can run on eclipse-jboss to test my custom code....
Advance Thanks.....
Not a rare problem.
What you need to combine two web applications (wars) together. You have your customization war on which you need to overlay the existing web application.
It looks like you have already solved it from build perspective and looking for Eclipse support. To my knowledge, Eclipse lacks support for this. You probably need to manually do the necessary configuration to make this happen.
It looks strange to me to have two WAR files.
Perhaps you have to consider to package your customizations in a JAR and inserting that jar in the original WAR file.
Otherwise, another solution, and what I do often with open-source project to customize is to have three projects in your workspace.
PRJ-src (with your original sources/JAR/WAR)
PRJ-custom (which depends of the previous one); This project contains only the new classes or custom spring xml files (with injection of my own classes)
PRJ (the merge of the two previous projects)
I create an Ant task in the 3rd project which takes the 1st project (PRJ-src) and merge with the 2nd project (PRJ-custom). This is possible to do so with Maven as well.
Then this is the only project I deploy in my app server (tomcat / jboss).
I have a Java Project, for which I'm now creating a Web interface, using a Dynamic Web Project from Eclipse. The Web project consists of a single servlet and two JSP's. Something like this:
/JavaApplication
/src
/lib
/resources
/WebApplication
/src
/Servlet.java
/WebContent
/WEB-INF
index.jsp
other.jsp
Now, I need to reference JavaApplication from WebApplication, in order to use its classes to process web requests. What's the best way to accomplish this ? My idea is to create a .jar of the JavaApplication, containing all the .class files, /resources, and /libs. In this way, I could include the .jar in the web application, and I could have a single .war file that contained the entire application.
What do you think? How is this problem typically solved ?
Note: I don't want to convert the Java Project into a Web project.
In Eclipse project properties, add the project to the Java EE Module Dependencies (Eclipse 3.5 or older)
or Deployment Assembly (Eclipse 3.6 or newer) entry in the project properties.
This way Eclipse will take care about doing the right thing to create a WAR out of this all (it will end in /WEB-INF/lib). No other configuration is necessary, even not some fiddling in Build Path.
Under Eclipse, you can declare Project References for a given project, the web application in your case. To do so, right click on your web application project, then go for Properties > Project References and select the JavaApplication project. This should allow you to call code from the JavaApplication project from the WebApplication without having to build a WAR. This is a solution for development.
For standard deployment (outside the IDE), you should indeed create a standard WAR. To do so, you'll have to package your JavaApplication as a JAR including the .class files and the files under /resources but not the libraries it depends on (JARs under /lib). These dependencies will actually end up in the WEB-INF/lib directory of the WAR, beside the JAR of your JavaApplication. These steps are typically automated with tools like Ant or Maven.
Connecting java app to web app for development :
right click on web project :
properties>project references> add the java project you want to refer
Now in properties tab of web project go to
properties>deployment assembly> add the project manually and run the app
Consider moving up to EAR level, if your web container supports that.
The tricky part with shared code is where should the common code be put. A copy pr web application? A copy in the web container? Overdoing the "share these classes" might end up in class loader problems.
If you are creating two separate web applications refactor common java code into a separate Eclipse project and refer to it from both WAR projects.
EDIT: Apparently I have misread the problem description, and thought you asked about an existing and a new web application sharing code.
If you have an Eclipse project with your application, and another with your web frontend, then you can let your application export the necessary resources which the "Export WAR" in Eclipse Java EE can wrap up in a jar file and put in WEB-INF/lib for you. You need to say this explicitly with a checkmark in Properties -> Java EE Module Dependencies for your web project. Expect you have to experiment a bit - this took me a while to learn.
Typically you would create an API interface using remote service beans from the Java application that expose the methods that you want to invoke in the web application. You would include a proxy of the API interface with your web application that calls the remote service bean in the Java application. Remember that you will need to register the remote bean in the web.xml file.
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