• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

maven / web inf

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys. I have Maven (the M2 plugin) working in eclipse with standard (non web) java projects.

I also have maven working on the command line, and now have a large repository in /usr/local/apache-maven/myRepository/

But after adding m2 to a web project, the JSP files do not "see" the M2 dependencies.

What I would like to do , is synchronize my maven repository on my hard disk with my eclipse web application. Or Alternatively, I'd like to have my pom.xml file in eclipse be smart enough to download files from scratch, but at least directly to my WEB-INF / lib directory.

Right now, eclipse is doing a hybrid : It's using the maven plugin to download new dependencies when I add them to pom.xml (thats good!) but, its downloading them to my maven repo on disk (in usr/local). Again, thats OKAY with me, but it is annoying because eclipse is smart enough to SEE my maven repository is external, INVOKE maven to get external jars.... but NOT smart enough to automatically PUT those jars in the WEB-INF directory !!!???

How can I get maven to do this the right way (in or out of eclipse .... is there a "mvn" command i can run outside of eclipse that will automatically add new jars to the build path in my eclipse web project ? If so, I'm okay doing that) ? I DO NOT want to simply download a "new " version of the maven plugin that "automagically" manages this issue for me using some eclipse specific logic.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Maven files should already be on your build path using the plugin, at least they are for me, and when I deploy the app the dependencies are deployed (I can double-check that; not in front of a useful machine at the moment). What versions of everything are you using?
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again, I have eclipse 3.4 and maven 2.9 I think.... (the very latest of both) think I'm going to try breaking my question up into smaller chunks....

1) This is an eclipse (i.e. java ee dynamic web) project.... Is the build path for a web project a litle more complicated than the build path for a normal java project?

2)I can solve the problem by manually copying maven downloaded jars into the web-inf folder. Is there a way to instruct maven to do this automatically ?

2.1) if I can accomplish 2, will deployment of war files still work effectively?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eclipse is at 3.5, btw.

The build path is identical--your issue is with deployment (I think, it's not clear what the actual problem you're having is). The Maven plugin puts the dependencies on the Eclipse build path, as you saw with the non-web project. Are you having the issue when you're editing a JSP file, or after deploying/running? What's the actual error you're getting?

Manually copying the files into WEB-INF/lib is not the correct answer--that's opposite of what you want to do with Maven.
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay..... Well basically, I have my pom.xml, and I have dependency management enabled.

But if I update my pom.xml by adding something like



Then I see no change to WEB-INF/lib.

But if I cd to /usr/local/apache-maven/repository

I see that iBatis is there.

.... So how do I get maven to update WEB-INF/lib with the necessary dependencies without manually copying them over ?

Im not getting an error, per se, I'm just not seeing the jars in my WEB-INF/lib folder.

That to me is, in and of itself, an error ! Since typically, jars MUST be in that folder for a web app to have access to them.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you actually get an error?
 
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
How did you install Eclipse? Did you get it from your distro's package manager, or did you download from the Eclipse web site?

I assume that you installed the m2eclipse plugin from the m2eclipse web site using the install new package feature in Eclipse...

In the Eclipse Preferences, under Maven | User Settings. There will be two entries - one for the location of the settings.xml file, the other for the repository. I recommend that you create a /home/xxx/.m2/settings.xml file and in that file place the location of your local repository. Then update the preferences to use your settings.xml file and click on Update Settings. Eclipse should then adjust the repository location.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Why would the repository location be an issue?)
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason the repository location is an issue is that the repository location is not WEB-INF/lib !

I know this sounds a little ignorant, but forgive me, I'm used to the idea that WEB-INF/lib is where the JARS go .....

Am I missing something ?

Here is the structure of my eclipse project ....

project
src
org
venn
controller
dao
JRE Systen Library
Maven Dependencies
Apache Tomcat v6
Web App Libraries
Referenced Libraries
EAR Libraries
target
WebContent
jsp
Web-Inf
html
.classpath
.project
pom.xml

The thing that is flustering me is that there are Maven Dependencies, and WEB-INF/lib. And the two are not merged... i.e. there are maven dependencies which are not in WEB-INF/lib.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if the repository location *was* WEB-INF/lib, it's still going to be in Maven layout, which is useless to a web app.

Maven *won't copy the libraries to the WEB-INF/lib directory until you build a war, via Maven*. The *plugin* handles build path, and deployment during development. At least it does for me. I don't recall having to do anything.

I repeat the question: do you actually have any errors?
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, when running on the Server, none of the Maven Managed dependencies are seen and thus I get Runtime class not found exceptions.

Can you give me a list of instructions for building a maven centric web project from scratch ? I think I'm just going to try rebuilding a web application from scratch, using maven from the very beggining, in the correct way.

I took a look at this link http://www.devx.com/Java/Article/36785/1954... Which describes the extensive refactoring of a WST project that is necessary to enable M2 dependency management. And I followed the directions, but now I'm finding that I get the error "Document Base .... " does not exist or is not a readable file.... At this point, the folders of my entire eclipse web project are entirely in shambles, and I have to completely rebuild it from scratch.... I think this strategy will work better than continually trying different perturbations of class path variables, etc.... Im sure theres a better way.

Thanks, any insights will be appreciated.

For begginers reading this : Just note that Maven does not automatically manage all your web project dependencies for you, i.e. not as easily as it manages them for a standard eclipse java project ....... there may be a little bit of tinkering you have to do.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't confuse Maven with a Maven plugin: Maven handles web project dependencies just fine, out of the box. It's been my experience that Eclipse support is the least mature of the major IDEs (IntelliJ, NetBeans, Eclipse).
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Found the solution ! It was that I was having issues with the eclipse deployment and the J2EE dependencies. Youre right, the M2 plugin does work well once eclipse is set up to export dependencies and libraries in the correct way. The important thing to differentiate between is wether or not it is that eclipse manages your deployment, or it is maven. If its not maven, and you are relying on eclipse, you have to make sure you do ALL the same things you would do in a normal eclipse web app --- that is, make sure your dependencies are being exported and bundled properly.

If you have used maven as a build tool , rather than just a dependency manager, then you probably have a different set --- or no set at all --- of issues to deal with.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great; I'm glad you figured it out. Sorry I couldn't help more--no Eclipse on this machine.
 
Peter Johnson
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

David Newton wrote:(Why would the repository location be an issue?)


My reading of Jay's question was that there were two repository locations on his PC and thus his PC was filling up with duplicates of the many JARs that Maven downloads. So my reply focused on tracking down and fixing the issues that might cause this. I suspected that Eclipse had its own Maven installation, which implied two settings.xml file (one in the conf directory of each Maven install) and thus two different repository locations. Setting a user-relative settings.xmlf file should take care of that.

I also did not understand the location of the repository, which is why I asked about how everything was installed.

jay wrote:If its not maven, and you are relying on eclipse, you have to make sure you do ALL the same things you would do in a normal eclipse web app --- that is, make sure your dependencies are being exported and bundled properly.


The m2eclipse plugin should take care of that for you. You must create a Maven project, not a Dynamic Web Application project, not an EJB project, only create Maven projects. When creating a Maven project you can select from a large set of archetypes, one of those should meet your needs. Of course you can always add your own. Once you do that, you can open your POM with the POM editor and use the Dependencies tab to add the dependent JARs to your project. The m2eclipse plugin will add the JAR to the project such that

If you do not create a Maven project, but instead create, for example, a Dynamic Web Project and then add a pom.xml to it to build it, then you will have to manually add your dependencies both to the POM and to Eclipse.
 
reply
    Bookmark Topic Watch Topic
  • New Topic