This page was started by Anusorn Swasdee to help other Geotools novices run the Spearfish demo from the Maps and styles , and get started using Geotools.
Requirements
As listed in the 2.2 Dependencies section of the Developers Guide, to use some parts of the Geotools library, you will need a recent java 2 runtime or SDK (1.4.2) and the following extra:
- Java Advanced Imaging 1.1.2 For JDK
http://java.sun.com/products/java-media/jai/downloads/download-1_1_2.html
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
Using gt2-spearfishdemo.zip
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):
$ java -jar SpearfishDemo.jar
Or
$ java -classpath "SpearfishDemo.jar" org.geotools.demo.gui.SpearfishSample
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 //:
14 //import org.geotools.data.arcgrid.ArcGridDataSource; 51 //ArcGridDataSource dsDem = new ArcGridDataSource(demURL); 52 //dsDem.setUseGzipCompression(true); 53 //dsDem.setGRASSFormatEnabled(true); 54 //FeatureCollection fcDem = dsDem.getFeatures(); 123 //map.addLayer(fcDem, demStyle);
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:
.;<some directory>\rc1\module\gt2-main.jar; <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
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):
$ javac -classpath ".;..\rc1\module\gt2-main.jar; ..\rc1\plugin\shapefile\gt2-shapefile.jar; ..\rc1\shared\JTS-1.4.jar; ..\rc1\shared\vecmath-1.3.jar; ..\rc1\shared\geoapi-1.1.0alpha.jar; ..\rc1\shared\units-0.01.jar" org\geotools\demo\gui\SpearfishSample.java
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):
$ java -classpath ".;..\rc1\module\gt2-main.jar; ..\rc1\plugin\shapefile\gt2-shapefile.jar; ..\rc1\shared\JTS-1.4.jar; ..\rc1\shared\vecmath-1.3.jar; ..\rc1\shared\geoapi-1.1.0alpha.jar; ..\rc1\shared\units-0.01.jar" org.geotools.demo.gui.SpearfishSample
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
import org.geotools.data.shapefile.ShapefileDataStore;
If JTS-1.4.jar is missing
The error appears when running the SpearfishSample.class
java.lang.NoClassDefFoundError: com/vividsolutions/jts/geom/GeometryFactory
When you forget to include vecmath-1.2.1.jar
The error appears when running the SpearfishSample.class
java.lang.NoClassDefFoundError: javax/vecmath/MismatchedSizeException
If you don't comment out ArcGridDataSource
About 3 errors
SpearfishSample.java:14: package org.geotools.data.arcgrid does not exist
import org.geotools.data.arcgrid.ArcGridDataSource;
When you forget to install Java Advanced Imaging
The error appears when running the SpearfishSample.class
java.lang.NoClassDefFoundError: javax/media/jai/EnumeratedParameter
11 Comments
Hide/Show CommentsAug 16, 2004
Herve Cros
I had tested this tutorial on windows and it works very well !
Some precisions to make it run with netbeans :
<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"
14 //import org.geotools.data.arcgrid.ArcGridDataSource;
51 //ArcGridDataSource dsDem = new ArcGridDataSource(demURL);
52 //dsDem.setUseGzipCompression(true);
53 //dsDem.setGRASSFormatEnabled(true);
54 //FeatureCollection fcDem = dsDem.getFeatures();
123 //map.addLayer(fcDem, demStyle);
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
Sep 16, 2004
Anonymous
I could not compile SpearfishSample.java in windows.
Reported error were as follows:
org/geotools/demo/gui/SpearfishSample.java 1 cannot resolve symbol
symbol : class StyleBuilder
location: package styling
import org.geotools.styling.StyleBuilder;
^
org/geotools/demo/gui/SpearfishSample.java 1 cannot resolve symbol
symbol : class StyleBuilder
location: class org.geotools.demo.gui.SpearfishSample
StyleBuilder sb = new StyleBuilder();
^
org/geotools/demo/gui/SpearfishSample.java 1 cannot resolve symbol
symbol : class StyleBuilder
location: class org.geotools.demo.gui.SpearfishSample
StyleBuilder sb = new StyleBuilder();
^
org/geotools/demo/gui/SpearfishSample.java 1 cannot resolve symbol
symbol : variable StyleBuilder
location: class org.geotools.demo.gui.SpearfishSample
Mark redCircle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED, Color.BLACK, 0);
^
org/geotools/demo/gui/SpearfishSample.java 1 cannot resolve symbol
symbol : variable StyleBuilder
location: class org.geotools.demo.gui.SpearfishSample
Mark yellowTri = sb.createMark(StyleBuilder.MARK_TRIANGLE, Color.YELLOW, Color.BLACK, 0);
^
5 errors
Errors compiling.
------------------------------
Any suggestion to deal with this issue? Thanks.
Sep 20, 2004
Rueben Schulz
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.
Sep 28, 2004
anuraag dixit
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
-> C:\geoapps
In geoapps folder, I unzipped the file geotools-bin-2.0.RC1.zip in the folder geotools-bin-2.0.RC1
-> C:\geoapps\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
-> C:\geoapps\org\geotools\demo\gui\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;
51 //ArcGridDataSource dsDem = new ArcGridDataSource(demURL);
52 //dsDem.setUseGzipCompression(true);
53 //dsDem.setGRASSFormatEnabled(true);
54 //FeatureCollection fcDem = dsDem.getFeatures();
123 //map.addLayer(fcDem, demStyle);
than as per your instrution in C:\geoapps\org\geotools folder I unzipped the sampledata.zip file in the folder sampledata
-> C:\geoapps\org\geotools\sampledata\
then i created the environment variable classpath and made the following enteries for that in System Properties:
.;
c:\j2sdk1.4.2_05\lib;
C:\geoapps\geotools-bin-2.0.RC1\module\gt2-main.jar;
C:\geoapps\geotools-bin-2.0.RC1\plugin\shapefile\gt2-shapefile.jar;
C:\geoapps\geotools-bin-2.0.RC1\shared\JTS-1.4.jar;
C:\geoapps\geotools-bin-2.0.RC1\shared\vecmath-1.3.jar;
C:\geoapps\geotools-bin-2.0.RC1\shared\geoapi-1.1.0alpha.jar;
C:\geoapps\geotools-bin-2.0.RC1\shared\units-0.01.jar
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\
-> C:\geoapps\org\geotools\demo\gui> javac SpearfishSample.java
It comiled successfully, but when I run the class file it throws following Exception:
-> C:\geoapps\org\geotools\demo\gui> java SpearfishSample
Exception in thread "main" java.lang.NoClassDefFoundError: SpearfishSample (wron
g name: org/geotools/demo/gui/SpearfishSample)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
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.
Regards.
Anuraag Dixit (India)
Sep 29, 2004
Rueben Schulz
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).
Sep 30, 2004
anuraag dixit
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:
i run the application in c:\geoapps folder:
C:\geoapps>java -classpath ".;c:\j2sdk1.4.2_04\lib;C:\geoapps\geotools-bin-2.0.R
C1\module\gt2-main.jar;C:\geoapps\geotools-bin-2.0.RC1\plugin\shapefile\gt2-shap
efile.jar;C:\geoapps\geotools-bin-2.0.RC1\shared\JTS-1.4.jar;C:\geoapps\geotools
-bin-2.0.RC1\shared\vecmath-1.3.jar;C:\geoapps\geotools-bin-2.0.RC1\shared\geoap
i-1.1.0alpha.jar;C:\geoapps\geotools-bin-2.0.RC1\shared\units-0.01.jar" org.geot
ools.demo.gui.SpearfishSample
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/geotools/
styling/Symbolizer (Unsupported major.minor version 48.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Sep 30, 2004
Rueben Schulz
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).
Nov 26, 2004
Anonymous
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
java.lang.NullPointerException
at java.net.URI$Parser.parse(URI.java:2933)
at java.net.URI.<init>(URI.java:565)
at org.geotools.data.jdbc.JDBCDataStore.getNameSpace(JDBCDataStore.java:1211)
at org.geotools.data.jdbc.JDBCDataStore.buildSchema(JDBCDataStore.java:1048)
at org.geotools.data.jdbc.FeatureTypeHandler.getFeatureTypeInfo(FeatureTypeHandler.java:200)
at org.geotools.data.jdbc.FeatureTypeHandler.getSchema(FeatureTypeHandler.java:168)
at org.geotools.data.jdbc.JDBCDataStore.getSchema(JDBCDataStore.java:322)
at org.geotools.data.postgis.PostgisDataStore.getFeatureSource(PostgisDataStore.java:994)
at spearfishpostgis.postgistestconn.main(postgistestconn.java:43)
Dec 07, 2004
Tom Sapienza
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.
Dec 13, 2004
Rueben Schulz
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.
Mar 01, 2006
Edward Smith
I can't download the java source or the data zip file, did the files get removed or moved?