cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl java interface on linux

From: Forrest Cahoon <forrest_at_abstractfactory.org>
Date: Wed, 06 Aug 2003 23:35:14 -0500

Hello, all.

I'm trying to help the folks working on iRATE (irate.sourceforge.net), a
  java program which downloads legal mp3s off the web and tries to use a
collaborative rating system to help its users find music they like.

We are having difficulty detecting & responding appropriately to
timeouts on the large http downloads of mp3s.

I thought, hey, libcurl is probably just the thing! It says they have a
java interface right here on their web page! I posted to their devel
list that I would try to come up with libcurl-based download implementation.

THEN I downloaded the java interface code. Oh, ok, this hasn't gotten
very far yet. It won't even compile on linux. But I'm not giving up;
someone has to get this thing to work.

So far, I've gotten the library to compile, but the test program won't,
and I'm not sure what's wrong.

I changed the Makefile with an eye towards platform-independence, but I
still have some linux-specific stuff in it. Here's what it looks like:

# Note: this makefile has been tested with gcc version 2.95.3-5 (cygwin
special)
# under Windows 2000 using Curl 7.9.5 and OpenSSL 0.9.6c

TARGET = javacurl.so
OBJS = javacurl.o
CC = gcc
CFLAGS = -c -v
JDK_HOME = /usr/local/j2sdk1.4.1
PLATFORM = linux
export CLASSPATH=.

# Note: with JDK1.3 you might have to replace "__int64" in jni_md.h by
"signed long"
# if you are encountering any compilation problem
CPPFLAGS = -I$(JDK_HOME)/include -I$(JDK_HOME)/include/$(PLATFORM)
-I./include

# Note: the libraries used below are for libcurl with SSL. You will
probably need to
# rebuild OpenSSL under Cygwin and then rebuild libcurl with SSL
support. Using
# the default libcurl.a from the Curl distribution is likely to cause a
failure
# at link time
LDFLAGS = -v -shared -fpic -L. -lcurl -lssl -lcrypto

all: CurlGlue.h CurlGlue.class javacurl.o $(TARGET) test.class

# Note: CurlGlue needs to be able to load javacurl.dll from the current
directory, or
# wherever it is stored. Update java.library.path as needed
test:
        java -Djava.library.path=./ test

javacurl.o: javacurl.c CurlGlue.h
        $(CC) $(CPPFLAGS) $(CFLAGS) $<

CurlGlue.h: CurlGlue.java CurlGlue.class
        javah CurlGlue
        touch CurlGlue.h

test.class: CurlGlue.class javacurl.o
        javac test.java

CurlGlue.class: CurlGlue.java
        javac $<

$(TARGET): $(OBJS)
        $(CC) -o $(TARGET) $(OBJS) $(LDFLAGS)

clean:
        rm -f javacurl.o CurlGlue.h CurlGlue.class

This appears to get me a javacurl.so, but I have no idea whether it
works, because compiling test.java failed with this error:

javac test.java
test.java:4: '.' expected
import CurlGlue;
                ^
test.java:5: '.' expected
import CurlWrite;
                 ^
2 errors
make: *** [test.class] Error 1

The '.' expected seems to me to imply that it wants CurlGlue and
CurlWrite to be in a package. I experimented a little bit with that
(using "package libcurl;" although I suppose it should really be
"package se.haxx.curl;") and it was quite a bit more complex. I got
test.java to compile though, although I couldn't run it because it said
it couldn't find main (???).

So, a couple of questions:

1) Does anyone know how I might be able to fix my test.java compile
errors _without_ putting the interface code into a package?

2) Should I fix up the code to use a package?
2a) "libcurl" or "se.haxx.curl" or something else?

3) Does anyone working in a different environment want to help come up
with a truly platform-independent Makefile? Linux is the only really
convenient development environment I have to work on this with.

Forrest

--
forrest_at_abstractfactory.org
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
Received on 2003-08-07