I have written a unix program with a sample code as follows :
export PATH=/usr/java5/jre/bin:$PATH
export JAVA_HOME=/usr/java5/jre/bin
export MW_HOME=$UCM_HOME/Middleware
export CLASSPATH=$MW_HOME:$MW_HOME/eaton/
# Verify whether required variables are set
if [ -z "${JAVA_HOME}" ]; then
printf "\n\nError: Set the following environment variables:\n\n"
printf "JAVA_HOME (Absolute path to jdk directory)\n\n"
exit 1
fi
JAVACMD="${JAVA_HOME}/java"
LIB="${UCM_HOME}/generic/oracle.ucm.fa_genericclient_11.1.1.jar"
config_file="${UCM_HOME}/generic"
echo $config_file
echo "${config_file}/connection.properties"
# jrf-client.jar is a manifest jar with MANIFEST.MF Class-Path referencing required client libraries
CUSTOM_CLASSPATH=$MW_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-client.jar
checkerror()
{
RESULTCODE=$?
if [ ${RESULTCODE} -ne 0 ];then
exit 1
fi
}
${JAVACMD} -Xms512m \
-classpath "${CLASSPATH}:${LIB}" \
-Ducm.prop.default="${config_file}/connection.properties" \
test.oracle.apps.tx.GenericToolUpload "${FILE_LOCATION}/${FILE_NAME}" "${ENTITY_LIST}"
checkerror
exit
When i am executing this program. It is going into error with-
JVMJ9GC020E -Xms too large for heap
JVMJ9VM015W Initialization error for library j9gc23(2): Failed to initialize
Could not create the Java virtual machine.
user profile was set with 256M. I have increased to 512M
But I am still getting the same error.
I think it is erroring out in ${JAVACMD} -Xms512m \ . But do not know the solution.
Related
My server is in a Unix environment. And I'm using tomcat server. I'm trying to upgrade the Java version, but tomcat is not starting after the upgrade.
which java still gives the old version.
Below is the script for java pointing to tomcat:
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
some script
fi
else
JAVA_PATH=`which java 2>/dev/null`
if [ "x$JAVA_PATH" != "x" ]; then
JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
fi
if [ "x$JRE_HOME" = "x" ]; then
if [ -x /usr/bin/java ]; then
JRE_HOME=/usr
fi
fi
fi
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
echo "At least one of these environment variable is needed to run this program"
exit 1
fi
fi
Tomcat uses JAVA_HOME variable to get the path for Java. So the question drills down to how you set JAVA_HOME and where to set it?
You might find JAVA_HOME under less /etc/profile.d/jdk.sh depending on which shell you are using. I am using cshell so its under /etc/profile.d/jdk.csh
If you will check less /etc/profile, this is the file which is loaded when a user logs in. There is a variable called as PATH the value for which might be something like /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin so you can access any executable under these paths.
The line in ponder in /etc/profile is for i in /etc/profile.d/*.sh from where all the variable (in case of bash) will be loaded into the environment. Also, it's important to note, if you are setting values here these variable will be set for all the users not just for one.
You might find this and this answer useful.
I programmed a Java app. For complex reasons I cannot export it as an executable (due to CVS and environment promoting practices) to Linux. I also cannot add the main class path to the MANIFEST.MF via 'jar -cvmf' command because it is not installed in the Linux environment the app is running in (I have no control over what gets installed). The only other option I found was to create the following shell script:
#!/bin/bash
#check that parameters were passed
if [ $# -lt 2 ]; then
echo ""
echo "Not enough arguments provided. You must have at least 2 arguments with ISO SQL time stamps."
echo " After that you can have unlimited number of parameters for tools."
echo ""
exit 1
fi
echo "Recovering events that occurred between $#"
ROOT_DIR=_spool_generator
JAR_DIR=jar
mkdir $ROOT_DIR
mkdir $ROOT_DIR/$JAR_DIR
FULL_DIR=$ROOT_DIR/$JAR_DIR
cp /home/wma/jar/SpoolGenerator.jar ./$FULL_DIR/
echo $#
START=$1
END=$2
java -cp "./$FULL_DIR/SpoolGenerator.jar" com.btv.main.Driver $# # --> does not work
#java -cp "./$FULL_DIR/SpoolGenerator.jar" com.btv.main.Driver "2001-02-12 18:15:00.0" "2001-02-12 19:15:00.0" --> works
#java -cp "./$FULL_DIR/SpoolGenerator.jar" com.btv.main.Driver "$START" "$END" --> works
echo "Execution is complete..."
exit
The key issue here is that I have an unlimited number of parameters the application uses. This works great when deploying the java app directly as an executable in Windows, works fine if I specify the positional arguments the Shell script takes, but how do I pass these same arguments to the java app from within the Linux script. I have to pass the parameters to the script surrounded in quotes due to the timstamp's special characters, this seems to cause some aberrant parsing when the parameters are passed to the jar. I appreciate any help.
I'm using the Oracle “Self-Contained Application Packaging” tool to make a .deb file for a JavaFX 8 desktop application. The generated package file can be installed without problems on Ubuntu but then the application fails to run. The file is installed as follows:
$ sudo dpkg -i vocabhunter-1.0.14.deb
However, attempting to run the application generates the following error:
$ /opt/VocabHunter/VocabHunter
VocabHunter Failed to locate JNI_CreateJavaVM
VocabHunter Failed to launch JVM
Importantly, I'm generating a bundle without the JRE included and on investigation it seems that the problem relates to this. The generated file /opt/VocabHunter/app/VocabHunter.cfg contains the following line:
app.runtime=
If I edit this and add the path to Java, the program launches without problems. As a workaround, I've suggested that after installing the .deb bundle the user run the following command:
sudo sed -i "s|app.runtime=.*|app.runtime=$JAVA_HOME|g" /opt/VocabHunter/app/VocabHunter.cfg
However, this makes things hard for the user. Does anyone know how to fix the configuration for the JavaFX packaging tool to avoid this problem?
The build uses Gradle to call an Ant script to generate the bundle. Gradle fills in all of the necessary variables. The Ant script is as follows:
<project name="VocabHunter Packaging" basedir=""
xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property environment="env"/>
<property name="JAVA_HOME" value="${env.JAVA_HOME}"/>
<target name="jfxbundle" description="Build the application bundle">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath="${JAVA_HOME}/lib/ant-javafx.jar"/>
<fx:deploy outdir="${basedir}/build"
nativeBundles="${packageType}">
<fx:platform basedir=""/>
<fx:application id="VocabHunterId"
name="VocabHunter"
mainClass="${mainClass}"
version="${version}"/>
<fx:resources>
<fx:fileset dir="${basedir}/build/libs"/>
</fx:resources>
<fx:info title="VocabHunter">
<fx:association description="VocabHunter session"
extension="wordy"
mimetype="application/x-vnd.VocabHunterSession"
icon="${sessionIcon}"/>
</fx:info>
<fx:bundleArgument arg="icon"
value="${appIcon}"/>
<fx:bundleArgument arg="mac.CFBundleVersion"
value="${version}"/>
<fx:bundleArgument arg="launcher-cfg-format"
value="prop"/>
</fx:deploy>
</target>
</project>
You can see the full script in context here.
I'm testing this using JDK 1.8.0_92 on Ubuntu 14.04.
To answer this here too, you are required to have JRE_HOME being set for running some native JavaFX launcher without having bundled JRE. On Windows it looks inside the registry and searches for HKLM\Software\JavaSoft\Java Runtime Environment\[CurrentVersion]\JavaHome. I could NOT find any documentation about this.
To workaround this, you are required to "update" the app.runtime-value as part of the postinst-script being executed while installing. Something like this:
#!/bin/sh
# postinst script for APPLICATION_NAME
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
echo Adding shortcut to the menu
SECONDARY_LAUNCHERS_INSTALL
APP_CDS_CACHE
xdg-desktop-menu install --novendor /opt/APPLICATION_FS_NAME/APPLICATION_LAUNCHER_FILENAME.desktop
FILE_ASSOCIATION_INSTALL
if [ "SERVICE_HINT" = "true" ]; then
echo Installing daemon
cp /opt/APPLICATION_FS_NAME/APPLICATION_PACKAGE.init /etc/init.d/APPLICATION_PACKAGE
if [ -x "/etc/init.d/APPLICATION_PACKAGE" ]; then
update-rc.d APPLICATION_PACKAGE defaults
if [ "START_ON_INSTALL" = "true" ]; then
if which invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d APPLICATION_PACKAGE start
else
/etc/init.d/APPLICATION_PACKAGE start
fi
fi
fi
fi
if [ -f /etc/profile ]; then
# load special environment variables
. /etc/profile
# remove stored value in case of dpkg-reconfigure
RUNTIME_PATH_TO_SET=""
if [ -z "$JRE_HOME" ]; then
echo JRE_HOME is not set, checking for JAVA_HOME being set
if [ -z "$JAVA_HOME" ]; then
echo JAVA_HOME is not set, checking for known locations
# look for known locations
KNOWN_JDK_DIRS="/usr/lib/jvm/java-8-oracle /usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/java-8-openjdk-i386"
FOUND_JAVA_HOME=""
# Look for the right JVM to use (use the first one)
for potentialjdkdir in $KNOWN_JDK_DIRS; do
if [ -r "$potentialjdkdir/bin/java" -a -z "$FOUND_JAVA_HOME" ]; then
FOUND_JAVA_HOME="$potentialjdkdir"
fi
done
if [ -z "$FOUND_JAVA_HOME" ]; then
# still nothing found :(
echo Please make sure to have Java installed and JRE_HOME variable set before running APPLICATION_LAUNCHER_FILENAME
else
echo Updating runtime-settings using known location
RUNTIME_PATH_TO_SET="$FOUND_JAVA_HOME"
fi
else
echo Updating runtime-settings using JAVA_HOME
# JAVA_HOME is set, use that value
RUNTIME_PATH_TO_SET="$JAVA_HOME"
fi
fi
# always write runtime-location, as it might get removed again when user calls dpkg-reconfigure
sed -i "s|app.runtime=.*|app.runtime=$RUNTIME_PATH_TO_SET|g" /opt/APPLICATION_FS_NAME/app/APPLICATION_LAUNCHER_FILENAME.cfg
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
When using the javafx-maven-plugin or javafx-gradle-plugin, put this script inside src/main/deploy/package/linux with the filename postinst to get picked up by the javapackager/bundler.
Disclaimer: I'm the maintainer of the javafx-maven-plugin and creator of the javafx-gradle-plugin
EDIT: updated script for working on dpkg-reconfigure too
I used Redhat and Jboss 4.2.2 GA for application server.
I have a basic problem that when I try to run
./jboss_init_redhat.sh start
is not working.
Basicly I want to run inside jboss_init_redhat.sh file;
/opt/jboss/bin/run.sh -c X -b 0.0.0.0
This line is working but jboss_init_redhat.sh not working.That's our problem.
I checked all permissions but there is not any permission problem.
jboss_init_redhat.sh is below:
#!/bin/sh
#
# $Id: jboss_init_redhat.sh 60992 2007-02-28 11:33:27Z dimitris#jboss.org $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}
#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"jboss"}
#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}
#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"ikarus"}
#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_HOST="0.0.0.0"
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}
#define the classpath for the shutdown class
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}
#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}
if [ "$JBOSS_USER" = "RUNASIS" ]; then
SUBIT=""
else
SUBIT="su - $JBOSS_USER -c "
fi
if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
# ensure the file exists
touch $JBOSS_CONSOLE
if [ ! -z "$SUBIT" ]; then
chown $JBOSS_USER $JBOSS_CONSOLE
fi
fi
if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
echo "WARNING: ignoring it and using /dev/null"
JBOSS_CONSOLE="/dev/null"
fi
#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}
if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
export PATH=$PATH:$JAVAPTH
fi
if [ ! -d "$JBOSS_HOME" ]; then
echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
exit 1
fi
echo JBOSS_CMD_START = $JBOSS_CMD_START
case "$1" in
start)
cd $JBOSS_HOME/bin
if [ -z "$SUBIT" ]; then
eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
else
$SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &"
fi
;;
stop)
if [ -z "$SUBIT" ]; then
$JBOSS_CMD_STOP
else
$SUBIT "$JBOSS_CMD_STOP"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "usage: $0 (start|stop|restart|help)"
esac
If you change JBOSS_USER information to RUNASIS, it should work properly.
Using openSUSE, I downloaded the Oracle rpms for jdk1.6.0_24 and I want to set the java home environment variable to /usr/java/jdk1.6.0_24 but the /etc/alternatives system is unable to automatically detect this installed JDK. Update-alternatives , or whatever just doesn't find the jdk.
So, I want to detect the JAVA home manually in a BASH script.
If I run this command: sudo find /usr -name 'jdk1.6*' , I get this result:
/usr/java/jdk1.6.0_24
How do pipe that result into a environment variable? I want to do something like
#!/bin/bash
read in JAVA_HOME var from a file
if file doesnt exist
sudo find /usr -name 'jdk1.6*'
prompt user for which jdk is correct
set that choice to a variable
add the JDK to alternatives if it is missing
save variable to a file and dont prompt next time
set the alternatives java choice
fi
echo $JAVA_HOME
something like
#!/bin/bash
function validate_java_home {
if [ -z ${JAVA_HOME} ]
then
# do something if the file doesn't provide ${JAVA_HOME}
else
if [ ! -e ${JAVA_HOME} ]
then
# do something if the file provides a non existent ${JAVA_HOME}
fi
fi
}
if [ ! -e ${YOUR_FILE_NAME_CONTAINING_JAVA_HOME} ]
then
JAVA_HOME_CANDIDATES=$(find /usr -name 'jdk1.6*')
echo "Found the following candidates for JAVA_HOME, reply with the one you want then press return"
echo ""
echo $JAVA_HOME_CANDIDATES
read USER_SUBMITTED_JAVA_HOME
echo "You chose $USER_SUBMITTED_JAVA_HOME"
JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
else
. ${YOUR_FILE_NAME_CONTAINING_JAVA_HOME}
fi
validate_java_home
export ${JAVA_HOME}
I haven't tested that but hopefully you get the gist (and I'd say using select as per glenn jackman's answer is more concise/friendly, didn't know that existed so I'm glad I read this Q!)
oldIFS="$IFS"
IFS=$'\n'
choices=( $(find /usr/java -type d -maxdepth 1 -print) )
select choice in "${choices[#]}"; do
[[ "$choice" ]] && break
done
IFS="$oldIFS"
export JAVA_HOME="$choice"
Not sitting at a linux terminal, but this should get you going:
...
jdkpath=`sudo find /usr -name 'jdk1.6*'`
export JAVA_HOME=$jdkpath
...
Adjust as needed.
Based on Matt's answer , here is the script I am using:
#!/bin/bash
# JAVA_HOME script for RPM based java installations
# http://www.oracle.com/technetwork/java/javase/install-linux-64-rpm-138254.html
# examine and understand /etc/alternatives before you run this
cd $SITE_HOME
function set_java_home {
if [ -z $JAVA_HOME ]; then
echo "Using default value for JAVA_HOME: /usr/java/default"
JAVA_HOME=/usr/java/default
fi
export -p JAVA_HOME
echo $JAVA_HOME > java.home.config
echo "JAVA_HOME variable set to $JAVA_HOME ."
}
if [ -f java.home.config ]; then
JAVA_HOME=$(<java.home.config)
else
JAVA_HOME_CANDIDATES=$(find /usr -type d -name 'jdk1.6*')
echo "Found the following candidates for JAVA_HOME. Pick one: "
echo "---"
echo $JAVA_HOME_CANDIDATES
echo "---"
read USER_SUBMITTED_JAVA_HOME
echo "You chose $USER_SUBMITTED_JAVA_HOME ."
JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
fi
# Set the variable
set_java_home