4 Replies - 4455 Views - Last Post: 14 June 2012 - 11:52 AM Rate Topic: -----

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Combining multiple folders into one JAR

Posted 13 June 2012 - 03:55 PM

Hi all,

I posted a similar question to this a while back, but I was going about it completely the wrong way; now even though I have a better handle on it I'm still stumped.

I have folders set up in a directory structure like this:
Root
    Folder1
        codeFolder
            source1
            source2
        resources
        buildScript
        Manifest.mf
    Folder2
        codeFolder
            source1
            source2
        resources
        buildScript



The code in Folder2, when I compile it, is self-contained, so there's no problem there. But, I'd like to start including the code in Folder2 in Folder1's JAR file. To complicate matters, both code folders have subdirectories named source1 and source2.

I think I can create a JAR file using this command from the Folder1 directory:
jar -cvmf Manifest.mf codefolder/source1/*.class codefolder/source2/*.class ../Folder2/codefolder/source1/*.class ../Folder2/codefolder/source2/*.class



But that would overwrite the source1 and source2 packages. That's the only way I can think of to do it, though, so I must be missing something.

Does anyone know if there's a way to do this while keeping the packages distinct?

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: Combining multiple folders into one JAR

#2 Kakerergodt  Icon User is offline

  • D.I.C Head

Reputation: 87
  • View blog
  • Posts: 201
  • Joined: 01-May 12

Re: Combining multiple folders into one JAR

Posted 13 June 2012 - 04:20 PM

What you can do is create a manifest in a META-INF folder and just create a zip file of that and your source files and rename the zip to jar. (since zip and jar uses same compression) This is a method I use when trying to figure out how to get different stuff to work in jar files.
Was This Post Helpful? 0
  • +
  • -

#3 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Combining multiple folders into one JAR

Posted 13 June 2012 - 04:31 PM

Thanks Kakerergodt,
I don't understand what you mean, could you give me an example?
Thanks,
Zel2008
Was This Post Helpful? 0
  • +
  • -

#4 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Combining multiple folders into one JAR

Posted 14 June 2012 - 07:19 AM

Hi again all,

I figured out a way to handle this; it's a little bit of a hack but it seems to work well, and maybe what I figured out can help other people.

If you want to add another source folder to a JAR, copy the source folder into your main source directory, then change packages as necessary in the new source folder. After you build the JAR, delete the copied folder.

Hope that helps someone,
Zel2008
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Combining multiple folders into one JAR

Posted 14 June 2012 - 11:52 AM

This is why packages were invented for but anyhow... and which package (sorry subfolder) your manifest file will reference ?
Can be easy to maintain with 2 different applications but what will you do when you will have hundred of them ?
Better to learn right away how to make package and so you will only have to

jar -cvmf Manifest.mf root

but you manifest.mf will have to change in any case if you change the main() you want to execute from that particular .jar

This post has been edited by pbl: 14 June 2012 - 11:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1