nfm
nfm

Reputation: 20677

Where do I put an external Java library in my program's directory structure?

I'm new to Java, and trying to figure out how to structure my program's files.

I've downloaded a library (jnotify), which contains both a jar and also zip of the Java source code.

So far, I've only got my program working by extracting jnotify's source to the top level directory of the program. So jnotify's source files are all over the place, and my program's code is in a subdirectory.

$ ls /path/to/project
CHANGELOG
inotify-syscalls.h
jnotify_64bit.dll
jnotify.dll
libnotify.so
my-projects-actual-files/
net/
README
... etc

I'm importing jnotify like so:

# myprogram/program.java
import net.contentobjects.jnotify.*;
... code body here ...

And running it by explicitly setting java.library.path:

$ java -Djava.library.path=. myprogram/Program

This feels wrong but I have no idea what the Java way of organising source files and libraries is.

How can I neaten my program's structure so that jnotify lives in something like lib/jnotify but can be imported, compiled and run sensibly?

Upvotes: 2

Views: 10615

Answers (1)

MeBigFatGuy
MeBigFatGuy

Reputation: 28568

The jar should just be on the class path, the library path specifies where the dll lives.

java -classpath lib/jnotify.jar;. -Djava.library.path=lib/ myprogram/Program

You shouldn't unzip the source code, unless you need to debug the jnotify code.

Upvotes: 5

Related Questions