This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zamoht
Zamoht wrote ...

2014/5/15

Importing Greenfoot classes into Eclipse

1
2
Zamoht Zamoht

2014/5/15

#
How can I import lets say the GreenfootSound class into one of my projects in Eclipse? I got the Greenfoot open source files, but I'm not quite sure where to go from here.
Zamoht Zamoht

2014/5/15

#
Guess I have to follow the guides in the source folder and setup the whole thing.
davmac davmac

2014/5/15

#
Guess I have to follow the guides
follow the guides
guides
... ;) That's what they're there for!! I'd suggest that if you don't know Eclipse well enough to manage importing classes into an existing project, you're probably taking on something that's beyond you. Nevertheless, good luck. If you need more help, please explain more about what you're trying to do; that way people can point you in the right direction much more easily.
Zamoht Zamoht

2014/5/15

#
Okay maybe this is beyond me, but I have to learn it from somewhere and I really want it to work. Now I've tried to follow the guide for setting up bluej, but when I run it I get a ton of errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Boot: tools.jar not found. Potential problem for execution.
java.lang.Error: Unresolved compilation problems:
    The import com.apple cannot be resolved
    The import com.apple cannot be resolved
    The import com.apple cannot be resolved
    QuitResponse cannot be resolved to a type
    Application cannot be resolved to a type
    Application cannot be resolved
    com.apple cannot be resolved to a type
    AppEvent cannot be resolved to a type
    com.apple cannot be resolved to a type
    AppEvent cannot be resolved to a type
    com.apple cannot be resolved to a type
    AppEvent cannot be resolved to a type
    QuitResponse cannot be resolved to a type
    QuitResponse cannot be resolved to a type
    com.apple cannot be resolved to a type
    AppEvent cannot be resolved to a type
    QuitResponse cannot be resolved to a type
    QuitResponse cannot be resolved to a type
    QuitResponse cannot be resolved to a type
 
    at bluej.Main.<init>(Main.java:32)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at bluej.Boot.bootBluej(Boot.java:323)
    at bluej.Boot.main(Boot.java:168)
I have 2.060 errors and 491 warnings in the project. Most of the errors says "Something cannot be resolved to a type". Where "Something" is many different class names. So the first thing I did was that I created a new Java Project and named it "bluej". Then I extracted the source and pasted the whole content of the bluej folder into my project: After that I tried to setup the source and output paths: Lastly I went to the Run Configuration and made the following changes to a new run option I named "BlueJ": You might have facepalmed a few times looking through the steps I made, but anyway I would like some help with the problem. Thanks in advance!
davmac davmac

2014/5/15

#
The import com.apple cannot be resolved
This implies you don't have the AppleJavaExtensions.jar on your build path (in the libraries tab). Did you follow the entire first step from the guide?
In the Libraries tab: * add all the necessary jars from the lib directory: AppleJavaExtensions.jar, bjdoclet.jar, diffutils-1.2.1.jar, httpclient-4.1.jar, httpcore-4.1.jar, httpmime-4.1.1.jar, junit-4.8.2.jar, org-netbeans-lib-cvsclient.jar, svnkit-javahl.jar, trilead.jar * You also need to add the 'tools.jar' file from your JDK (except in case of Mac JDK 1.6).
Please read the guide carefully and follow it exactly.
Zamoht Zamoht

2014/5/15

#
Wauw... I missed those steps, I'm sorry about that. I still have a lot of warnings and the console prints out "class Boot: tools.jar not found. Potential problem for execution.", but it seems to run without any problems (I did remember to add the tools.jar to the libraries tab). Thanks for your time and help.
Zamoht Zamoht

2014/5/15

#
Discovered that the tools.jar is found by the following method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 * Get the URL of the  current tools.jar file
 * Looks for lib/tools.jar in the current javaHome
 * and in the parent of it.
 * tools.jar is needed on many (but not all!) systems. Currently,
 * MacOS is the only system known to us without a tools URL, but
 * there may be others in the furure. This method returns null
 * if tools.jar does not exist.
 *
 * @return   The URL of the tools.jar file for the current Java implementation, or null.
 * @exception  MalformedURLException  for any problems with the URL
 */
private URL getToolsURL()
    throws MalformedURLException
{
    String osname = System.getProperty("os.name", "");
    if(osname.startsWith("Mac"))     // we know it does not exist on a Mac...
        return null;
 
    File toolsFile = new File(javaHomeDir, "lib/tools.jar");
    if (toolsFile.canRead())
        return toolsFile.toURI().toURL();
 
    File parentDir = javaHomeDir.getParentFile();
    toolsFile = new File(parentDir, "lib/tools.jar");
    if (toolsFile.canRead())
        return toolsFile.toURI().toURL();
    else {
        // on other systems where we don't find it, we just warn. We don't expect it
        // to happen, but you never know...
        System.err.println("class Boot: tools.jar not found. Potential problem for execution.");
        return null;
    }
}
For some reason "javaHomeDir" is equal to "new File(System.getProperty("java.home"));". System.getProperty("java.home") links to the JRE on my system and therefore isn't able to find the tools.jar. I fixed the problem by copying the tools.jar into the JRE lib, but this seems like an odd fix. I will try to find a way to look for the JDK folder instead and change the code.
davmac davmac

