I have a project creating some FAT jar to be used via webstart loaded from an ear. This leads to the following Maven projects in a multi-module project
jar project creating the FAT jar
war project creating the webstart war
ear file containing the server application and the war file for webstart
The jar and war artifacts are only used as intermediate artifacts to be able to create the ear artifact. However, Maven handles them as artifacts and so they are always uploaded to Nexus.
Since the jar is getting real fat, I would like to avoid uploading it 3 times to nexus for each build. Is there a way to avoid this? I can think of two ways:
Moving that three projects to one pom file
Some flag / option / whatever telling Maven to handle artifacts as intermediate artifacts not being deployed or installed
Does something like this or any other solution to my problem exist?
If this is a multi-module project, you can set <maven.deploy.skip> to true in the projects where artifacts should not be deployed.
Related
In my maven project, I have this dependency which is my own project that is installed in my local maven (through cmd mvn install):
<dependency>
<groupId>com.myproject</groupId>
<artifactId>api-core</artifactId>
<version>1.0.0</version>
</dependency>
However when I start the tomcat server, I will get ClassDefNotFoundError on the classes within this project.
I tried to add the jar to the deployment assembly through the project's properties, however when I add this jar file, it is taken as a folder and will always be placed into the Deploy path of "WEB-INF/lib/core.api.1.0.0.jar" which is then a folder inside the lib, therefore tomcat isn't able to locate the jar file. I also noticed in the Web Deployment Assembly, the Maven Dependencies are deployed to WEB-INF/lib. Apparently my own jar file is not considered Maven Dependencies when it is being deployed. When I further look into the Maven Dependencies from Eclipse, the jar file is packed inside as "core" folder and it is not treated as a jar file. Therefore on run time, the web app has trouble locating the jar file and is giving me complain.
Further investigation shows that in Eclipse, I have the core project imported, and Eclipse is "smart" to recognize that project is the one generating the dependency, and therefore automatically convert the jar to the folder. If I remove the core project, the maven dependencies will then successfully added as a jar file, and then the deployment to tomcat issue not problem at all!
So, my question is, is it a way to keep the dependency in folder structure, while I can still have to core project imported to my workspace?
Yes, there is one: Show up the contextual menu of the web project, go to the Maven tab and uncheck the Resolve dependencies from workspace projects option: In this way, Eclipse will not interfere in Maven's dependency resolution chain.
I know about maven war overlays, but they assume that the original war file is a maven project.
What if I only have access to the packaged war file and I need to modify it by adding new resources or updating few values in properties file using maven and push the new overplayed packaged war file to tomcat on a server?
Is it too complex to do this in maven?
If I install the war file in my repository does the maven build process automatically use it?
It doesn't assume that the WAR is a Maven project, whatever that means, just that the WAR is a Maven artifact. You can install any WAR as an artifact, it does not matter how it was built. If you then declare a dependency to this artifact, you'll be able to overlay it. While it is easy to add and replace files (just create a normal web project structure containing the new files and the WAR plugin will do the rest), it is not easy to modify them. If you really wanted that, you'd have to run something like the replacer plugin after the original WAR is extracted but before the package phase of your project. It is also possible to download a (WAR) file instead of getting it from a repo by using some exotic plugins, but this is probably not something you should be doing as it blows away half the benefits of Maven.
As for deploying the newly-built application to a remote Tomcat, while doable using the Tomcat plugin, it is not something I would be doing from Maven. It is usually a job for a build server, like e.g. Jenkins, while the Tomcat plugin is more for local development and testing.
I have an eclipse workspace (for work) that has an ear project that I use to "export"/deploy an ear file to a JBoss server.
However, they recently asked me to create an ant script that can build the workspace and create the ear, and I have done this successfully. The problem arises when I try to run my program with this ear that was built using the ant script; for deploying I'm simply copying the resulting ear file and pasting it into the JBoss/standalone/deployments folder and running the application.
The JBoss AS starts fine, but then I get a few exceptions that halt my application that I do not get when I do a build and deploy through eclipse. The two ear files are identical when viewing the two ear files using 7zip, however I see in the eclipse workspace, in the ear project, theres a .settings folder that has 4 files, one of them being org.eclipse.wst.common.component and I'm guessing this (if not all 4 files) is necessary when deploying somehow.
Does ecplise use this .settings folder and the files inside when deploying an ear? What happens during this process? and how can I replicate it in an ant script so that my application runs identically from either ant or eclipse builds?
EDIT
let me just add that none of the files in the .settings folder get packaged up in the ear file, so I'm guessing they're somehow used when eclipse does a build/deploy, but it doesnt get placed in the final ear product
thank you
Eclipse uses the data in org.eclipse.wst.common.component to figure out the dependencies needed for deployment. The file corresponds to the settings found in Eclipse when Right-clicking on an EAR project > Properties > Deployment Assembly.
E.g. if your EAR project has a dependency on a WAR project then Eclipse knows to include the WAR when deploying because of the Deployment Assembly settings which get stored in org.eclipse.wst.common.component
When building the EAR using Ant you need to add these dependencies manually (without relying on Eclipse metadata)
I have in Eclipse web application project that depends from other projects.
When I run debug on embedded Tomcat in lib folder that Eclipse copied not jars, but folders with names like:
dependent_lib1.jar
dependent_lib2.jar
dependent_lib3.jar
....................
So web application don't start because didn't found some files. When I manually deleted all these folders and manually copy jar files - all works.
Does it possible ask Eclipse (or maven - this is maven project) to copy jars or ask Tomcat use folders like jars?
Thanks.
Here is how I think it should be done with maven:
If the other projects are also maven projects, export them as maven artifacts in your local repository. A nice article is Maven Deploy Plugin - If they are not maven projects you should manually generate the jar files and add them to the repository, some information can be found at Best way to create a maven artifact from existing jar
Add the exported artifacts as dependencies to your project. A lot of details can be found at Introduction to the Dependency Mechanism
Hope this helps.
Eclipse cannot do it as its just an IDE, you would need use A BUILD SCRIPT using ANT(Copy tag should do it) and run it before you start your server.
Check this for more details:
http://www.javabeat.net/tips/103-writing-simple-ant-build-script.html
I'm got a pretty simple question... I have a Maven 3 project set up like so:
Root POM project
- EAR project: depends on the WAR project
- WAR project
I'd like to use the assembly plug-in to make a ZIP file containing the exploded EAR (which contains the WAR). Any suggestions on how I should do this? Should I put the assembly configuration details in the root .pom or EAR .pom?
Thanks!
-Jon
You could have a third project, say earzip, with a dependency on the ear project. This project can have the necessary configuration (assembly descriptor and other plugin definitions as required) to explode the ear and zip it up again as suitable. This will keep your parent pom clean, as well as not put multiple things in your ear pom.
When I was looking for the way to run batch script from ant (~1 year ago) I found only the following solution:
In the pom that builds your parent project add runant plugin
In the ant script (1) add target that runs a batch script (if on Windows)
In the batch script (2) add archiving task.
No point to add zipping task to the pom that builds an EAR (IMHO). It should be parent pom task.
I hope that these threee would do the magic.
Good luck!