Docker-compose and Java - java

I'm quite new to devops world, and I'm currently learning it. I'm trying to start a docker-compose file with kafka and specific app that interacts with it, following one of the tutorials. It requires to start the java jar with the following parameters:
java -Dcom.sun.management.jmxremote.port=5555 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar build/libs/kafka-streams-scaling-all.jar
The question is - how do I run multiline command with options? I've tried it this way:
autoscaling:
exec:
command:
- java
- |
-Dcom.sun.management.jmxremote.port=5555 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar build/libs/kafka-streams-scaling-all.jar
But it returns in "./docker-compose.yml", line 75, column 9 could not find expected ':' in "./docker-compose.yml", line 76, column 9
and some of the answers on the internet suggest to use > sign:
autoscaling:
exec:
command: >
java -Dcom.sun.management.jmxremote.port=5555 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar build/libs/kafka-streams-scaling-all.jar
But docker doesn't seem to understand the "-" part of the command expected <block end>, but found '-' in "./docker-compose.yml", line 74, column 7
What is the best way to approach the running the java jars with options in docker-compose files?

Wrong indentation
<service_name>:
command: |
java \
-Dcom.sun.management.jmxremote.port=5555 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar build/libs/kafka-streams-scaling-all.jar

Related

Java Debug Adapter Protocol

I want to have Debug Adapter Protocol for Java for my application, I did much research but found only vscode implementations that can't be used for my app (because it contains a local vscode package).
I know that Debug Adapter Protocol for Java can be activated by giving some requests to the language server, which will return port as a response on which it will be available. I started to dive deep into codes from vscode and vscode-java-debug, but can't figure out which I need. I only found that vscode has the following wrapped command using which it activated java DAP.
export const JAVA_START_DEBUGSESSION = "vscode.java.startDebugSession";
Maybe someone knows, what kind of request is it or can give some examples?
I activated the java language server using the following command below:
java \
-Declipse.application=org.eclipse.jdt.ls.core.id1 \
-Dosgi.bundles.defaultStartLevel=4 \
-Declipse.product=org.eclipse.jdt.ls.core.product \
-Dlog.level=ALL \
-noverify \
-Xmx1G \
--add-modules=ALL-SYSTEM \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
-jar ./plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar \
-configuration ./config_linux \
-data /path/to/data
You can find more details from here: https://github.com/eclipse/eclipse.jdt.ls/blob/master/README.md#running-from-the-command-line

How to save output predictions into a CSV in weka using command-line by loading a saved model?

I am running a weka command to predict by loading an already trained and saved model. I need these predictions of the test file on the loaded model to be saved as a CSV file. What command should I use in commandline to do the same.
I have already tried the following:
java -cp /usr/share/java/weka.jar -Xmx28G weka.classifiers.meta.FilteredClassifier \
-classifications "weka.classifiers.evaluation.output.prediction.CSV -p 1-3,20,29" \
-T test.arff -l ./j48.model > only_predictions.csv
I have tried the above command with all the permutations of placing the -classifications "weka..." at different places in the same command itself as was suggested in some answer to similar question. It gives me illegal option "-classifications" error each time.
-classifications "weka.classifiers.evaluation.output.prediction.CSV -p first" \
-l $model \
-T $dataset \
|tail -n+6 |head -n -1
This also didn't work for me as was suggested in one of the similar question.
Also tried training and predicting in a single command but didn't work
java -cp /usr/share/java/weka.jar -Xmx28G weka.classifiers.meta.FilteredClassifier -classifications \
"weka.classifiers.evaluation.output.prediction.CSV -p 1-3,20,29 -distribution -file predictions.csv" \
-t ${g1_train_arff} -T test.arff -F "weka.filters.unsupervised.attribute.Remove -R 1,26,28" \
-W weka.classifiers.trees.J48 -c last -- -C 0.25 -M 5
Also, using java -cp /usr/share/java/weka.jar weka.core.Version command gives me 3.6.10.
I expected a proper csv file created with the output prediction values along with the attribute range given with the -p option.
Please help me with the problem. Thanks in advance.

Adding `-Dcom.sun.management.jmxremote` as VM argument stops the server

