- Java Advanced Imaging 1.1.2 For JDK
Running the Spearfish demo
There are currently two ways to run the Spearfish demo:
- Use gt2-spearfishdemo.zip
- Compile and run the java code yourself
- From the command line
- Using an IDE like NetBeans
The SpearfishSample.class, geotools 2.0rc1 jar files (including gt2-arcgrid.jar) and data, were packaged into a single zip file (gt2-spearfishdemo.zip). This can be downloaded from the attached files on the Map and style tutorial .
On windows and Mac OSX you should be able to run this by unzipping the *.zip file and double-clicking on SpearfishDemo.jar. On linux, (and windows and Mac OSX) the demo can be run from the command line using the following command (from within the unzipped gt2-spearfishdemo directory):
The SpearfishDemo.jar file has a manifest, which tells the java interpreter the class to run and the additional jar files that it needs on the classpath.
Compiling and running the code
The following is a list of files you need to run SpearfishSample.java
- geotools-bin-2.0.RC1.zip - the geotools 2.0rc1 release
- SpearfishSample.java - the tutorial code
- sampleData.zip - data for the tutorial code
Prepare the files
First, unzip geotools-bin-2.0.RC1.zip. For the following discussion, the rc1 zip file was extracted to <some directory>\rc1.
Next place the SpearfishSample.java file in <some directory>\TESTGT2\org\geotools\demo\gui. The org\geotools... directory structure is the java package for the SpearfishSample class.
Then extract sampleData.zip into <some directory>\TESTGT2\org\geotools\sampleData
The SpearfishSample.java file must be modified because gt2-arcgrid.jar was not part of the 2.0rc1 release. Comment out the following lines. The line number is before the //:
Compile SpearfishSample.java from the command line
The java interpreter and compiler has a CLASSPATH, which is a list of the directories and jar files where it looks for the *.class files it needs to run a program. This classpath can be set in the CLASSPATH environment variable or passed to the java interpreter with the -classpath flag. See Can you explain CLASSPATH? in the The comp.lang.java FAQ List for more information about the Classpath.
The jar files that you will need on your CLASSPATH are:
- gt2-main.jar - most of the geotools code
- geoapi-1.1.0alpha.jar - geoapi interfaces implemented by Geotools
- gt2-shapefile.jar - shapefile support
- JTS-1.4.jar - geometries (shapefile dependency)
- units-0.01.jar - another dependancy
- vecmath-1.3.jar - another dependency (also part of Java 3D 1.3.1 )
These files are in <some directory>\rc1\module, <some directory>\rc1\plugin or <some directory>\rc1\shared and The CLASSPATH environment variable will look like this:
From within <some directory>\TESTGT2 (assuming the 2.0 rc1 release code is in ..\rc1), you can compile SpearfishSample.java with the following command (all on one line):
Note: you will need to replace the ";" classpath separators with ":" and change the "\" to "/" on linux.
This should produce the file: org\geotools\demos\gui\SpearfishSample.class
Run SpearfishSample.java from the command line
Running SpearfishSample.class is similar to compiling it and can be done with the following command (all on one line):
Since the ArcGridDataSource is missing, the DEM grid will not be shown.
Compiling and running SpearfishSample from NetBeans
Contributed by Herve Cros
- Prepare the files as described above
- Create a new NetBeans project (menu Project/Project manager/new)
- Mount the following jar files (right click on Filesystem and select Mount/Archive Files (also found under the File menu/ Mount Filesystems...))
- <some directory>\rc1\plugin\shapefile\gt2-shapefile.jar;
- <some directory>\rc1\shared\JTS-1.4.jar;
- <some directory>\rc1\shared\vecmath-1.3.jar;
- <some directory>\rc1\shared\geoapi-1.1.0alpha.jar;
- <some directory>\rc1\shared\units-0.01.jar"
- Mount the directory <some directory>\TESTGT2 (right click on Filesystems and select Mount/Local Directory)
- Add the java file to the project (menu windows/Project, then right click on "project" and "Add Existing" then chose the file <some directory>\TESTGT2\org\geotools\demo\gui\SpearfishSample.java
- Project menu /Execute Project ... (or use the Execute button on the toolbar). Netbeans should compile and run SpearfishSample, using all the mounted jar files and directories for the classpath.
List of errors
When there are no jar files specified in CLASSPATH
About 70 errors. ( Package ... does not exist. )
When only gt2-main.jar is specified in CLASSPATH
About 14 errors
If gt2-shapefile.jar is missing.
SpearfishSample.java:15: package org.geotools.data.shapefile does not exist
If JTS-1.4.jar is missing
The error appears when running the SpearfishSample.class
When you forget to include vecmath-1.2.1.jar
The error appears when running the SpearfishSample.class
If you don't comment out ArcGridDataSource
About 3 errors
SpearfishSample.java:14: package org.geotools.data.arcgrid does not exist
When you forget to install Java Advanced Imaging
The error appears when running the SpearfishSample.class
I had tested this tutorial on windows and it works very well !
Some precisions to make it run with netbeans :
note : of course, first of all you have to download the files geotools-bin-2.0.RC1.zip, SpearfishSample.java, and sampleData.zip. And to unzip them as describe in this article
Posted by crv at Aug 16, 2004 12:46
I could not compile SpearfishSample.java in windows.
Reported error were as follows:
org/geotools/demo/gui/SpearfishSample.java 1 cannot resolve symbol
Any suggestion to deal with this issue? Thanks.
Posted by at Sep 16, 2004 13:47
org.geotools.styling.StyleBuilder appears to be in the 2.0rc1 release. Therefore I would assume this problem is caused by a classpath issue. Check that you have gt2-main.jar on your classpath.
Posted by rschulz at Sep 20, 2004 23:08
The SpearfishSample.java file compiled successfully , but unable to run the file:
I have my personal computer with Intel P-III 700 Mhz processor and 256 MB ram running Windows XP professional.
I have installed JDK, j2sdk1.4.2_05 and JAI jai-1_1_2-lib-windows-i586-jdk, JRE for JAI jai-1_1_2-lib-windows-i586-jre.
On the C: drive I created the folder geoapps
In geoapps folder, I unzipped the file geotools-bin-2.0.RC1.zip in the folder geotools-bin-2.0.RC1
than as per your instruction in geoapps folder I created the folders org\geotools\demo\gui and kept SpearfishSample.java
Than as per your instruction I modify the SpearfishSample.java because gt2-arcgrid.jar was not part of the 2.0rc1 release. I Comment out the following lines. The line number is before the //:
14 //import org.geotools.data.arcgrid.ArcGridDataSource;
than as per your instrution in C:\geoapps\org\geotools folder I unzipped the sampledata.zip file in the folder sampledata
then i created the environment variable classpath and made the following enteries for that in System Properties:
Now when everything has been set, than on the command prompt, I compiled the SpearfishSample.java in the folder C:\geoapps\org\geotools\demo\gui\
It comiled successfully, but when I run the class file it throws following Exception:
Exception in thread "main" java.lang.NoClassDefFoundError: SpearfishSample (wron
Now I also downloaded the gt2-spearfishdemo.zip file, I extract this file in C:\test\ folder; now with the same settings as I mentioned above, I run the C:\test\SpearfishDemo.jar and it is running perfectly.
Please guide me how to run the source code of the application.
Posted by anuraag_dixit at Sep 28, 2004 21:44
This is a classic java newbi mistake (I made it a few years ago when I started with java also).
Java looks for classes on the classpath and the current directory (it is best to make sure '.' is also on the CLASSPATH so that java will search the current directory for class files).
Now, the short answer to your problem is you should be in the C:\geoapps directory and run the command:
> java org.geotools.demo.gui.SpearfishSample
The org.geotools.demo.gui part is the package for the class which is part of the full class name for SpearfishSample. Java looks in the current directory (C:\geoapps) and finds org\geotools\... which is the beginning of the class name. So again, C:\geoapps needs to be on your classpath or you need to execute the java command from here so it places the current directory ('.') on the classpath.
When you ran java in C:\geoapps\org\geotools\demo\gui, java looked for org.geotools.demo.gui.SpearfishSample here. It could not find it since only SpearfishSample is in this directory.
Also note that the use of the CLASSPATH environment variable is not the favoured method to run this (you end up having to resetting it for every different java program you use). A better method is to pass the classpath to java when you call it. For example use:
> java -classpath ".; my; classpath;" some.class.file
To save yourself some typing, you can place the above command in a batch file (*.bat) and execute that (or use ant, maven, eclipse, netbeans, etc).
Posted by rschulz at Sep 29, 2004 01:56
first of all i thank you for responding back instatly , but sorry to tell you that i still unable to run the application this time it has thrown different exception:
Posted by anuraag_dixit at Sep 30, 2004 14:21
Unfortunately, the only thing I can think of is that the c:\j2sdk1.4.2_04\lib; on your classpath is unnecessary.
A google for this error indicates that it may be a problem with the released jars being built for a newer jvm than you are using. If you cannot solve this, try posting this question to the geotools user email list (you will get more responses there).
Posted by rschulz at Sep 30, 2004 23:59
D:\JBuilder9\jdk1.4\bin\javaw -classpath "D:\tools\opengis\gt2demo\SpearfishPostGIS\classes;D:\gthome\plugin\postgis\gt2-postgis.jar;D:\gthome\plugin\shapefile\gt2-shapefile.jar;D:\gthome\shared\batik-1.5.jar;D:\gthome\shared\batik-bridge-1.5.jar;D:\gthome\shared\batik-css-1.5.jar;D:\gthome\shared\batik-dom-1.5.jar;D:\gthome\shared\batik-gvt-1.5.jar;D:\gthome\shared\batik-rasterizer-1.5.jar;D:\gthome\shared\batik-svg-dom-1.5.jar;D:\gthome\shared\batik-transcoder-1.5.jar;D:\gthome\shared\batik-xml-1.5.jar;D:\gthome\shared\geoapi-20041011.jar;D:\gthome\shared\JTS-1.4.jar;D:\gthome\shared\mailapi-1.3.jar;D:\gthome\shared\mockrunner-0.2.jar;D:\gthome\shared\opengis-legacy-0.1.jar;D:\gthome\shared\units-0.01.jar;D:\gthome\shared\vecmath-1.3.jar;D:\gthome\module\gt2-main.jar;D:\gthome\plugin\postgis\lib\log4j-1.2.8.jar;D:\gthome\plugin\postgis\lib\postgis-driver-1.0.jar;D:\gthome\plugin\postgis\lib\wkb4j-1.0-RC1.jar;C:\Program Files\PostgreSQL\8.0-beta2-dev3\jdbc\pg74.215.jdbc3.jar;D:\gthome\extension\graph\gt2-graph.jar;D:\gthome\extension\validation\gt2-validation.jar;D:\JBuilder9\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;D:\JBuilder9\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;D:\JBuilder9\jdk1.4\jre\lib\charsets.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\dnsns.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\ldapsec.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\localedata.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\sunjce_provider.jar;D:\JBuilder9\jdk1.4\jre\lib\im\indicim.jar;D:\JBuilder9\jdk1.4\jre\lib\jaws.jar;D:\JBuilder9\jdk1.4\jre\lib\jce.jar;D:\JBuilder9\jdk1.4\jre\lib\jsse.jar;D:\JBuilder9\jdk1.4\jre\lib\rt.jar;D:\JBuilder9\jdk1.4\jre\lib\sunrsasign.jar;D:\JBuilder9\jdk1.4\lib\dt.jar;D:\JBuilder9\jdk1.4\lib\htmlconverter.jar;D:\JBuilder9\jdk1.4\lib\tools.jar" spearfishpostgis.postgistestconn
Posted by at Nov 26, 2004 20:30
When is the Arc Grid stuff going to be added back into the development tree? Has some other package rendered it obsolete? I have a need for displaying DEM files, but I'm new at all this and I'm not sure what to do about it right now.
Posted by sapienza at Dec 07, 2004 17:19
ArcGridDataSource was replaced by the new GridCoverageExchange implementation. SpearfishSample in the svn (DNS issues right now) demo directory uses the new code. This should be in the upcomming 2.1 release.
Posted by rschulz at Dec 13, 2004 00:11
I can't download the java source or the data zip file, did the files get removed or moved?
Posted by edward303 at Mar 01, 2006 17:00