String path = System.getProperty("user.dir")+"\\src\\test\\pageImg.png"在项目里是对的。
导出成jar包,就出错了路径是: D:/myjar.jar/test/pageImg.png像这样的路径该怎么改 

解决方案 »

  1.   

    System.getProperty("user.dir") 就是你的jar包的位置了,不要\\src,
      

  2.   

    System.getProperty("user.dir")输出的就是项目的完整路径啊 你只要为引用的资源建立相对应的目录即可
      

  3.   

    这个pageImg.png你确定你打到包里面了?
      

  4.   

    如果是项目的资源文件,最好用resourceMap:
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(timing.TimingApp.class).getContext().getResourceMap(RunningDialog.class);
            jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon"));
      

  5.   

    不要用这种路径,打jar包以后会有问题试试这个
    BufferedReader reader = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("test/1.txt")));
      

  6.   

    如果是Image的读取,看看这里
    http://www.gamedev.net/community/forums/topic.asp?topic_id=417009
      

  7.   


    this.getClass().getResource("/")
    得到的是当前的classpath的绝对URI路径。
    用这个试一下,获取的是 你的项目下面的 classpath配置路径,比如在eclipse下面, 你编译后的class 在 build下面,那么此时 this.getClass().getResource("/") 就是 D:/eclipse/workspace/***/build/
    这里假设你的eclipse项目在D:/eclipse/workspace/ 这个路径下面。