I have 6 maven projects that depended each other. I need to deploy all of them every time. Deploying 6 projects as seperated files are consuming my time and it's jar hell.
I'm looking for a way that will make my deployment easier with one single file. I dont know it's a jar file or war , ear i dont know.
Some of my projects fat jar, some of them one jar and the rest are assembler.
Any idea how i can solve this ?
Thank you.
Do you want to deploy a single jar, that contains all the jars (or whatever files) of all the projects? Then use one of the maven plugins that builds all dependencies into a single jar. shade and assembly both do it, there may be others.
You can also use the ear or war goals, but they have particular connotations and don't sound suitable for your aim.
Related
I'm creating build scripts for an existing project. All of their EAR files are built (manually) and the way they do it is put the JAR dependencies of the WAR into the EAR lib folder. The WEB-INF/lib folder of the WAR files are empty. When I'm building with gradle it's putting the JAR dependencies of the WAR into WEB-INF/lib folder and nothing in the EAR lib folder.
It seems like either would work and further it seems (to me) that the more logical path is to put the WAR dependencies in WEB-INF/lib. Is there a preferred or more correct way?
If you only have one WAR file in the EAR, then I would definitely recommend using WEB-INF/lib. Further, I would recommend deploying the WAR directly without the EAR file, as that removes a layer of unnecessary complexity.
The case where you would want to put dependency JARs in the EAR is when you have multiple WAR files that need the same dependencies. Then you can save space by sharing the same dependencies with all of the WARs in the app.
Hope this helps!
As you noted, either works technically, if it's consistent - assuming the EAR just consists of a single web module, all that's really necessary is to put them all in one place, since stuff in the EAR can't "see" stuff in the WAR under default Java EE class loading configuration.
Conceptually, though, you are correct - it's more elegant and cleaner to put everything used by a WAR in the WAR itself, rather than putting it in an otherwise-vacant EAR. While not a big deal now, it becomes important if you expand your application to multiple modules (web or EJB), because putting stuff in EAR/lib eliminates your ability to manage multiple dependencies across the modules. If you need one version of a library in WAR1 and a different version in WAR2, that's impossible if you're packaging everything at the EAR level.
I have an old project. I am trying to add maven build to the project.
All the jar files in the project are present currently in the WEB-INF/lib folder.
Is there a way to add these jar files to the classpath during source compilation and then have it in the war file lib
This is one of the places where switching to Maven hurts. There are a lot of suggestions where most short-circuit something you will need later, and hurt you there. I would suggest that you
Move your jar files out of the lib folder into another project folder not meaning anything special to Maven.
For all jars that you easily recognize, make the proper Maven dependency in your pom file. This will allow Maven to download sources and javadoc if present.
For the remaining jars, you can tell Maven to install them as part of your normal build as custom dependencies. I asked the same question years back and got a very useful response at Multiple install:install-file in a single pom.xml. This will allow you to get up and running quickly.
When you have the time, locate proper replacements for your custom dependencies.
Take your time doing this. It is tedious work but it pays off quickly.
I have a question about using Apache Maven: I built a very simple Maven-based project. This works fine so far.
Now I want to make an executable JAR file from my target file. The problem here seems to be that the dependencies (external libraries) are not packaged together with my app.
I've already googled and found the maven-assembly-plugin. That actually does exactly what I want, but seems to be somewhat inflexible, since the dependencies are not automatically resolved and I can not specify file filters, etc. (or only with much effort over assembly.xml).
What I really like is the solution of spring-boot-maven-plugin, so automatically determine all linked JAR files and put in a lib folder. Now my little project is not a Spring application, so Spring Boot might not be suitable for me, right?
So what would interest me: Is there a way to get a similarly structured and executable JAR archive as spring-boot-maven-plugin builds?
Just use Maven Shade Plugin. It packages your dependencies inside your jar and you can specify the Java packages to exclude
I am working on a Hadoop project in Eclipse that depends on another one of my projects; I've included the other project in my build path, but when I export the dependent project, it only contains the classes from that same project.
Ordinarily, this would not be a problem, as I could just link the other project with the -cp flag, but Hadoop requires you to pass the jar as an argument, meaning that all of my dependencies must be inside that jar.
Is there a way, in Eclipse, to automatically build and include classes from projects that you depend on?
Thanks.
You coud use Ant to automatically build, test and export. It needs some time learning it, but its worth.
There are possible tasks (fileset, zipgroupfileset, copy) to include files, jars (unzipped) or anything into the final jar. By this way you definitly know whats inside your distribution jar and you don't need an eclipe installation running.
I suggest you take a look at maven as a build tool. You define the dependencies and build steps for each of your projects in files called pom files. The maven plugins for Eclipse (the m2e plugins) can take the configuration in the pom file and setup your Eclipse build paths and project description so that you can access the classes in your other project in Eclipse. Maven can also create a jar for you that has the classes from both projects (a "jar-with-dependencies").
In maven terms, your two projects are called "artifacts" with one having a dependency on the other.
The one downside to maven (and the cause for many negative comments about maven) is an initially steep learning curve that can be frustrating. What you're trying to do, however, is very straightforward and I expect you can find a number of examples showing you exactly what you want to do.
The first step, and that's what my answer is about, is to take a look at maven. It may seem overly complex, but it can scale to handle just about any build configuration you need as your hadoop apps get more and more complex.
You can export a project as a Runnable jar, which can be useful if you want a single jar, with dependencies included.
Select the Project. File > Export. Select the Java section. Select Runnable JAR file.
See related answer:
Eclipse: How to build an executable jar with external jar?
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).