• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Maven: Creating a jar with just part of my code

Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've got a maven project that has two source folders, let's call them aFolder and bFolder. I can't know in advance what code I will have in any of them since it will depend on previous phases. I just want to create a jar that has all the classes of aFolder but none of the classes in bFolder, BUT code in aFolder depends on code in the bFolder. Let's say bFolder is a dependency but it's impossible for me to find it in the maven repository. Is there any standard way to do it?

Or else, is there any (not so standard) way to do it? I guess there must be a way using assembly plugin, but so far none of the well-known descriptors seems to do what I need, and when it comes to create my own descriptor I don't know how to do "Taking two folders as classpath but taking just one of them as code to include in the jar". Any help?

Thank you very much!

Saloon Keeper
Posts: 22291
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to tell for sure, but your build process doesn't sound like a good fit for Maven. Maven is geared towards creating a "universal" module that will be the same for all people everywhere and not a custom module whose contents are determined by build options. Profiles don't count - they make things like a "universal tomcat" module, "universal websphere module" and so forth.

So you might consider using Ant, if that's what you want.
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maven treats every project as one unit with one target artifact. Composited artifacts just use several of these "simple" artifacts.

In your case you have to different base artifacts in one project. This is contrary to the Maven way. Just make two projects out of them and add a dependency to ProjectB (bFolder sources) with scope "compile". Maybe you could even simplify by using a multi-module project.
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your replies.

I absolutely agree, but you know sometimes one has to find an ad-hoc solution to fit requirements from above. Anyway I solved it using antrun plugin and assembly... nothing worth explaining it here.

Anyway I have another question about assembly plugin. I have my own descriptor to create a jar and I wrote something like this:

Where ${classes} is a folder in which I placed my classes:

But inside the jar I only want to have from de "com" folder and on, not including "mydir". I mean:
Instead of:

Does anyone know how to?

Best regards

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic