I'm trying to use foreman to run a java app locally which deploys fine to heroku.
My Procfile looks like this
web: java $JAVA_OPTS -cp target/classes;target/dependency/* Start
but when i do formeman start i get
15:51:21 web.1 | unknown command: java $JAVA_OPTS -cp target/classes;target/dependency/* Start
If I just enter java at the prompt i get java's help text back so its on my path. If I use the full path to the java executable in the Procfile it works, but it'd be cleaner if I didn't need two versions of the Procfile
Is there somethinf funky going on with my path or is foreman not getting the path from my environment?
Could it be the environment variable is the problem?
Windows:
java %JAVA_OPTS% -cp target/classes;target/dependency/* Start
Linux:
java $JAVA_OPTS -cp target/classes:target/dependency/* Start
Looks like the example is a mix of both :-)
Environment variable
Related
I am trying to run two java application one after other in my docker container.
In my dockerfile i have specified invoker.sh as the entry point.
ENTRYPOINT ["sh", "/opt/invoker.sh"]
Then i use this script to run two jar files.
#!/bin/sh
java -jar loader.jar
java -jar service.jar
but this does not work. It gives
Error: Unable to access jarfile javaimpl-loader.jar
and only the service.jar is executed. When i tried echo $(ls) it shows that both the jar files are there.
but if i change the script to
#!/bin/sh
echo $(java -jar loader.jar)
java -jar service.jar
then both the jars work. Why cant i use the 1st script. any help regarding this highly apreciated.
It appears the first example is being treated as a single line, you could work with that. Also, I would prefer bash to /bin/sh. Like,
#!/usr/bin/env bash
java -jar loader.jar && java -jar service.jar
I am running Gatling on Centos server. The Server has Java 1.7 installed which is not supported by Gatling 2.2 and I am not allowed to update Java version. I was wondering if there was a way to specify java location in gatling configuration to run from a specific Java installation and not from /usr/bin or /usr/sbin. Thanks in advance.
Regards,
AB
You could export JAVA_HOME=/<your-path> before running gatling.
Assuming you're using the gatling.sh script to launch Gatling, you can just edit that script to refer to whatever installation of the JDK that you want. You can set a local JAVA_HOME value and also prefix the calls to java executable with the full path of your JDK 8 installation.
For example, near the end of the shell script, something like this:
JAVA_HOME=/path/to/JDK8
# Run the compiler
${JAVA_HOME}/bin/java java $COMPILER_OPTS -cp "$COMPILER_CLASSPATH" io.gatling.compiler.ZincCompiler -ccp "$COMPILATION_CLASSPATH" "$#" 2> /dev/null
# Run Gatling
${JAVA_HOME}/bin/java $JAVA_OPTS -cp "$GATLING_CLASSPATH" io.gatling.app.Gatling "$#"
I have an error following the next tutorial from Heroku specifically on this part
[https://devcenter.heroku.com/articles/getting-started-with-java#run-the-app-locally][1]
If I execute that instruction foreman throws the following error:
Error: cannot find java class $JAVA_OPTS
I have already declared a env variable like this:
Name variable : JAVA_OPTS
Variable value: -Xms256m -Xmx512m
The Proc file that foreman is trying to execute has the following:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* Main
Im clueless about what is happening.
Note: I already checked some other questions
Running java with JAVA_OPTS env variable
Foreman terminates immediately
foreman can't find java
Hope someone knwos what is happening.
EDIT : I answered my own question below
I suspect you are running on Windows. If so, then you'll have to reference the JAVA_OPTS var like %JAVA_OPTS%. But Heroku will still need the *nix style ($JAVA_OPTS), so I recommend creating a Procfile.win next to your Procfile with the following contents:
web: java %JAVA_OPTS% -cp target/classes:target/dependency/* Main
Then run this to start your app locally:
$ foreman start --procfile=Procfile.win
This is what I did in order to solve the issue:
Seems that the documentation at heroku site is not clear about what operating system are you using. But then I found the answer in the link below:
Heroku Deploy your Java app locally
The original Proc file script whas like this:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* Main
and I modified it as you can see below:
web: java %JAVA_OPTS% -cp target\classes;"target\dependency\*" Main
Just as Heroku documentation states.
This solved the problem and I was able to run my app locally
If you're using 'nix,
export JAVA_OPTS
before running the script that expects it.
I want to setup a Minecraft server, which automatically starts up on system startup.
I use the following script to manually run: /home/mc_ftb/server/start.sh
#! /bin/sh
java -Xms1G -Xmx3G -jar /home/mc_ftb/server/mcpc-plus-1.5.2-R0.2-forge716-B527.jar nogui
The cron to start it on start up looks like that:
mc_ftb Ja ~/server/start.sh
This structure already worked with other mods, like Tekkit, but now with a FTB (NewWorld) mod, I get the error
Exception in thread "main" java.lang.NullPointerException
at cpw.mods.fml.relauncher.FMLRelaunchLog.resetLoggingHandlers(FMLRelaunchLog.java:212)
at cpw.mods.fml.relauncher.FMLRelaunchLog.configureLogging(FMLRelaunchLog.java:191)
at cpw.mods.fml.relauncher.FMLRelaunchLog.log(FMLRelaunchLog.java:242)
at cpw.mods.fml.relauncher.FMLRelaunchLog.info(FMLRelaunchLog.java:274)
at cpw.mods.fml.relauncher.FMLRelauncher.setupHome(FMLRelauncher.java:164)
at cpw.mods.fml.relauncher.FMLRelauncher.relaunchServer(FMLRelauncher.java:147)
at cpw.mods.fml.relauncher.FMLRelauncher.handleServerRelaunch(FMLRelauncher.java:45)
at net.minecraft.server.MinecraftServer.main(MinecraftServer.java:1622)
at org.bukkit.craftbukkit.Main.main(Main.java:21)
Starting the script in a terminal as mc_ftb works fine, but even not with the cronjob, I already tried to start it via exce java ....
The script and the jar file are +x'ed. I'm using the actual stable Debian.
Try adding a 'source /etc/profile' as the first line in your script, this will load the environment variables first.
So replace
#! /bin/sh
java -Xms1G -Xmx3G -jar /home/mc_ftb/server/mcpc-plus-1.5.2-R0.2-forge716-B527.jar
with
#! /bin/sh
source /etc/profile
java -Xms1G -Xmx3G -jar /home/mc_ftb/server/mcpc-plus-1.5.2-R0.2-forge716-B527.jar
I am starting a java programm under Red Hat Enterprise Linux Server release 5 (Tikanga).
directory structure:
- bin ->sc.jar,start-sc.sh,sc-lib-all.jar
- conf->log4j-sc.properties,sc.properties
command to run the java programm (which is perfectly working):
/usr/java/jdk1.6.0_37/bin/java -Xmx1024M -Dlog4j.configuration=file:../conf/log4j sc.properties -jar sc.jar -config ../conf/sc.properties
if i put it into a shell script the java programm can't find the prop file anymore.
shell script (start-sc.sh) looks like:
#!/bin/sh
/usr/java/jdk1.6.0_37/bin/java -Xmx1024M -Dlog4j.configuration=file:../conf/log4j-sc.properties -jar sc.jar -config ../conf/sc.properties
i am a newbie on shell scripting any ideas what i am missing? thx!
i guess you started your shell script not from the bin directory, which the dir start-sc.sh belongs to.
to explain it clear, let's make an example.
say, your script is here:
/foo/bar/bin/start-sc.sh
if you start it under /foo/bar/bin/, it (the relative path) should work.
but if you start your script from /home/yourHome/someDir/ , the relative path will point to $PWD/../, which is /home/yourHome/
you could either in your script first cd /foo/bar/bin/ before you start the java app. or do something like:
a=`dirname $0`
if [ $a = '.' ];then
a=`pwd`
fi
cd $a
/usr/java/jdkxxxx/java .....
It sound fine to me, does this version work?
#!/bin/sh
/usr/java/jdk1.6.0_37/bin/java -Xmx1024M -Dlog4j.configuration=file:$(pwd)/../conf/log4j-sc.properties -jar sc.jar -config $(pwd)/../conf/sc.properties
Edit #1:
Try put the following before launching your program:
echo `pwd`
The output tells you where you are running your script, so you can check if it's the right path or not.
Edit #2:
Try this script
#!/bin/bash
LOG4JCONF="/absolute/path/to/the/log4j/conf/file"
SCCONF="/absolute/path/to/the/other/conf/file"
/usr/java/jdk1.6.0_37/bin/java -Xmx1024M -Dlog4j.configuration=file:$LOG4JCONF -jar sc.jar -config $SCCONF