Wednesday 10 December 2008

Create JAD for Jar in Linux (01)

Here is Code of Created JAD in Linux
Jad file we need to running Jar File in Java
With JAD and JAR , in our PC can running File such as Games Java in HandPhone Nokia, SE (Sony Erickson) etc


Save this as “jadmaker.sh”:


#!/bin/bash
#
# Given a J2ME midlet jarball, create a JAD for it
# Usage: ./jadmaker.sh

# safety check 1
FILE=$1
if [ ! -f "${FILE}" ]; then
echo "Input file '${FILE}' missing, exiting."
exit 1
fi

# safety check 2
JAD="${FILE%.*}.jad"
if [ -f "${JAD}" ]; then
echo "${JAD} already exists, overwrite? (y/N)"
read tmpans
answer=$(echo "$tmpans" | tr '[:upper:]' '[:lower:]')
if [ "$answer" != "y" ] && [ "$answer" != "yes" ]; then
echo "Not overwriting ${JAD}, exiting."
exit 1
else
rm -f "${JAD}"
fi
fi

# unzip the internal manifest, changing line endings to our local OS
# the sed action removes blank lines, with or without spaces/tabs
unzip -aa -j -p ${FILE} "META-INF/MANIFEST.MF" | sed -e '/^[ \t]*$/d' > "${JAD}"

# generic variables
echo "MIDlet-Jar-URL: ${FILE}" >> "${JAD}"
echo "MIDlet-Info-URL: http://" >> "${JAD}"

# actual jarball size
FILESIZE=$(stat -c%s "${FILE}")
echo "MIDlet-Jar-Size: ${FILESIZE}" >> "${JAD}"

# weee
echo "Created ${JAD}."
exit 0


==========================================================
Reference
http://java.sun.com

1 comment:

Abish ! said...

Thank You!
Simple yet Functional.
That makes linux my favorite.

I want to add something:

||To run the script type:

abish@abish-lappy:~$ sh jadmaker.sh oxford.jar
(where oxford.jar is the .jar i want to make .jad of)

gOoD lUcK.