2012-12-18 7 views
4

GWT에서 간단한 이미지를로드하려고합니다. 그러나 결코 발견되지 않습니다.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.pngImageTest 클래스와 동일한 디렉토리에 저장된다. 또한 src/main/resources 아래에 두었습니다. 같은 오류.

어디에서 이미지를 찾아야합니까?

답변

9

webapp 디렉토리에 넣어야합니다 (index.html 파일 근처의 GWT 설정에서 WAR 디렉토리로 지정됨).

그렇지 않으면 src/main/webapp/resources/images/yourimage.png의 경우 resources/images/yourimg.png과 같은 상대 경로를 지정해야합니다.

대안은 클라이언트 번들을 사용하는 것입니다 : 다음

public interface AppBundle extends ClientBundle { 

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

    public static final AppBundle INSTANCE = GWT.create(AppBundle.class); 

} 

그리고 당신의 코드에서 :

AppBundle.INSTANCE.myImage(); 

당신의 이미지가 AppBundle 클래스와 같은 패키지에 배치해야합니다이 경우.

+0

클라이언트 번들이 완벽하게 작동합니다. – membersound

관련 문제