4

GWT で単純な画像を読み込もうとしています。しかし、それは決して見つかりません。

    import com.google.gwt.user.client.ui.Image;

    public class ImageTest implements EntryPoint {
        Image image = new Image("test.png");
    }

結果:

[WARN] 404 - GET /test.png (127.0.0.1) 1394 bytes
   Request headers
      Host: 127.0.0.1:8888
      User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
      Accept: image/png,image/*;q=0.8,*/*;q=0.5
      Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
      Accept-Encoding: gzip, deflate
      Connection: keep-alive
      Referer: http://127.0.0.1:8888/ImageTest.html?gwt.codesvr=127.0.0.1:9997
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1394

test.pngクラスと同じディレクトリに配置されImageTestます。の下にも入れてみましたsrc/main/resources。同じエラー。

画像はどこに配置する必要がありますか?

4

1 に答える 1

8

それらをディレクトリに配置する必要がありますwebapp(ファイルの近くのGWT設定でWARディレクトリとして指定されていindex.htmlます)。

resources/images/yourimg.pngそれ以外の場合は、のように相対パスを指定する必要がありますsrc/main/webapp/resources/images/yourimage.png

別の方法は、クライアント バンドルを使用することです。

public interface AppBundle extends ClientBundle {

    @Source("image.png")
    ImageResource myImage();

    AppBundle INSTANCE = GWT.create(AppBundle.class);

}

そして、あなたのコードで:

AppBundle.INSTANCE.myImage();

この場合、イメージは AppBundle クラスと同じパッケージに配置する必要があります。

于 2012-12-18T20:02:17.810 に答える