• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

automatically copy maven jars to target folder

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm wondering if it's possible for eclipse to copy all maven jars to certain folder during auto build (not maven build, but eclipse build, found in Project -> Build Automatically), just like we can configure eclipse to compile to java classes to target folder (by default, it will be bin, but can be configured to other folder as well). thanks
 
Saloon Keeper
Posts: 26897
192
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why?

I've got something like 2GB of jars in my maven cache and a lot of them are different versions of the same thing, since different projects are at different resource versions.

One of the things I like about Maven is that it doesn't keep multiple copies of the same jar in multiple places. It pulls a copy from the cache when you do a build that needs it in the resulting product, and the rest of the time you're saving disk space.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn;t mean all the jars in maven repository, but only jars included in a project (under maven dependencies). thanks
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
basically I just need to know how to deploy my maven project to tomcat (all the compiled java source files, the resources, jsp, css, and javascripts including all jars in maven dependencies). So I need maven to delete the previous deployment (clean everything), and the redeploy in exploded form (not in war). Is there a plugin for eclipse to achieve this? thanks
 
Tim Holloway
Saloon Keeper
Posts: 26897
192
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not need to deploy your source code to Tomcat. Tomcat won't know what to do with it. You do need to deploy a WAR to Tomcat, and the easiest way to develop webapps using Maven+Eclipse is to layout your Eclipse project as a Maven WAR project, then add a Tomcat Context file to TOMCAT_HOME/conf/Catalina/localhost that has its codeBase pointing at the Eclipse project's target/xxxxxx.war file or the exploded war directory (xxxxxx) that is where Maven assembles the files that it will then pack into a WAR. Either one works, although you can save a few seconds if you skip the Maven goal that actually zips up the WAR.

To test such a webapp, stop Tomcat, run the maven goals "clean compile war:war", then start Tomcat. If your Context is properly defined, Tomcat will deploy the results of the Maven build and, if Tomcat is running in debugging mode, Eclipse will allow you to set breakpoints in your source code.

To make changes to the webapp, you should generally stop Tomcat, alter the code, re-run Maven and restart Tomcat. Tomcat can pick up changes on the fly, but complex projects may not re-deploy cleanly. One thing that usually is safe to do, however is change static (non-class) content on the fly. The command I use to do that is "mvn -o war:exploded".

The normal Maven war:war goal does not (re)compile the Java classes. The war:exploded likewise does not, and it also skips the actual zipping up of the WAR. The "-o" option tells Maven to run offline, which makes it a bit faster and is usually safe when doing lots of compiles one after the other. I do like to run online about once a day, though to pull any possible changes coming in from the archives.
 
Tim Holloway
Saloon Keeper
Posts: 26897
192
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, I did make the assumption that you're running a local copy of Tomcat.

If you need to build a WAR and deploy it to a remote machine, there are Maven goals that do that using one of the several available remote deployment channels such as the Tomcat admin web services and the JSR-88 standard deployment mechanism. You'd have to define the target machine and deployment options in your POM.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm running this:


and my pom is:


but nothing happened.
anything else I need to add?
thanks
 
Tim Holloway
Saloon Keeper
Posts: 26897
192
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean when you say "nothing happened"? Did it not create/update the exploded WAR in the target directory, or do you mean that your server didn't pick up the mods in real time or were the mods never picked up at all, even after a server restart?
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, clean project did the trick. but now, I got extraneous folder appearing in the deployment location. so here's what I did :
1. I saw that package com.springtraining.model should've been com.springtraining.hibernate.model
2. So, I right clicked on the package an refactor and change the name accordingly
3. when running mvn -o, I got two folders : the original com.springtraining.model and com.springtraining.hibernate.model, the former contains all files from the point before refactoring of the package, while the latter contains all the latest files from after refactoring of the package

I also couldn't resolve the maven-clean-plugin jar.

how do I resolve this?
thanks
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and I'm not behind any proxy. all other jars (spring and its dependencies are downloading just fine). I got this:
 
Tim Holloway
Saloon Keeper
Posts: 26897
192
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the command "mvn clean" is coming back with an error, then your copy of Maven may be damaged. That particular goal is pretty fundamental and is probably actually built into Maven itself.

When you run "mvn war:exploded", it does not do a clean, so if you change things, the original files in the target directory don't get wiped out, it's just that new target files get written. That will overwrite older copies of files, but not remove obsolete files, which is why I like to do my builds with a "clean" as the first goal in the list. Likewise, the "war" goals only assemble a WAR, they don't cause Java compiles, which is why my full build will be something like "clean compile war:war" or simply "clean package".

I make a distinction, because my builds are set up to construct an OS installer package, so "package" not only does the compile and war goals, but also the OS package builder goal, which I don't always want to run. Since most builds are for testing, not actual installation.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply, what about the extraneous folder? and I've downloaded a new copy of maven, still got the same error regarding maven clean plugin. any idea? thanks
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding the error on mvn clean, try wiping out your local repository, or at least the org/apache/maven directory. It could be that the metadata in your local Maven repository is corrupted.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic