Space in Java command-line arguments throwing error in Amazon cloud - java

I'm running following command in Amazon cloud(server ec2 platform Linux ) but the terminal is throwing an error.
java -jar runnable.jar getinfo -n "kaus mond"
ERROR: Was passed main parameter 'mond"' but no main parameter was
defined.
But the same command in my local windows system is working fine.
If there is no space in "kaus mond" then working fine in Amazon cloud as well but with space not accepting.
Please suggest me how to make it work with white space.

Use single instead of double quotes around the string parameter:
java -jar runnable.jar getinfo -n 'kaus mond'

Related

how to run kubectl command in java

I can run kubectl get secret/rabbitmq-expressmode -n expressmode in shell successfully.
However when I try to run it in java with either ProcessBuilder or Runtime.getRuntime().exec, the error:
Error from server (BadRequest): the server rejected our request for an unknown reason
is thrown out.
What's the possible reason?
Best approach would be to use official java client library.
Installation is pretty easy, and code examples shows you how to use it.
If the official one does not meet your requirements, there are also community-maintained client libraries:
Java (OSGi)
Java (Fabric8, OSGi)
Java
I had same issue but resolved by programmatically creating bash file containing kubectl... command I was trying to execute directly.
For example, create bash file and put your kubectl command there (i.e.: some-file.sh). Then try then executing it in bash process running within your java code (bash some-file.sh).

How to run Java application using Cygwin

I've been trying to compile and run this example for javafx  https://openjfx.io/openjfx-docs/#maven using Cygwin on Windows 10.  It took awhile to get past the compile because my javafx is stored in C:\Program Files\javafx-sdk-13.0.1, the trouble being the space in the folder name.  After trying lots of different things I finally found How to cd into a directory with space in the name?, which in a nutshell tells you to put quotes around your environment variable, "PATH_TO_FX". 
Then I tried to run the example 
$ java --module-path "PATH_TO_FX":mods -m hellofx/hellofx.HelloFX
Error occurred during initialization of boot layer​java.nio.file.InvalidPathException: Illegal char <:> at index 10: PATH_TO_FX:mods​
So I thought the PATH_TO_FX was the problem but it turns out it is not.
$ java --module-path src:mods -m hellofx/hellofx.HelloFX
Error occurred during initialization of boot layer​java.nio.file.InvalidPathException: Illegal char <:> at index 3: src:mods​
src is a valid directory and I still get the same problem.  I think it is related to java being stored in a directory with spaces in it but I'm not sure.
#Ray_Write
isn't ; for Windows? Cygwin uses bash
This has nothing to do with the shell. The parsing of --module-path is handled entirely by the java interpreter, and according to the docs uses ; on Windows instead of :, presumably for congruence with Windows PATH separators.
Since this Java installation is a native Windows application and not one built for Cygwin, one should still use ;. So in effect, this has nothing to do with Cygwin.
For passing file paths to java you may also need to use cygpath to convert the path to its native Windows path.
You're right #Iguananaut, I do need a semi colon, to get my example to work I had to escape it.
java --module-path "$PATH_TO_FX"\;mods -m hellofx/hellofx.HelloFX
where PATH_TO_FX is in .bash_profile as
PATH_TO_FX="C:/Program Files/javafx-sdk-13.0.1/lib"

Docker environment variable with spaces

I need to run a docker image where I pass a bunch of jvm configurations to a jar file. I'm passing the configs via -e parameters as the example bellow.
Dockerfile:
FROM openjdk:9-jre
COPY test.jar /
CMD java -jar -DinstallationDate=$INSTALLATION_DATE /test.jar
Run command:
docker run -e INSTALLATION_DATE="03.05.10.2019 15:00:00" space
The problem is that when I run this, it gives me the following error:
Error: Unable to access jarfile 15:00:00
I tried running it with the json notation, like:
docker run -e ["INSTALLATION_DATE","03.05.10.2019 15:00:00"] space
It doesn't give me an error, but the parameter comes as an empty string.
I also tried to escape the space char with "\", but still didn't work.
Anyone knows how can I send this parameter to the jar execution inside the docker container? Is there another approach to this?
The problem is likely occurring because the CMD in your Dockerfile:
CMD java -jar -DinstallationDate=$INSTALLATION_DATE /test.jar
...is subject to word splitting after the variable $INSTALLATION_DATE is expanded. In order to turn off word splitting for that second argument to java, consider enclosing the variable in double quotes:
CMD java -jar -DinstallationDate="$INSTALLATION_DATE" /test.jar

Can't run a example by Doop - Framework for Java Pointer Analysis

I am trying to using Doop framework. I am following this link: https://bitbucket.org/yanniss/doop
I downloaded the code and compiled it successfully. but when I am trying to Running Doop by the following command
$ DOOP_HOME>./bin/doop -a context-insensitive -j ./lib/asm-debug-all-4.1.jar
in my case, it is :
./doop -a context-insensitive -j ../lib/asm-debug-all-5.0.3.jar
But, unfortunately, I got an error.
vuquangvinh#vuquangvinh-VPCEA24FM:~/tutorial/DoopFramework/code/doop/bin$ ./doop -a context-insensitive -j ../lib/asm-debug-all-5.0.3.jar
:: loading settings :: url = jar:file:/home/vuquangvinh/tutorial/DoopFramework/code/doop/lib/ivy-2.3.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
The EXTERNALS directory is invalid: null
I have no idea what is happening. I have tried, but this framework seems to be not popular. Anyone can help me!
Many thanks!
As stated in the documentation the tool expects several environment variables DOOP_HOME, DOOP_OUT, DOOP_HOME and DOOP_EXTERNALS to be set and it simply complains that DOOP_EXTERNALS is not set.
Instead of setting the environment variable you can also pass the externals directory via command line option --externals <the directory>.

Java Runtime OR Processbuilder OR Other

I'd like to know what the best alternative is for running command line executables from Java. The Target platforms for the commands are Windows 7(+) and Unix/Linux.
I have a class that currently uses Runtime.exec() along with the enhancements from the JavaWorld StreamGobbler article. It works about 90% of the time on both Windows and Unix. The other 10% of the time I need to extend the class and then fiddle with putting cmd.exe of /bin/sh in front of the command. I've also had to fiddle sometimes between using a single String that has command and arguments to splitting the command and args into a String[] array.
My latest is a new error/exception "java.lang.IllegalArgumentException: Executable name has embedded quote, split the arguments." My current Runtime.exec() class works fine in Eclipse running as a Java application, but once I build it and run from an actually command prompt, it fails with the above exception.
So now I'm reading that we should be using ProcessBuilder to do command line executables to the OS platform.
My question is, what is the best alternative? Runtime.exec(), ProcessBuilder, or some other option? Is there one option that will service both Windows and Unix/Linux? If not, which one works best with Windows? Which one works best with Unix/Linux?
tia, adym
Not sure how to give Bohemian credit, but I used ProcessBuilder...Solution is at :
Java - ProcessBuilder command arguments with spaces and double-quotes fails

Categories

Resources