Search code examples
javaantbuilddependenciesivy

How do I build 2 jar files with different dependencies?


I have two different versions of the same third-party library, and need to deploy to two different systems. Each system uses a different version of the library.

LibraryA and LibraryB have the same API interface and my code is currently built with LibraryA and deployed to SystemA. Now I need a second version that is built with LibraryB and deployed to SystemB.

Of course I could copy/paste my code and compile each project with a different library, but this seems like a maintenance nightmare. Both libraries can be installed and developed against concurrently. Currently I am using Ant, but everything is on the table and anything that could help would be considered.


Solution

  • I managed to get this working with an enhanced Ant build files and Eclipse settings. This fulfilled our requirements of a temporary ability to toggle Libraries in Eclipse, Compile/Test using both Libraries and deploy to different environments.

    The Ant build script originally compiled and tested over LibraryA and I copied and pasted another section for LIbraryB. This allows the project to compile with both LibraryA and LibraryB and runs JUnint tests over both libraries.

    The startup script was modified to java -cp "Project.jar:$SYMLINK_LIB/*" project.main [space delimited arguments]

    $SYMLINK_LIB contains symlinks to the jar libraries differing between two different environments.

    Eclipse Configuration

    1. Built a project for LibraryA and LibraryB
    2. For both projects, right click on the project a. Click on "Libraries" and "Add JARs" i. Add the jar files necessary for this Library b. Click on tab "Order and Export" ii. Check all jar files so that they will be used by any Project that imports this project. c. Click "OK"
    3. Right click on the project that needs to import LibraryA and LibraryB a. Click on tab "Projects" and "Add" to add Project LibraryA (or LibraryB) b. If this project is going to be imported by other projects that will require access to LibraryA or LibraryB - click on "Order and Export" and select LibraryA and LibraryB. c. Click "OK"