0

I finished a Java Program, and now i'm creating a Batch File to set it up. I have no great knowledge of batch files, and CMD commands, thats why im asking this question :).

This is what i have already :

@echo off
C:
md \Calc
D:
cd Calculator
move D:\Calculator\Calc.jar C:\Calc\

However This Requires that the user places the folder "calculator" into D:\, which can be inconvenient, is there a way to solve this?

2
  • Hi - Did you know that you can set it up so the user can just double-click the .jar file (or a shortcut of the .jar file) to invoke your app? I think there are many better ways to go than a .bat file. IMHO... I'd recommend "do nothing" (just give them the .jar). Here are other alternatives: Create Windows installer for Java
    – paulsm4
    Aug 15, 2012 at 23:26
  • Thanks For The Reply Paul, However I tried double - clicking on the .jar and nothing happens. Im only a beginner programmer, so its just a command line application for now, perhaps you could show me how to set it up the way you said? Aug 16, 2012 at 2:17

3 Answers 3

0

You can use PUSHD C: to change directory and then POPD will return you to the previously current directory.

2
  • Thanks for that Neil, that helps alot :). Also, is there a way to make cmd find a file, then move to that directory? Aug 16, 2012 at 2:19
  • You can use FOR /R to find a file and in the controlled statement you can use the %~dp prefix to extract just the drive and path from the variable.
    – Neil
    Aug 16, 2012 at 23:27
0

to search for a file, and copy it to the stated location:

for /f "tokens=*" %%a in ('dir /b/s d:\calc.jar') do copy "%%a" c:\calc\

This has the issue that it will copy every calc.jar it finds to the location (overwriting the old one).

Look at the output of dir /b/s d:\calc.jar to see what files it will find

0

To make a .jar file run by double-clicking, set a file association in Windows:

http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html

Open the Windows Explorer, from the Tools select 'Folder Options...'
Click the File Types tab, scroll down and select JAR File type.
Press the Advanced button.
In the Edit File Type dialog box, select open in Actions box and click Edit...
Press the Browse button and navigate to the location the Java interpreter javaw.exe.
In the Application used to perform action field, needs to display something similar to C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe"

-jar "%1" % (Note: the part starting with 'javaw' must be exactly like that; the other part of the path name can vary depending on which version of Java you're using) then press the OK buttons until all the dialogs are closed.

1
  • Thanks for the reply, however i want this app to be distributable, so that people don't have to set file association, just so they have to click an .exe, however the way i am doing it rquires the users to place the file in D:\ then run setup.bat then run the Calc.bat. Then it runs the app. Aug 19, 2012 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.