Dependency management on tomcat server - java

I have a java web application which is deployed on several servers. The project uses maven dependency management tool.
The war file that is created after including all the dependencies is quite large. If I use scope "provided" for all dependencies, the war fail created is quite small. I want to use the latter war file for deployment and manage dependencies on the remote servers itself.
I can add a folder containing those dependencies to all the servers and include it in the tomcat class path but if in future I add another dependency I will have to add that dependency to all the servers. Please suggest a workaround.

Related

Is there a jboss-deployment-structure.xml equivalent for tomcat?

I need to migrate from jboss to tomcat, we have two war modules and need to declare the dependency between the two deployments in order for the libraries to be accessible by both the separate war files.
requirement arises due to licensing issues around the packaging of jar files in internal binaries.

Is there a way to point jar libraries in a different location from a war in tomcat 8 to reduce war size?

I have my web service made in Grails/Gradle which contains a lot of dependencies jars making the war size heavy which is deployed in tomcat8. Is there any way that my war would use the dependencies from separate location so that my war would be free from these bulk dependency libraries.
If you are using maven for instance you could do something. In all dependecies you dont want to include into your WAR file add the tag.
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
Then when maven build your WAR file, a folder lib-provided will generated, you can get rid of this folder and reduce the size of your war.
All those dependecies you dont want to include in your WAR, you should place them into your TOMCAT_HOME/lib and Tomcat will check the libraries of your project and also the jars located in this folder.
IMPORTANT: I would never do this option, because you are doing your WAR dependent to some specific application server, if you try to deploy your WAR in another Server, wont work, if you update your maven dependencies you have to manually update them in your application server.
So I highly would go for another option rather than this, and I would keep your WAR independant to any application server.
Check your project into Git (of course without jars) and create a script on your server to check it out, build it (with Maven or Gradle) and deploy it to Tomcat.
Have a look at a Continous Integration system like Bamboo or Jenkins, to do that automatically.

Tomcat dependency in a project that is a dependency for a project that also uses tomcat

I have project-A that is has Tomcat as a dependency and acts as a library for web applications that I write. I have project-B that is a web application that has tomcat as a dependency as well as project-A as a dependency. When I deploy project-B as a web app and run it with Tomcat I get a NoClassDefFoundError:javax/servlet/http/HttpServlet.
I am guessing this is because project-B is has two references to the Tomcat library? What is the best way to structure dependencies like this? I have tried to use Maven (for the first time) with this project to help solve this, but it doesn't seem to change anything. Do I need to setup Tomcat as a Maven dependency in both projects and exclude it in the pom for Project-B?
Where have you kept project-A classes? Looks like you have not included project-A as dependency to project-B.. Have you kept project-A jar or classes in Web application of project-B..
Or you may need to put your project-A jar inside tomcat classpath itself. Moreover, you may not need to include all dependency in project-A jar, skip tomcat jar to avoid redundancy..
In case anyone has this issue I'll outline how I solved this. In my project-B I had inadvertently added the project folder for project-B to the build time classpath. In eclipse this is under the run configuration settings for the tomcat server in this case. A odd issue that I accidentally caused myself but it might be useful for someone.

How to compile a web project with Weblogic dependencies

I'm trying to implement SSO for a web project that will be deployed on Weblogic. In the examples that I found the user identity is retrieved using weblogic's inner classes e.g. :
import weblogic.security.Security;
...
Subject subject = Security.getCurrentSubject();
I believe a jar containing this "weblogic.security.Security" is in weblogic's classpath, but how am I supposed to compile the project? This dependency is not available from maven so there's no way to mark it as "provided".
Is there a common solution to this problem or I should get this jar from the weblogic directory and add it to the project's classpath?
Thanks
You will have to get the jar, add it to your local maven repository (or your organisation one, generally nexus or artifactory) and set the scope as provided.
See http://docs.oracle.com/cd/E21764_01/web.1111/e13702/maven_deployer.htm for an example on how to deploy your jar in your local maven repo.

Application server-agnostic build script

I have a J2EE application that needs to be distributed to customers, who will have application servers of their own choice. What is the recommended way of writing a build script that would compile the J2EE application sources (at customer sites) so that they will eventually be able to deploy the application on their servers ?
Moreover, what JARs should one actually use during the compilation process ? Since this is meant to an application server agnostic script, is it recommended to use the JARs (say servlet.jar, jms.jar, ejb.jar etc.) from the application server, rather than having my customers download these JARs from a particular repository ? Is there any such repository that is recommended for such JARs (JARs of J2EE APIs) ?
PS: The EAR file cannot be built locally and shipped to customers, since additional development will be done at each installation to integrate with other systems, perform customizations on the application etc.
Build the application locally, and distribute the WAR/EAR files to the customer.
Edit:
The situation you describe is basically that you need to provide a code base for further development by the customer. In that case I would suggest that you look into creating maven modules of your work which are pushed to a private repository accessible by the customer. You then let them know that they need to depend on module X version Y in their pom.xml, and module X then pulls in all the libraries needed in the correct versions.
Note that if they don't use Maven, they might use Ant Ivy for the dependency resolving.
Some generic J2EE API jars can be found at Sun's site, however you might have to dig a lot to find them.
I would just use any JAR you have handy, bundle it with the source, but away from /WEB-INF/lib
Basically, don't include the container jars (servlet.jar, jms.jar, ejb.jar etc.) in your EAR or WAR file.
If you are just talking about servlet.jar, the web container provides that - you shouldn't include it in your war file.
If you are creating an EAR file, they you must be using an enterprise container and it will have a JMS.jar and EJB.jar.
JMS on Tomcat would be a little trickier - you'd need people to install something like activemq on their servers.

Categories