So I have been facing issue when I add -Dcom.sun.management.jmxremote to my server vm arguments, it just stops. Is there something obvious that I am missing ? FYI - This is a spring boot application.
Here's how I am starting the server
java \
> -Dcom.sun.management.jmxremote \
> -Dcom.sun.management.jmxremote.ssl=false \
> -Dcom.sun.management.jmxremote.authenticate=false \
> -Dcom.sun.management.jmxremote.port=1099 \
> -Dcom.sun.management.jmxremote.rmi.port=1199 \
> -XX:+HeapDumpOnOutOfMemoryError \
> -XX:+FlightRecorder \
> -server -jar my-app.jar
-Dcom.sun.management.jmxremote and -Dcom.sun.management.jmxremote.port=1099 both give the problem. If I remove them, server starts.

WildFly command inside domain.sh

Inside the domain.sh file that comes with WildFly Final 8.0.0 we can see the line in which java is actually being called:
eval \"$JAVA\" -D\"[Process Controller]\" $PROCESS_CONTROLLER_JAVA_OPTS \
\"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/process-controller.log\" \
\"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
-jar \"$JBOSS_HOME/jboss-modules.jar\" \
-mp \"${JBOSS_MODULEPATH}\" \
org.jboss.as.process-controller \
-jboss-home \"$JBOSS_HOME\" \
-jvm \"$JAVA_FROM_JVM\" \
-mp \"${JBOSS_MODULEPATH}\" \
-- \
\"-Dorg.jboss.boot.log.file=$JBOSS_LOG_DIR/host-controller.log\" \
\"-Dlogging.configuration=file:$JBOSS_CONFIG_DIR/logging.properties\" \
$HOST_CONTROLLER_JAVA_OPTS \
-- \
-default-jvm \"$JAVA_FROM_JVM\" \
'"$#"' "&"
I understand most of the commands, but I have not being able to find what does the double dashes do "--" in a java argument context. How are the arguments between the two sets of double dashes interpreted by the jvm?
Double dash is used to signify end of the command options.
If you replace 'eval' on 'echo' you will see doubled OPTS like '-server -Xms64m -Xmx512m'
This means first settings are for Process Controller after -- you have settings for Host Controller

Adding Profiler script in tomcat server

I want to profile tomcat server with a java profiler. My profiler runs from the script say run.sh which looks like below:
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
JAVACMD="$JAVA_HOME/bin/java"
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly; cannot execute: $JAVACMD"
exit 1
fi
java -javaagent:lib/jborat-agent.jar \
-Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \
-Dch.usi.dag.jborat.liblist="conf/lib.lst" \
-Dch.usi.dag.jp2.outputFilePrefix="output" \
-Dch.usi.dag.jborat.instrumentation="ch.usi.dag.jp2.instrument.AddInstrumentation" \
-Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \
-Dch.usi.dag.jborat.codemergerList="conf/codemerger.lst" \
-Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.jar/jp2.jar/jborat-agent.jar/jborat.jar $*
Could somebody please guide me how can I include this profiler in tomcat ?
Is it possible to write something like this CATALINA_OPTS="$CATALINA_OPTS -javaagent:run.sh" in catalina.sh ?
I would really appreciate any help regarding this.
Thanks.
I tried adding options of run.sh (profiler) to setenv.sh as below but does not work. It does not give any error but The server is not starting. I dont know why.
Here is my setenv.sh file:
#!/bin/sh
export CATALINA_OPTS="java -javaagent:lib/jborat-agent.jar \
-Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \
-Dch.usi.dag.jborat.liblist="conf/lib.lst" \
-Dch.usi.dag.jp2.outputFilePrefix="output" \
-Dch.usi.dag.jborat.instrumentation="ch.usi.dag.jp2.instrument.AddInstrumentation" \
-Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \
-Dch.usi.dag.jborat.codemergerList="conf/codemerger.lst" \
-Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.jar/jp2.jar/jborat-agent.jar/jborat.jar "
I already answered your exact same question yesterday. Briefly, you want this:
$ export CATALINA_OPTS="-javaagent:lib/jborat-agent.jar -Xss256m -Xms256m \ -Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \ -Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \ -Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.ja‌​r"
$ $CATALINA_HOME/bin/startup.sh
I don't understand why you need more than that: your script just adds a bunch of system properties to the JVM launcher: you can do that with $CATALINA_OPTS. If you want to set them somewhat permanently, put the export into bin/setenv.sh and it will automatically be run every time you run bin/startup.sh (and bin/shutdown.sh for that matter).

Categories

Resources