2014/5/15

#
You need to run BlueJ using the JDK rather than the JRE, then the warning will disappear.
Zamoht Zamoht

2014/5/15

#
Any specific reason why Eclipse uses the JRE by default? I went to Window->Preferences->Java->Installed JREs and changed the path from my JRE to my JDK. It feels weird to change what is labeled as "Installed JREs" to a JDK, but I did the job. Now for the Greenfoot setup. Once again, thanks a lot.
Zamoht Zamoht

2014/5/15

#
I follow the guide for setting up Greenfoot in Eclipse. I am sure I followed the first step correctly. I don't get the second step and at the third step I ran the bluej build.xml in the ant view without any problems, but when I did the same for the Greenfoot build.xml I get the following error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Buildfile: D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml
update-images:
     [copy] Copying 1 file to D:\home\davmac\workspace\greenfoot\package
     [copy] Copying 1 file to D:\home\davmac\workspace\greenfoot\package
     [copy] Copying 1 file to D:\home\davmac\workspace\greenfoot\boot\src\bluej
     [copy] Copying 1 file to D:\home\davmac\workspace\greenfoot\package\macfiles\Greenfoot.app\Contents\Resources
     [copy] Copying 1 file to D:\home\davmac\workspace\greenfoot\package\macfiles\Greenfoot-legacy.app\Contents\Resources
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
     [copy] Copying 1 file to D:\Program Files (x86)\eclipse\workspace\greenfoot\images
init:
     [copy] Copying 20 files to D:\Program Files (x86)\eclipse\workspace\greenfoot\classes
     [copy] Copying 5 files to D:\home\davmac\workspace\greenfoot\lib
    [mkdir] Created dir: D:\Program Files (x86)\eclipse\workspace\greenfoot\package
compile:
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:197: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
     [rmic] RMI Compiling 16 classes to D:\Program Files (x86)\eclipse\workspace\greenfoot\classes
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.PackageAlreadyExistsException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in interface rmiextension.wrappers.RProject.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in rmiextension.wrappers.RProjectImpl.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in rmiextension.wrappers.RProjectImpl.
     [rmic] error: Class bluej.extensions.ProjectNotOpenException not found in rmiextension.wrappers.RProjectImpl.
...
     [rmic] D:\Program Files (x86)\eclipse\workspace\greenfoot\classes\rmiextension\wrappers\event\RInvocationEventImpl_Stub.java:199: Class bluej.extensions.BPackage not found.
     [rmic]     public bluej.extensions.BPackage getPackage()
     [rmic]                                      ^
     [rmic] D:\Program Files (x86)\eclipse\workspace\greenfoot\classes\rmiextension\wrappers\event\RInvocationEventImpl_Stub.java:205: Class bluej.extensions.BPackage not found.
     [rmic]         return ((bluej.extensions.BPackage) $result);
     [rmic]                                  ^
     [rmic] D:\Program Files (x86)\eclipse\workspace\greenfoot\classes\rmiextension\wrappers\event\RInvocationEventImpl_Stub.java:209: Class bluej.extensions.BPackage not found.
     [rmic]         bluej.extensions.BPackage $result;
     [rmic]                         ^
     [rmic] D:\Program Files (x86)\eclipse\workspace\greenfoot\classes\rmiextension\wrappers\event\RInvocationEventImpl_Stub.java:212: Class bluej.extensions.BPackage not found.
     [rmic]             $result = (bluej.extensions.BPackage) in.readObject();
     [rmic]                                        ^
     [rmic] D:\Program Files (x86)\eclipse\workspace\greenfoot\classes\rmiextension\wrappers\event\RInvocationEventImpl_Stub.java:220: Variable $result may not have been initialized.
     [rmic]         return $result;
     [rmic]                ^
     [rmic] D:\Program Files (x86)\eclipse\workspace\greenfoot\classes\rmiextension\wrappers\event\RInvocationEventImpl_Skel.java:111: Class bluej.extensions.BPackage not found.
     [rmic]         bluej.extensions.BPackage $result = server.getPackage();
...
     [rmic] 187 errors
 
BUILD FAILED
D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:202: Rmic failed; see the compiler error output for details.
 
Total time: 1 second
Hopefully this will be my last question. Why does this error occur? Next time someone tells me that something is beyond me I will listen.
davmac davmac

