Java classpath set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuananh87vn
    New Member
    • Sep 2007
    • 63

    Java classpath set

    hi,
    I'm not familiar with Java but have to use it to slice a map into smaller tiles. Actually I use Batik projects and it has the following .java file:

    ImageTiler.java

    [java]

    package com.ajaxian.ama ps;

    import org.apache.bati k.apps.rasteriz er.DestinationT ype;
    import org.apache.bati k.apps.rasteriz er.SVGConverter ;

    import javax.imageio.I mageIO;
    import java.io.File;
    import java.awt.*;
    import java.awt.image. BufferedImage;

    public class ImageTiler {
    private static final String BASE_DIR = "rc/";
    private static final int TILE_WIDTH = 100;
    private static final int TILE_HEIGHT = 100;

    public static void main(String[] args) throws Exception {
    // create the tiles
    String[][] sources = { { "mapSpain.j pg", "0" },
    {"mapSpain-smaller.jpg", "1"} };
    for (int i = 0; i < sources.length; i++) {
    String[] source = sources[i];
    BufferedImage bi = ImageIO.read(ne w File(BASE_DIR + source[0]));
    int columns = bi.getWidth() / TILE_WIDTH;
    int rows = bi.getHeight() / TILE_HEIGHT;
    for (int x = 0; x < columns; x++) {
    for (int y = 0; y < rows; y++) {
    BufferedImage img = new BufferedImage(T ILE_WIDTH, TILE_HEIGHT,
    bi.getType());
    Graphics2D newGraphics = (Graphics2D) img.getGraphics ();
    newGraphics.dra wImage(bi, 0, 0, TILE_WIDTH, TILE_HEIGHT,
    TILE_WIDTH * x, TILE_HEIGHT * y,
    TILE_WIDTH * x + TILE_WIDTH,
    TILE_HEIGHT * y + TILE_HEIGHT,
    null);
    ImageIO.write(i mg, "JPG", new File(BASE_DIR + "tiles/" +
    "x" + x + "y" + y + "z" + source[1] + ".jpg"));
    }
    }
    }
    }
    }
    [/java]

    as guided I put all JAR files in D:\jcp and set it as classpath, using this command: java -classpath D:\jcp; com.ajaxian.ama ps but all I received is the error: "java.lang.NoCl assDefFoundErro r: com/ajaxian/amaps/ImageTiler
    Exception in thread "main"
    Process completed."

    ImageTiler.java file is placed in D:\xampp\htdocs \MAP\code\Googl eMaps\src\com\a jaxian\amaps and inside D:\xampp\htdocs \MAP\code\Googl eMaps\rc are the two images.


    what's the problem here? I know nothing about java. so plz guide me out :(
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by tuananh87vn
    what's the problem here? I know nothing about java. so plz guide me out :(
    It's a classpath problem: for one thing you have to explicitly mention the jars you
    want to use in the classpath list; just mentioning the directory where they are
    stored is not enough. If your 'main' class is a packaged class, say foo.bar.Main
    then it needs to be stored in a directory X/foo/bar/Main.class and X has to be
    an element of your classpath too.

    kind regards,

    Jos

    Comment

    Working...