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.
IndexProcessing DevelopmentLibraries,  Tool Development › Help with making libraries...
Page Index Toggle Pages: 1
Help with making libraries... (Read 1990 times)
Help with making libraries...
Sep 17th, 2005, 3:45am
 
I don't know. Maybe I should have taken a course on Java.

I don't understand how to create a library... AT ALL. I'm reading the instructions four or five times now and there's no clear way to do it.

From the howto.txt:

A very basic library example:

Code:

package libraryexample;

public class BoringLibrary {
PApplet parent;

public BoringLibrary(PApplet parent) {
this.parent = parent;
parent.registerDispose(this);
}

public void dispose() {
// anything in here will be called automatically when
// the parent applet shuts down. for instance, this might
// shut down a thread used by this library.
}
}


What is all this? The line "package libraryexample;" immediately gives me an error during compile...

When I'm writing a library, do I actually enclose all of my functions and classes within "public class className"?

And after I fit my code into this standard, what do I do? Do I hit play, and take the .jar out? This doesn't seem to work (compile error: java.lang.InstantiationException: BoringLibrary)

The howto.txt says:

Quote:
Creating .jar Files For Your Library

Since your code is inside a package, you need to make sure that its
inside subfolders in the .jar file. It should be noted that jar files
are simply .zip files (they can be opened with WinZip or Stuffit) with
a "manifest" file.

In the past, you may have used:
javac *.java
to compile your files. Once they're inside a packages, you must use:
javac -d . *.java
which will create folders and subfolders for the packages. For
instance, for all the stuff in processing.core.* it would create:

processing/ ->
 core/ ->
   PApplet.class
   PGraphics.class
   ..etc

then you can jar that stuff up using:
jar -cf core.jar processing
or with the command line info-zip utility:
zip -r core.jar processing



Typing javac in console gives me a:

"'javac' is not recognized as an internal or external command, operable program or batch file."




Eh. Totally confused here. Anyone have a step-by-step way to do it? It can't be this hard...
Re: Help with making libraries...
Reply #1 - Sep 17th, 2005, 3:54am
 
Testing something else now.

I'm making the SVGImport a library.

I've stuck all of my functions and classes into a PDE, compiled it.

It results with a .jar and a .java file in the /applet folder.

I put these in a new library folder called svgimport/library and placed these into processing/libraries.

I started a new pde and imported svgimport library.

Instead of placing import processing.svgimport.*; into my code, it placed import processing.core.*;.

What's the deal?

Please help, thanks!
Re: Help with making libraries...
Reply #2 - Sep 17th, 2005, 5:05pm
 
you're just missing the fourth paragraph of the library howto.. in libraries/howto.txt or http://dev.processing.org/libraries/

It is not recommended that you try to build libraries from within
Processing itself. The PDE is built with the sole purpose of creating
short sketches that are part of PApplet that have a few files at most.
We don't plan to extend the PDE to also support developing libraries
(or tools, once those are enabled) because then it simply becomes like
any other IDE that is quickly too general for our target audience.
Users who are advanced enough in their programming skills to build
libraries should almost always be skilled enough to use another IDE
like Eclipse or something else (if they aren't already) to build
their library.

i'll change that to "you cannot" rather than "it is not recommended". p5 assumes everything is a PApplet, and that's gonna break everything.
Re: Help with making libraries...
Reply #3 - Sep 19th, 2005, 1:44am
 
Hey Ben
Thanks for the addition.

Hmm.. so in order to make a library I need to compile with java itself. This means I need the JDK (also named J2SE?) right?

I'm installing it now to check.

I feel that I should learn this anyways. I don't know much compiler stuff or porting to other platforms ... but I do know how to write code. It's time to break out of this shell.

Just one question for now. Do I put everything in a .java file to compile? Is the .java file simply a text file? Thx..
Re: Help with making libraries...
Reply #4 - Sep 19th, 2005, 1:51am
 
Okay... installed J2SE. No javac command...
trying some more...


*edit*

Document says:

Quote:
In the past, you may have used:
javac *.java
to compile your files. Once they're inside a packages, you must use:
javac -d . *.java
which will create folders and subfolders for the packages.


I'm just stuck right here. Please help.

Typing javac in command prompt gives me:
Quote:
'javac' is not recognized as an itnernal or external command, operable program or batch file.
Re: Help with making libraries...
Reply #5 - Sep 19th, 2005, 2:12am
 
you need to add the folder that contains javac to your PATH environment variable.

so go to Control Panels -> System -> Advanced (?) -> Environment Variables (something like that.. i'm on my mac right now) and look for the PATH setting.

add c:\j2se-1.4.2_05\bin (or wherever it's installed) to the listing. then re-open your command prompt and see if javac works at that point.

there's also eclipse...
Page Index Toggle Pages: 1