2014/5/15

#
Have you edited the build.properties file for both BlueJ and Greenfoot? What settings did you provide for Greenfoot?
Zamoht Zamoht

2014/5/15

#
I tried to change the build.properties. They look like this: BlueJ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#####################################################################
##               BlueJ build properties
#####################################################################
##
## This file contains user system related properties for building
## bluej via ant. Tis file gets includes into bluej's main build.xml
## via the property ant task. This means build.xml does not need to
## contain machine specific config information.
##
#####################################################################
 
#####################################################################
# the build_java_home is used to find the compiler to fork and the
# tools.jar file to use with it. Note that in general all
# compilation should be done on the minimum supported JDK for
# BlueJ (which is currently Java 6)
#####################################################################
#build_java_home=c:/Program Files/Java/jdk1.6.0_13
#build_java_home=/opt/jdk1.6.0
#build_java_home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6
build_java_home=/opt/jdk1.7.0_40
 
# java_command_dir_name should normally be 'bin', except on Mac (Java 6
# and prior) where it should be 'Commands'
 
java_command_dir_name=bin
#java_command_dir_name=Commands
 
#####################################################################
# the run_java_home is used to find the jvm to run and the
# corresponding tools.jar file. Usually the same as above.
#####################################################################
run_java_home=${build_java_home}
 
#####################################################################
# The JDK is bundled with the non-legacy Mac build.
#####################################################################
mac_bundled_jdk_path=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk
 
#####################################################################
# Pass this property down to lower build files to find various jars etc
# Makes it easier if the current directory is not bluej_home
#####################################################################
bluej_home=D:\Program Files (x86)\eclipse\workspace\bluej
#bluej_home=/Users/mik/Development/bluej
 
#####################################################################
# This property defines where the "Wix" bin directory (containing
# the Wix executables) is. Needed for building the .msi Windows
# installer.
#####################################################################
wix_bin=C:/Program Files/Windows Installer XML v3.5/bin
Greenfoot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#####################################################################
##               Greenfoot build properties
#####################################################################
##
## This file contains user system related properties for building
## greenfoot via ant. Tis file gets includes into greenfoot's main
## build.xml via the property ant task. This means build.xml does not
## need to contain machine specific config information.
##
#####################################################################
 
 
# Location of the BlueJ project 
#bluej.projectdir=/home/davmac/workspace/greenfoot
bluej.projectdir=D:\Program Files (x86)\eclipse\workspace\bluej
 
# Location of the Greenfoot project 
greenfoot.projectdir=D:\Program Files (x86)\eclipse\workspace\greenfoot
#greenfoot.projectdir=/home/polle/netbeansWorkspace/greenfoot
 
#####################################################################
# The following is only needed when executing BlueJ from Ant or an
# IDE.
#####################################################################
# tutorial (an URL)
greenfoot.tutorial=file://${greenfoot.projectdir}/resources/tutorial/tutorial.html
# tutorial scenario (a name)
greenfoot.tutorial.scenario=wombats
# location of the scenarios (a File)
greenfoot.scenarios=${greenfoot.projectdir}/scenarios
 
 
#####################################################################
# Which scenario to use when running the standalone viewer.
# This is used for profiling.
#####################################################################
greenfoot.standalone.scenario=${greenfoot.scenarios}/greeps/
greenfoot.standalone.main=Earth
greenfoot.standalone.labels=${greenfoot.projectdir}/labels/english/greenfoot-labels
I still get the errors with the Greenfoot setup, just with the new paths.
davmac davmac

2014/5/16

#
These are Java properties files; you need to either double your backslashes, or use forward slashes, in your paths. Look at the example paths in the BlueJ build.properties file. Also your build_java_home looks like a unix setting, but all your other settings are for Windows.
Zamoht Zamoht

2014/5/17

#
Removed both projects and started over. Got some problems again at the build thing. This time my properties looked like this. BlueJ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#####################################################################
##               BlueJ build properties
#####################################################################
##
## This file contains user system related properties for building
## bluej via ant. Tis file gets includes into bluej's main build.xml
## via the property ant task. This means build.xml does not need to
## contain machine specific config information.
##
#####################################################################
 
#####################################################################
# the build_java_home is used to find the compiler to fork and the
# tools.jar file to use with it. Note that in general all
# compilation should be done on the minimum supported JDK for
# BlueJ (which is currently Java 6)
#####################################################################
#build_java_home=c:/Program Files/Java/jdk1.6.0_13
#build_java_home=/opt/jdk1.6.0
#build_java_home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6
build_java_home=D:/Program Files/Java/jdk1.7.0_40
 
# java_command_dir_name should normally be 'bin', except on Mac (Java 6
# and prior) where it should be 'Commands'
 
