Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Running external batch script from .jar

  1. #1
    Junior Member
    Join Date
    Mar 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Running external batch script from .jar

    Hi,

    I'm currently trying to create a .jar file to run a program (minecraft server) that is basically started by a .bat script that contains:

    java @parameter_hoder_text.txt %*

    and in the .txt file:
    -p "a lot of path"
    --add-modules ALL-MODULE-PATH
    --add-opens java.base/java.util.jar=cpw.mods.securejarhandler
    --add-opens java.base/java.lang.invoke=cpw.mods.securejarhandler
    --add-exports java.base/sun.security.util=cpw.mods.securejarhandler
    .
    .
    .
    then the case is, that if I run the .bat file by clicking on it, it runs without any problem but if I try to run it from a .jar file, it fails to load the modules.

    WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-exports
    WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-opens
    WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-opens
    Error: Could not find or load main class cpw.mods.bootstraplauncher.BootstrapLauncher
    Caused by: java.lang.ClassNotFoundException: cpw.mods.bootstraplauncher.BootstrapLauncher
    Press any key to continue . . .


    I even tried executing the code in the .bat file in my .jar
    ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", ".../...run.bat");
    and
    ProcessBuilder pb = new ProcessBuilder("java","here", "goes", "every", "line", "of", "the", ".txt file");
    but this way It still couldn't find the modules.

    The reason why I want to run the .bat file from a .jar file is that the program is on a remote server and It only allows me to run .jar files.

    Is there any right/import differences when using JVM?

    (I just started to learn java today, with a few years of programming experience)


    EDIT:

    I just succeeded to run the program locally, using:
    Process p = Runtime.getRuntime().exec("cmd /c start run.bat", null, null);
    but on the remote side I have no access to cmd (what a surprise :D )

    which leaves me with the only solution:

    using the Java code with the parameters in the .txt file.

    So the question remains narrowed:
    Why does java not find the modules when run from a .jar file?
    Last edited by Jake012345; March 28th, 2024 at 01:16 PM.

Similar Threads

  1. Error connecting to Unix and running script from Java code
    By schlinzj in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 25th, 2014, 09:02 PM
  2. running script in Postgres via JDBC
    By varu in forum JDBC & Databases
    Replies: 8
    Last Post: November 4th, 2013, 12:21 PM
  3. running script in Postgres via JDBC
    By varu in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 1st, 2013, 01:52 AM
  4. PRoblem Running Executable script in linux
    By ntu in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: May 2nd, 2011, 06:06 AM
  5. Running a external exe in Mac OS
    By supertreta in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 15th, 2010, 01:32 PM