Problem with transofrmation, jar or classpath problem.

View: New views
1 Messages — Rating Filter:   Alert me  

Problem with transofrmation, jar or classpath problem.

by sosna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I am trying to transform point from one crs to another. I wrote following code:

public static void main(String[] args) {
    //
                CoordinateReferenceSystem sourceCRS = null;
                CoordinateReferenceSystem destCRS = null;
               
                GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
                WKTReader reader = new WKTReader( geometryFactory );
               
                Point p = null;
                try {
                        p = (Point) reader.read("POINT(1 2)");
                } catch (ParseException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                }
                Point p2 = null;
                try {
                        sourceCRS = CRS.decode("EPSG:4326");
                        destCRS = CRS.decode("EPSG:2176");
                } catch (NoSuchAuthorityCodeException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                } catch (FactoryException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }

           try {
                        MathTransform math =CRS.findMathTransform(sourceCRS, destCRS);
                        try {
                                p2 = (Point) JTS.transform(p, math);
                        } catch (MismatchedDimensionException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } catch (TransformException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                } catch (FactoryException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }
               
                System.out.println("POINT: " + p.toString());
                System.out.println("POINT TRANSFORMED: " + p2.toString());
 
The program works fine under eclipse and i have result as following:

POINT: POINT (1 2)
POINT TRANSFORMED: POINT (113493.97844319436 4040522.2084545777)

The problem is when i generate jar for this project. When i run it using: java -jar ctd.jar i have following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/opengis/referenci
ng/FactoryException
Caused by: java.lang.ClassNotFoundException: org.opengis.referencing.FactoryExce
ption
        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)
Could not find the main class: CoordinateTransformer. Program will exit.

I have following jars in project:

geoapi-2.2-M1.jar
gt-api-2.5.2.jar
gt-epsg-hsql-2.5.2.jar
gt-main-2.5.2.jar
gt-metadata-2.5.2.jar
gt-referencing-2.5.2.jar
hsqldb-1.8.0.7.jar
jsr-275-1.0-beta-2.jar
jts-1.9.jar
vecmath-1.3.1.jar

What i am doing wrong? Could someone tell me where is hsql database file ??