java_command_dir_name=bin
#java_command_dir_name=Commands
 
#####################################################################
# the run_java_home is used to find the jvm to run and the
# corresponding tools.jar file. Usually the same as above.
#####################################################################
run_java_home=${build_java_home}
 
#####################################################################
# The JDK is bundled with the non-legacy Mac build.
#####################################################################
mac_bundled_jdk_path=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk
 
#####################################################################
# Pass this property down to lower build files to find various jars etc
# Makes it easier if the current directory is not bluej_home
#####################################################################
bluej_home=D:/Program Files (x86)/eclipse/workspace/bluej
#bluej_home=/Users/mik/Development/bluej
 
#####################################################################
# This property defines where the "Wix" bin directory (containing
# the Wix executables) is. Needed for building the .msi Windows
# installer.
#####################################################################
wix_bin=C:/Program Files (x86)/WiX Toolset v3.8/bin
I am not sure about the mac_bundled_jdk_path. What should I do with it when I use Windows? Remove it or just let it stay as it is? Greenfoot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#####################################################################
##               Greenfoot build properties
#####################################################################
##
## This file contains user system related properties for building
## greenfoot via ant. Tis file gets includes into greenfoot's main
## build.xml via the property ant task. This means build.xml does not
## need to contain machine specific config information.
##
#####################################################################
 
 
# Location of the BlueJ project 
#bluej.projectdir=/home/davmac/workspace/greenfoot
bluej.projectdir=D:/Program Files (x86)/eclipse/workspace/bluej
 
# Location of the Greenfoot project 
greenfoot.projectdir=D:/Program Files (x86)/eclipse/workspace/greenfoot
#greenfoot.projectdir=/home/polle/netbeansWorkspace/greenfoot
 
#####################################################################
# The following is only needed when executing BlueJ from Ant or an
# IDE.
#####################################################################
# tutorial (an URL)
greenfoot.tutorial=file://${greenfoot.projectdir}/resources/tutorial/tutorial.html
# tutorial scenario (a name)
greenfoot.tutorial.scenario=wombats
# location of the scenarios (a File)
greenfoot.scenarios=${greenfoot.projectdir}/scenarios
 
 
#####################################################################
# Which scenario to use when running the standalone viewer.
# This is used for profiling.
#####################################################################
greenfoot.standalone.scenario=${greenfoot.scenarios}/greeps/
greenfoot.standalone.main=Earth
greenfoot.standalone.labels=${greenfoot.projectdir}/labels/english/greenfoot-labels
This time the Greenfoot build printet "BUILD SUCCESSFUL Total time: 12 seconds" In the end, but I got some warnings: Some of these:
1
2
compile:
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:197: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
A whole bunch of these:
1
2
3
4
5
compile-scenarios:
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:240: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:240: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:240: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:240: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
This:
1
[javadoc] D:\Program Files (x86)\eclipse\workspace\greenfoot\common\GifImage.java:43: warning - @overrides is an unknown tag.
This:
1
2
3
4
5
6
7
compile-standalone:
   [delete] Deleting directory D:\Program Files (x86)\eclipse\workspace\bluej\lib\greenfoot\standalone
    [mkdir] Created dir: D:\Program Files (x86)\eclipse\workspace\bluej\lib\greenfoot\standalone
    [javac] D:\Program Files (x86)\eclipse\workspace\greenfoot\build.xml:599: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 115 source files to D:\Program Files (x86)\eclipse\workspace\bluej\lib\greenfoot\standalone
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] 1 warning
And more of those " warning: bootstrap class path not set in conjunction with -source 1.6" Lastly this:
1
[javadoc] D:\Program Files (x86)\eclipse\workspace\greenfoot\src\greenfoot\Actor.java:586: warning - @return tag has no arguments.
I had to add "junit-4.8.2.jar", "AppleJavaExtensions.jar" and "tools.jar" to the Greenfoot project (not in the guide) to get rid of all the errors. When I run the Java Application described at the buttom of the Greenfoot setup guide I get "cannot find splash image: greenfootsplash.jpg" in the console and an "empty" Java Application is added to the Windows process bar. Any thoughts?
Zamoht Zamoht

2014/5/18

#
Got rid of the 1.6 warnings by replacing 1.6 with 1.7 in the build.xml besides that it doesn't seem like it changed anything. The 'includeintruntime' warnings doesn't seem to make any difference (looked it up here ). I can see that "greenfootsplash.jpg" exists at "D:\Program Files (x86)\eclipse\workspace\bluej\boot\src\bluej" and at "D:\Program Files (x86)\eclipse\workspace\greenfoot\resources\images". I would like to know where I can find the piece of code printing out "cannot find splash image: greenfootsplash.jpg" since this could help me figure out where on my system the program is looking for the splash.
There are more replies on the next page.
1
2