run script as Intellij build with debugging - java

I have the following script (run) with starts a project:
#!/bin/sh
######## ENTER PATH TO YOUR JAVA, JAVAC AND JAR BINARIES HERE
export JAVA_HOME=/usr/local/lib/jdk-8u25
export _JAVA_OPTIONS=
export PATH=${JAVA_HOME}/bin:${PATH}
java="java"
exec ${java} -server -d64 -XX:+UseParallelGC -Xms4G -Xmx4G -jar build/experiments.jar $*
typing ./run 8 5 5 -ins50 -del50 -keys1048576 -prefill -file-data-temp.csv starts the project.
Using this post I managed to run the code from intellij, but because it see's it as an external shell script, debugging the code is impossible. how can I make the script (run) as the "root" file of the project?

Related

How to run a jar with a different java path using a .sh script (Openj9)

How would I go about running my Jar files to test with Openj9 in Ubuntu?
Preferably using a .sh script
you can use a script like below:
#!/bin/bash
your_path_to_open_jdk_9/bin/java -jar yourJar.jar

Java not running in crontab

java -jar /home/scripts/relay.jar is working fine when I launch from command line. The command produces a file: relay.txt
In crontab
/usr/bin/java -jar /home/oneprovider/relay.jar
is not producing anything. I first had it without /usr/bin/ but then did which java and added absolute path with no luck. The jar file was originally written for windows but it works in Linux fine when launched from command line
What am I missing?
Agreed that the working directory is likely the problem. Can you write a shell script that wraps the java invocation and sets the working directory? Something like:
#!/bin/sh -e
cd /home/oneprovider
/usr/bin/java -jar /home/oneprovider/relay.jar
Then change the cron job to run the script instead. Remember to chmod it and make sure that the cron user can write to the directory if it isn't your personal crontab.

why doesn't jenkins start my java program?

This is extremely annoying but I have a script launch.sh like:
#!/bin/bash -x
java -jar foo.jar &
If I run it by hand, my java program starts up. However in Jenkins I configured that just does execute shell: $HUDSON_HOME/launch.sh >& out
I see from out file that it looks like it started java, but when I do a ps I don't see it there. How do I configure jenkins appropriately?
https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller
add
export BUILD_ID=dontKillMe
to shell script

Java runs OK from command line, but gives "Could not find or load main class" from shell script

The command below runs fine when I execute it on RedHat 6 from command line:
java -cp /my/dir/Dep1.jar:/my/dir/Dep2.jar:/my/dir/MainJar.jar one.of.my.classes.Class1 <args> > log.txt
However, when I execute the following script test1.sh (which has 755 permissions):
#!/bin/sh
export JEXE="java"
export JBDIR="/my/dir"
export ARGS="<args>"
export JARS="${JBDIR}/Dep1.jar:${JBDIR}/Dep2.jar:${JBDIR}/MainJar.jar"
export CLASSPATH=""
for f in `ls ${JBDIR}/*.jar`
do
export CLASSPATH=$CLASSPATH:$f
done
cd "${JBDIR}"
"${JEXE}" -cp "${JARS}" one.of.my.classes.Class1 "${ARGS}" > log.txt
as ./test1.sh from command line, I get Could not find or load main class. What am I doing wrong?
UPDATE:
Sorry for bad editing of the original question. Corrected.
echo produces java -cp /my/dir/Dep1.jar:/my/dir/Dep2.jar:/my/dir/MainJar.jar one.of.my.classes.Class1 <args>
I added building CLASSPATH trying to get the script to work. Removing it has no effect,i.e. I get the same exact error.
Is it possible that the JAR is build somehow incorrectly? I generate it by running an ant build from Eclipse.
The script worked after I added
export PATH=$PATH:<path to java directory>

How to run jar from .conf?

I've got the following script to run:
# harvest_bug
#
start on runlevel [345]
script
java -jar /home/admin/es09AndroidUpdater/es09AndroidUpdater.jar
end script
But my linux machine doesn't know anything about java. If I run java -version, I will get
bash: java: command not found
I guess java is not in $PATH, because I still can run Tomcat and things like that. For example Tomcat's setenv.sh looks like that:
export JAVA_HOME=/usr/java/default
export JRE_HOME=/usr/java/default/jre
PATH=$PATH:$JRE_HOME/bin
export PATH
PATH=$PATH:$JAVA_HOME/bin
export PATH
export JAVA_OPTS="-Des09.config=/home/es09/es09.properties -Xms128m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m"
So how can I modify the script to run my jar? Can I do this?
# harvest_bug
#
start on runlevel [345]
script
export JAVA_HOME=/usr/java/default
export JRE_HOME=/usr/java/default/jre
PATH=$PATH:$JRE_HOME/bin
export PATH
PATH=$PATH:$JAVA_HOME/bin
export PATH
export JAVA_OPTS="-Des09.config=/home/es09/es09.properties -Xms128m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m"
java -jar /home/admin/es09AndroidUpdater/es09AndroidUpdater.jar
end script
Is that ok? Will linux run this script? Sounds very stupid, because I'm not familiar with bash, linux and things like that.
The main purpose of setting java path in $PATH or $JAVA_HOME environment variable is to define the exact path of java executable.
To run your script, use
$JRE_HOME/bin/java $JAVA_OPTS -jar /home/admin/es09AndroidUpdater/es09AndroidUpdater.jar

Categories