making a batch file to install a program - java

One of my friend told me that he used a batch program to install a java program on the machine,that placed the necessary files in a particular directory and also planted a shortcut on the desktop. How can it be done ? If there are tutorials that teach this please link me to them

All you need to do is use some basic windows commands to make this work. I'm not going to write the script for you but I can point you in the right direction. A batch script on windows is a simple text file ending with the .bat extension.
You can use any command typically available on the windows command prompt (AKA cmd.exe). A good starting point is learning how to move and copy files around so you want to take a look at the commands by the same name on the Command-line reference from Microsoft. There is also a handy guide linked on the same page to batch files and how they work.
The documentation linked is for Widows XP and the syntax of the commands should be back and forwards compatible with other Windows versions.

Installing a Java program is the same thing as installing a ... program ;-)
You can create a batch installer from scratch with a .bat file or use an installer builder tool.
I use NSIS because it's free and simple to use ... but there's others.
You also may want to build an .exe instead of a jar file (sometime, windows open the jar archives instead of launching java). I use Launch4J to wrap my java application in a .exe file.

If the app. has a GUI, install/launch it using Java Web Start. It works on Windows, OS X & *nix, and can install both desktop shortcuts and menu items to launch the app. on platforms that support such things.
JWS is supported & supplied by Oracle.

This code is a simple batch script. Customize this code.
Code:
#echo off
color f0
:: overwrite your program name after the '=' ::
set ProgramNameHere=ProgramNameHere
goto start
:start
cd/
cd users
cd %username%
cd desktop
md %ProgramNameHere%
:: overwrite your file path on the 'DATA' ::
:: overwrite your file name on the 'file1', 'file2'...
:: overwritw your file name after the 'extracting'.
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file1.txt
echo extracting file 1
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file2.txt
echo extracting file 2
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file3.txt
echo extracting file 3
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file4.txt
echo extracting file 4
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file5.txt
echo extracting file 5
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file6.txt
echo extracting file 6
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file7.txt
echo extracting file 7
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file8.txt
echo extracting file 8
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file9.txt
echo extracting file 9
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file10.txt
echo extracting file 10
ping localhost>nul
goto exit
:exit
exit

Related

Is it possible to embed a jar file in a Windows Powershell script?

When I have a jar(hoge.jar) file, and a unix shell script(hoge.sh) or a windows batch file(hoge.bat), I can obtain ones with the jar file like below:
cat hoge.sh hoge.jar >foo.sh
or
copy /b hoge.bat+hoge.jar foo.bat
Is there any way to do that with a powershell script (hoge.ps1)
copy /b hoge.ps1+hoge.jar foo.ps1
As for the foo.ps1 obtained as above,
java -jar foo.ps1
does work, but the part of the powerscript never runs... (when used as the powerscript ofcourse)
You can potentially store any file in a powershell script. Here is an excellent article that shows you how to do so with base 64 encoding.

Why are some Cygwin files not executable?

