This site requires JavaScript, please enable it in your browser!
Greenfoot back
bpiltin@unitedisd.org
bpiltin@unitedisd.org wrote ...

2012/4/14

Creating a Library

Hi there! I am new to this forum and I did a quick search to no avail... I wanted to package some classes I wrote in Greenfoot into a library that my students can download and import into their own scenarios. Is there any way to do this from within the Greenfoot IDE? I tried putting the classes into their own package and it wouldn't let me. I would have done it through eclipse, but I can't get Greenfoot to work as an importable library from within eclipse either. Any help would be appreciated. Thanks!
drhorriblejr drhorriblejr

2012/4/14

#
I do not know quite how to help you but I did something like what your trying to do before It is packed with custom commands and things like that. I'm not sure if this will help but if it will...Heres the url: http://www.greenfoot.org/scenarios/4767 PS: When you go to the site click "Open in Greenfoot".
That's kind of you to try to help. I'm actually an APCS teacher and I wrote a couple of frameworks that I wanted my students to use. One is for GUI objects and the other is some file i/o and networking stuff. I didn't want them to have to copy all of the classes one by one into their projects and simply wanted them to use an import statement for them. I wrote them in Greenfoot so they could see how it was done and view the source, but when it comes to using them I simply want them to import them as library classes.
drhorriblejr drhorriblejr

2012/4/14

#
Oh okay :D
rick rick

2012/4/14

#
Bpiltin, if you have full access to the greenfoot installation just drop the .jar files into the directory "Path to Greenfoot/greenfoot/lib/userlib/" The README.txt in that directory says:
The userlib directory is used by BlueJ as a repository of class libraries (as either jar or zip files). Class libraries in this directory are recognised and added to BlueJ's classpath at start-up. Loaded libraries can be viewed via the User Library List displayed in the Preferences dialog accessible via the Tools>Preferences...>Libraries menu option. Libraries placed here will be accessible by all BlueJ projects and all users.
Wherever it states "BlueJ" just read "Greenfoot" :-) You can also provide your students with the .jar files so that they can put it into a directory of their own choice which they will have to add in the "Libraries" Preferences.
The problem is that I wrote the classes using the Greenfoot IDE. It won't seem to let me put the classes in their own package. I try to create a directory structure under the project folder as well and this doesn't seem to help. My assumption was that I could just put the classes in their own package, export them as a .jar file and then import them using the method you stated above. Am I mistaken? Again, any help would be appreciated.
davmac davmac

2012/4/16

#
You can have classes in libraries, but they won't show up in the Greenfoot interface. Is this the problem? I.e. you want the classes to show in the interface? If so I'm afraid there's no solution other than copying the classes that you want to be visible into the project. (You don't have to copy the source code in, if you don't want to - just the .class file).
Importing class libraries isn't the problem really, it's that I'm trying to create a class library through Greenfoot itself. I wanted to show the kids how to make their own class libraries, and so I wrote a GUI API based around the Actor and MouseInfo classes and the drawing methods from GreenfootImage. I was going to compile and build it in eclipse, but then the Greenfoot .jar seems more like an installer than a class library so I couldn't compile in eclipse. My only option then was to try to put my classes in a package and use the .jar that Greenfoot builds as a class library for them to import. The problem was that I couldn't actually put any of my classes into a package of their own so I'm not sure how I could make a library without packages. Does that make sense?
davmac davmac

2012/4/16

#
Importing class libraries isn't the problem really, it's that I'm trying to create a class library through Greenfoot itself
Ok, I think I understand. It's not really supported, though; Greenfoot not supporting Java packages is one issue - and when you export a jar file from Greenfoot, you're exporting an application rather than a library (you could still use it as a library and refer to classes within it, from Eclipse; I don't understand why that didn't work for you).
Ok. I'll forget trying to make the packages from within Greenfoot. Is there any way that I can compile my library against the Greenfoot classes from within eclipse? I can't see an easy way to import the Greenfoot package into eclipse so that I can compile them. I tried to add the english/api/greenfoot source directory to my eclipse project, but there are still a bunch of classes that are missing. I can't seem to find them anywhere. Is there a Greenfoot.jar library that I can compile my classes against?
Problem Fixed! I found that the classes for Greenfoot are located in C:\Program Files\Greenfoot\lib\greenfoot\standalone. I added that to my build path and I was able to compile. Thanks for all of your help!
You need to login to post a reply.