We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › problems creating a library
Page Index Toggle Pages: 1
problems creating a library (Read 842 times)
problems creating a library
Feb 27th, 2006, 3:31pm
 
Hi,

I'm having some problems writing a library for processing.

I've got a java file that defines a class called "BuoyCommunicator".  This java files declares itself part of the package "processing.buoycomm".  I can (successfully) compile the java file into a class file, using the command:
javac -classpath pathToProcessingJar BuoyCommunicator.java

I then create a jar file from the resulting class file:
jar -cf buoycomm.jar BuoyCommunicator.class

Then I copy the jar file in a directory called "library" inside the folder "buoycomm" in the libraries directory of processing. Eg:
cp buoycomm.jar processingPath/libraries/buoycomm/library/

My library then appears on Processing's "import library" menu.  However, when I try to import the library, no import statement appears at the top of the sketchbook.

Also, if I try and import the library by hand by adding the statement
import "processing.buoycomm.*";
to the top of the sketchbook and compile, I get an error that jikes cannot find the package processing.buoycomm, even though it says its looked in buoycomm.jar.

I think maybe I'm missing something obvious.... any ideas?  Help most appreciated!

Many thanks.
Re: problems creating a library
Reply #1 - Feb 27th, 2006, 4:02pm
 
Ok, I've realised the problem.  The structure of the jar file has to reflect the package structure.
So I made the jar file with the struture:
buoycomm.jar:
          processing\buoycomm\BuoyCommunicator.class

And placed buoycomm.jar inside path\processing\libraries\buoycomm\library\

And now all is fine!  Perhaps this could be stated explicitly in the library howto file?

cheers,


Re: problems creating a library
Reply #2 - Feb 27th, 2006, 4:02pm
 
try:

javac -source 1.3 -target 1.1 -d . -classpath pathToProcessingJar BuoyCommunicator.java
jar -cf buoycomm.jar processing\*

the processing\* bit is because using -d . create a directory structure along the lines of the "package" line, and puts the compiled files in there.

Also, I think I've seen it written that processing.* namespace shoudl only be used for processing itself, not the libraries, so you may want to change it to complext.buoycomm to keep it caonsistent with the other libraries.

Edit: see you solved it at the time I posted. The howto does mention the path part, in the section "Creating .jar Files For Your Library"
Re: problems creating a library
Reply #3 - Feb 27th, 2006, 5:37pm
 
near as i can tell, all this is already in the howto.txt, including the note about not using processing.* as a prefix for any packages (in the final section). is there something i'm missing?
Re: problems creating a library
Reply #4 - Feb 27th, 2006, 11:28pm
 
Yes, I apologise, this information is in the howto.txt.    I'd missed the significance of the javac -d switch in the section "Creating .jar Files For Your Library"

I was primarily working from the "very simple example".  Now my only suggestion is to have the jar file structure info here too.

The comments about the processing namespace are very clear!

Thank you both for your help.

Page Index Toggle Pages: 1