我自己写了一个java的小程序,希望能够在没有jre的机子上运行,姑且叫此程序为 MyApp. 
  现在我已经有MyApp.jar和精简的jre。我还做了一个批处理文件,内容就是运行MyApp.jar
  问题是,我不知道用户会把程序安装在哪个盘哪个文件夹,我写的批处理文件就找不到jar包和jar。
  怎么办? 其实我是没做过安装程序~~

解决方案 »

  1.   

    你要把那个批处理文件和jar放在一起,安装的时候就安装到同一个目录了,然后运行的时候就从本目录中找,就不会有问题
      

  2.   

    我知道要用相对路径或者通配符,就是不知道bat文件应该怎么写?大侠给个例子?!
      

  3.   

    用相对路径,把你的jar,jre,bat都放到同一目录下!应该就可以了!
      

  4.   

    如果在Java程序中引入了外部包,而又不想把其放入jre/lib/ext文件夹下,只是想放在与工程的代码一起的,如:
    Test.java在包com.biao.normal中
    project directory: JavaDemo
     
    JavaDemo/com/biao/normal/Test.java
    JavaDemo/pack.jar
    Test.java要用到pack.jar中的com/biao/pack/PackageDemo.java
     
    怎样写classpath和javac, java来运行Test.java?
    JavaDemo/runandcompile.bat:
    set classpath=.;./pack.jar
    javac com/biao/normal/Test.java
    java com/biao/normal/Test
     
    其中最关键的一点是set classpath=.;./pack.jar中的".;"是必不可少的,少了可能程序能编译成功,但是运行不了。
      

  5.   

    %~dp0 is only available within a batch file and expands to the drive letter and path in which that batch file is located (which cannot change). It is obtained from %0 which is the batch file's name.
      

  6.   

    可以使用 winrun4j  http://winrun4j.sf.net
    有一个配置项是指定jre位置的。
    vm.location  
    Specify the location of the JVM dll you want to use. This is useful when you package your own JRE with your app.
      

  7.   

    楼主“精简的jre”是什么意思?
      

  8.   

    jre 中用不到的不包含进来