I'm creating a packaged project usingdist and am trying to modify the generated start script to run the app on port 9001.
Here is what is generated:
exec java $* -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
Here is what I tried, which doesn't seem to work.
exec java $* -Dhttp.port=9001 -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
Any ideas?
I've also tried specifying http.port=9001 in application.conf with no avail. It was very easy to do this in Play 1.2.X, seems a step backward.
After running play dist and then extracting the generated bundle, you can start Play 2 on a different port by running:
./start -Dhttp.port=5432
Or if you would rather edit the start script you can update it to be:
#!/usr/bin/env sh
exec java $* -Dhttp.port=5432 -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
And then run:
./start
Related
i use this shell script to start the java project
cd target
echo "shell parameters: $*"
java -classpath . com.tencent.Example $*
But now I need to use the jdbc jar,How should I modify the shell script and in which path to put the jar?
If the jar is in the current directory,Change the shell to this.
cd target
echo "shell parameters: $*"
java -classpath .:./mysql-connector-java-8.0.27.jar com.tencent.Example $*
I've been trying to get my Java application to run as a daemon in the background after startup. I've followed the instructions given in the top answer here and to no avail.
This is my /etc/init.d/myapp file:
#!/bin/bash
# MyApp
#
# description: bla bla
case $1 in
start)
/bin/bash /var/lib/myapp/start.sh
;;
stop)
/bin/bash /var/lib/myapp/stop.sh
;;
restart)
/bin/bash /var/lib/myapp/stop.sh
/bin/bash /var/lib/myapp/start.sh
;;
esac
exit 0
as for the /var/lib/myapp/start.sh, it looks like this:
#!/bin/bash
java -jar myapp-1.0.0RC.jar &
and works fine when run from a terminal via ssh.
i also ran the update-rc.d myscript defaults command, and was only given a warning about headers and LSB
After this, once i reboot the server, the app isnt running. Any help is appreciated.
Thanks.
When bash scripts are run, they are not automatically ran from the same directory that contains them.
You will either need to update your scripts to change directory to that which holds the scripts before starting the jar:
#!/bin/bash
cd /var/lib/myapp/
java -jar myapp-1.0.0RC.jar &
Or, refer to the jar file with a full path:
#!/bin/bash
java -jar /var/lib/myapp/myapp-1.0.0RC.jar &
Check if your service is registered properly via chkconfig
$ chkconfig --list
If not you can see your service listed on the output, then try adding this lines to your script
#!/bin/bash
# chkconfig: 2345 95 20
# description: bla bla
# processname: myapp
and then run
chkconfig --add myapp
For more information you can check the man page for chkconfig
I have to extract and generate some .h files from a jar and idl file.
Need to use a .bat from external developers:
#echo off
java -jar C:\WorkspaceSwim\trunk\iB\build\BlueGen\target\bluegen.jar -o C:\WorkspaceSwim\trunk\Example\Distribution\build\GeneratedDDSFiles C:\WorkspaceSwim\trunk\Example\Distribution\Flight.idl
set NDDSHOME=C:\WorkspaceSwim\trunk\iB\build\ToolBox\NDDS
set RPCDDSHOME=C:\WorkspaceSwim\trunk\iB\build\ToolBox\RPCDDS
setlocal
set dir=%~dp0
set args=%1
:getarg
shift
if "%~1"=="" goto continue
set args=%args% %1
goto getarg
:continue
set JREHOME=%JAVA_HOME%
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes\" com.eprosima.rpcdds.idl.RPCDDSGEN %args% "-I%RPCDDSHOME% /idl"
I think there are some fail on the script , but i can't see it. Maybe a problem with quotes? i tryied this 3 posibilities :
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes\" com.eprosima.rpcdds.idl.RPCDDSGEN %args% "-I%RPCDDSHOME%\idl"
Error: principal class \idl doesn't found or load
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes" com.eprosima.rpcdds.idl.RPCDDSGEN %args% "-I%RPCDDSHOME%\idl"
Error: principal class com.eprosima.rpcdds.idl.RPCDDSGEN doesn't found or load
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes\ com.eprosima.rpcdds.idl.RPCDDSGEN %args%" -I "%RPCDDSHOME%\idl"
Unrecognized option: -I
Error: Could not create the Java Virtual Machine.
Previusly i use this .cmake to generate the code that will run this .bat
add_custom_command(
OUTPUT ${DDSGeneratedFiles}
COMMAND java -jar ${iB_BlueGen} -o ${GeneratedDDSDirName} ${LocatedFile}
COMMAND "set NDDSHOME=${iMASBlue_NDDS_DIR} &" "set RPCDDSHOME=${iB_RPCDDS_DIR} &" ${RPCDDSGenerator} -replace -d ${GeneratedDDSDirName} -I${CMAKE_CURRENT_SOURCE_DIR} ${LocatedFile}
DEPENDS ${IncludeDependencies}
MAIN_DEPENDENCY ${LocatedFile}
COMMENT "Calling RPCDDS Generator '${RPCDDSGenerator}' on '${IdlFile}'"
)
Thnx for your answers.
To debug batch files, change line
#echo off
in your batch file to
#echo on
and run again
I want to run the following script within a Java executable jar on the Raspberry Pi.
the script (= stream.sh):
#!/bin/sh
raspivid -fps 25 -w 640 -h 360 -vf -n -o - -t 999999 |cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/cam.sdp,rtcp-mux}' :demux=h264
the Java code:
Runtime.getRuntime().exec("sh stream.sh"));
The problem is that the jar must be run with sudo and the vlc command doesn't accept sudo. Neither the script or the Java code contain sudo but as the jar is executed as sudo, vlc still gives the error "VLC is not supposed to be run as root...".
What is the easiest way to make the script run in user mode inside the jar?
I would use su -l $LOGIN -c $CMD or sudo -u $LOGIN $CMD.
Runtime.getRuntime().exec("sudo -u myuser sh stream.sh"));
man sudoers has all the information you need.
You need to change /etc/sudoers
-java -classpath<> <classname> in the ".bat" file to launch java test from cmd windows
how to do that using perl to launch java test from linux ?
Don't use perl. For such a simple job, a simple shell script will do:
#!/bin/sh
/path/to/java -classpath foo.jar:bar.jar:. classname
Make the file executable with chmod +x filename and execute it with ./filename
A similar approach using the -jar option is possible. Additionally, you can forward any command line parameters using the special parameter #.
#!/bin/sh
/path/to/java -jar foo.jar "${#}"