Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Java project as library

I have three projects in my eclipse workspace:

EventKitchenCore
EventKitchenDesktop
EventKitchenAndroid

EventKitchenCore contains all the core functionality, and EventKitchenDesktop and EventKitchenAndroid are essentially just different user interfaces.

I have EventKitchenCore added and working as a library in EventKitchenDesktop, however I am unable to figure out how to add it as a library to EventKitchenAndroid.

How do I do this? It would be a pain in the tush to have to export as a jar in the lib directory every time I make a change...

I tried adding the Core project in Properties > Java Build Path > Libraries and Properties > Android > Library, but no luck :\

Update - for now, I got it working by exporting the core project as a jar in the libs folder. However I make frequent changes, and like I said, it's a pain in the tush.

like image 696
Entity Avatar asked Nov 29 '22 13:11

Entity


1 Answers

Eclipse has builtin Ant support. You can make use of it to automatically create a JAR of the current project and put it in a folder of another project.

Provided that EventKitchenAndroid and EventKitchenCore projects are both in the same workspace, create a build.xml file in EventKitchenCore project which contains just this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="EventKitchenCore" default="createjar">
    <target name="createjar">
        <jar destfile="../EventKitchenAndroid/libs/EventKitchenCore.jar" basedir="bin" />
    </target>
</project>

To test it, select the file in Eclipse and press Ctrl+F11 to run it as Ant build file. If it works the way you want, then you can tell Eclipse to automatically execute this build file everytime the project is built. Go to the project properties of EventKitchenCore and in the Builders property, click Import... and select the build.xml file you just created.

Now, it will be executed everytime the project is built. You can manually force the build of a project by pressing Ctrl+B. See also the video demo I just created.

like image 59
BalusC Avatar answered Dec 04 '22 16:12

BalusC