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).
Related
So I have a Docker network that has a Docker file with a bunch of information. I have a java program that is going to bring up the enviorment and then produce several commands to run within this enviorment. To be clear, the first command I need to run is NOT inside the Docker enviorment. I am having some challenges with the Process and Runtime classes.
First, say I wanted my java program to launch a new gnome terminal and then run a command to get into the docker network. I have this command,
Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal"});
Gnome terminal sucessfully comes up but any additional arguments I give in this array are just ignored. For example,
Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","ls"});
Does not work. The command I ultimatly want to run would look something like this,
Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","sudo","docker","exec","-it","sawtooth-shell-default", "bash"});
Second, Once I have this running, will additional commmands I run work within the Docker enviorment? I have a python file with a Stream handler that specifies the correct commands to run.
Other documentation on related issues was limited.
I made sure my code was wrapped in a runtime exception try catch and that I was running the correct .class file. Any help on this would be great!
Edit: I have also tried to run this in another linux terminal like Hyper and Tilda
I also am able to get a sudo sign in when I run the command like so,
Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","--","sudo","docker","exec","-it","sawtooth-shell-default", "bash"});
However it closes immediatly after authorizing.
Okay this is what I was attempting to do.
https://www.atlassian.com/blog/software-teams/deploy-java-apps-with-docker-awesome
This site is outdated and I had to use this link for getting that latest version of the java PPA.
This process basically installs java into the docker contatiner so that I can run a java program that uses Runtime.
I am working on a KTor server. I run the generated jar file using java -jar command. So I expect that only one Java process should run. After running for a while another Java process is being created which is bound to different port.
I checked the details of the process using ps -a [PID] and find this new Java process is "kotlin-compiler-embeddable" program.
I am wondering why this process is being created, what is use of this and is it safe to kill it.
Thanks for any pointer.
kotlin-compiler-embeddable is used in scenarios when you have to package the compiler in a single jar, and no external dependencies. This is the case of Ktor.
I get the infamous error "Could not find or load main class..." when I am trying to run java command as root.
I tried this solution without any success.
which java returns /usr/bin/java so I tried appending at ˜/.bashrc
export PATH=$PATH:/usr/bin/java
or
export PATH=$PATH:/usr/bin, again... without success.
ps: I want to run as root because I've created a simple server using sockets and I want to ping it with an android app. The problem is that I am getting permission denied.
Maybe this could help:
sudo java -cp $CLASSPATH com.blubber.Bla
I need to run a single java program (which will change the content of some text files) on my new website. What's the easiest way to do that for example using php code?
Do I need to install JVM or any other software in order for this to work?
Please guide on how to do this step by step if possible.
You have to install a Java Runtime Environment (JRE) on your server to be able to run a java program.
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
To execute a java program in php, you can simply use the exec() function :
exec("java -jar yourProgram.jar");
http://php.net/manual/en/function.exec.php
I have a dokku container running a node.js app, my backend needs to use java8 to run some command lines. I have the following error message from my server:
[Error: Command failed: /bin/sh -c java
/bin/sh: 1: java: not found
]
How can I make java8 accessible inside my dokku container?
You need to create your own image based on current one (or modify your current Dockerfile if you already have it) and add java to it. How exactly to add java depends on base image and java which you need. Here the sample for ubuntu based image and oracle java8
After that you could run container from that image. You could use your local image or you could push your image to public or private registry.
Here Dockerfile documentation and best practices for it creation.