I'm attempting to execute Cygwin commands on Windows from a Java application. In cygwin's bin, I noticed some files are Application type (.exe) while others (like zcat and zless) have no extension and are just File type.
I've added the bin to the Windows PATH and seem to only be able to execute the .exe files from cmd. The code below works.
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "ls");
Process p = pb.start();
I want to use things like zcat and zless but they aren't executable and cmd complains that 'zcat' is not recognized as an internal or external command,
operable program or batch file.
If I manually change the file to .exe, I get a pop-up error saying zcat can't start or run due to incompatibility with 64-bit versions of Windows. I've installed the 64-bit version of cygwin (setup-x86_64). Why isn't all of cygwin's bin executable?
Most of the cygwin programs are NOT binary program but script one.
The command file can give you a description of the file type:
$ file zcat
zcat: POSIX shell script, ASCII text executable
while
$ file cat
cat: PE32+ executable (console) x86-64, for MS Windows
reading the first 5 rows of zcat
$ head -n 5 zcat
#!/bin/sh
# Uncompress files to standard output.
# Copyright (C) 2007, 2010-2016 Free Software Foundation, Inc.
we see on first row the #! that says that is a script to be executed by the
/bin/sh interpreter.
In other case we can have
$ head -n5 2to3
#!/usr/bin/python2.7.exe
import sys
from lib2to3.main import main
sys.exit(main("lib2to3.fixes"))
so 2to3 is a python 2.7 script
Nobody else has said this, so for anybody else looking for this ... if you need to run the "z..." commands from the cmd window AND you have the cygwin bin directory in your path, you can run them (yea, it's a bit klugy) using bash, as in
bash zcat file.gz
etc.
Or you can run them directly from the cygwin terminal.
FWIW I had to find the 'more' utilities and load them. For some reason they weren't in my initial set of packages I downloaded

Use shell script to execute java saxon transform to create file

I've been trying to use PHP to execute a shell script(.sh) and do Java saxon.transform to create a file. When I run the PHP file, it doesn't show any errors but the file is not being created.
script.sh is executable(chmod +x), and jar path is predefined.
script.sh
echo "Running step 01."
java net.sf.saxon.Transform -o:review.html -s:merged.html -xsl:xsls/01-simplify.xsl --suppressXsltNamespaceCheck:on;
if [ -f "review.html" ]
then
echo "Review.html file successfully generated."
echo "Done"
else
echo "Something went wrong."
echo "Check the <code>merged.html</code> file."
fi
php
echo shell_exec('./script.sh');
Result
Something went wrong.
Check the merged.html file.
The same java command works as it's supposed to when executed from command line. It just doesn't work on web.
I'm on Ubuntu 16.04, with PHP7.
Any suggestions would be appreciated.
Thanks.
If you check your error.log file it should give you more details as to what is going wrong. using the command:
tail /var/log/apache2/error.log -n 100
Or similar
I tried running a similar shell script within a php environment. I get the following error:
Error on line 7 of test.xsl:
Failed to create output file file:/var/www/html/samples/review.html: Permission denied
in built-in template rule
Failed to create output file file:/var/www/html/samples/review.html
It is probably permission problems you are getting when you create the output file.

Writing a bash script to run a java program

I'm rank new to bash thus the question.
I've a java program that I've exported as a .jar.
This file when run as
java -jar somefile.jar
goes into an infinite loop and awaits a file name. Based on the correct file path it generates an output.
How do I write a bash script to do automated testing of this project.
I need the scrip to do the following -
Run the program, which is run the same command
provide an array of 5 files as an input to the program
For each file write the output to an log file.
This should do it.
#!/bin/bash
files="$#"
for i in $files;
do
echo "Doing $i"
java -jar somefile.jar <<< "$i"
done
Make sure you chmod u+x filename it first. Then call it like this:
./filename firstfile secondfile thirdfile etc.
Other:
As sjsam pointed out, the use of <<< is a strictly bash thing. You are apparently using bash ("I'm rank new to bash..."), but if you weren't, this would not work.
Suppose my java program is HelloWorld.java. We can run it in 2 ways:
1st using executable jar
2nd by running java class from terminal
create a new text file and name it hello.sh
In hello.sh
!/bin/bash
clear
java -jar HelloWorld.jar
Save it and open terminal:
1 navigate to directory where your HelloWorld.jar is present
2 give permission to terminal to run the bash script by using the following command
sudo chmod 754 hello.sh
3 run you script by running the following command
./hello.sh

How to install Jar file with parameters innosetup

I'am trying to create a setup with innosetup for my application but before the finish of the installation of my setup.exe i'd like to run other installation by this command :
java -jar build.jar buildinfo.xml
this Jar installation will takes 45 seconds but i don't know how can i do it .
Also you can...
create a batch file with your commands ("java -jar" etc.)
use "Bat to exe converter" (search on Google) in order to convert
your batch file in a Windows executable file
run that exe file at the end of Inno setup procedure
I hope this can help someone :-)

Categories

Resources