Are there any existing solutions for remote execution of commands on a windows server from Java natively? psexec.exe is not an option since the java application has to be cross platform.
Even a preexisting solution using Java RM would be sufficient.
Currently, I'm using an SSH client library to ssh through java into a Windows server that's running the cygwin SSH daemon. Sadly the SSH daemon has some issues when it comes to quoting commands that go into a CMD (as opposed to bash) shell.
It'll require some work, but the remoting library in Hudson has very good support for running commands and doing file operations over the network on remote computers.
see https://jenkins.io/projects/remoting/ (you'll have to dive into the code)
Check out the Java RDP Client. Not really out of the box, but with little digging you should be able to trim it down to what you need.
Since it uses getopt, I would assume it's GPL'd.
Related
My Linux-based C++ server (central document repository) uses git to manipulate file that it and receives from clients. Git is being used by executing standard git shell commands from the server application.
Now I develop a Java client that is intended to be used on Windows machines.
Client's network only accepts emails (it is heavily firewalled) so the server generates a diff patch file that should be applied on the client's side.
I'm not really a Windows user so this whole git bash thing confused me. How to I execute git commands from windows application? Similar to system("git add ."), but for Java and with security and error checking.
I read there are git libraries but a failed to find if they support applying patch files.
I am not sure if I get you completely right, but if you are looking for a way to master git through Java, I would suggest to have a look at JGit. It's the Java implementation for git that is e.g. used within the Eclipse IDE.
JGit also offers the ApplyCommand which suits your need for applying patch files.
There are several tutorials to be found across the web.
For remote connection: ssh -Y remoteuser#remoteip
I need to open terminal in remote machine only; for example a gnome-terminal.
This is a typical use case for a library such as Jsch:
JSch is a pure Java implementation of SSH2.
JSch allows you to connect to an sshd server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs.
Beyond that: please understand that not every language is suited for all kinds of problems - personal opinion here: I would rather avoid using Java for tasks such as "controlling a remote system" somehow. First of all; I would avoid re-inventing the wheel; you really want to rely on existing solutions. But instead of programming something in Java, I would rather look to other solutions, such as scripting with python; or using tools such as salt, puppet, chef, ...
I have a console application (written in Java), which should run on a Linux machine until it is stopped.
Logging is done by the application itself.
The application needs to be stopped whenever a new version is available (i. e. I login, stop the application, copy the new JAR file, and then launch it again).
What are the options for implementing this, apart from those specified below?
Known ways to do it:
1) Tanuki service wrapper
2) nohup java -jar myapp-1.32.jar &
I use Java Service Wrapper, but you already mentioned it. I think it should suit your needs.
Apache Commons Daemon is also popular: http://commons.apache.org/daemon/, but I never used it.
I'm using this startup script: http://shrubbery.homeip.net/c/display/W/Java+Daemon+Startup+Script
[Changed domain name - by wiki owner]
Some modern Linux distributions have switched to upstart. That's a daeomon starting and stopping all the other services. I'd definitely look into that. Since it solves some tricky problems with production ready start scripts. The downside is that it has no java specific functionality.
There also the apache commons deamons http://commons.apache.org/proper/commons-daemon/jsvc.html
Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily.
Jsvc allows the application (e.g. Tomcat) to perform some privileged operations as root (e.g. bind to a port < 1024), and then switch identity to a non-privileged user.
I'd like to program a little application in Java which would block all network connections (for whole os, not just VM) on demand. The application is for the Windows platform only and I would like to use Windows specific APIs.
I looked at the Windows Firewall API, but didn't find anything useful. Also, I don't know how to call these APIs using JNA.
I'm asking you for a few pointers or examples for how I could accomplish these tasks:
Using Windows Firewall or other APIs in Java using JNA or some other library (JNI is not preferred)
Block/Unblock all connections
You can use the "netsh" command line, see http://support.microsoft.com/kb/875357
Invoke netsh command using the followinf syntax:
Runtime.getRuntime().exec(command)
But, I think, firewall is not what you need in this case. Here is the command line utility to enable/disable network interfaces for Windows: http://www.novell.com/communities/node/2338/network-configuration-command-line-control
There is no API support for this in Java. You cannot do it.
I have to make a tool for automated distribution of the Java code. Basically, I have a repository with compiled files, and about 50 locations to distribute the same code.
Does anyone know some opensource tool which can help me in this process?
If you are speaking about easy deployment of java applications, use JNLP. The only thing user has to do in this case is to surf to URL.
If you wish to do it without any user participation I believe the solution depends on target platform:
Use SSH for Unix platforms
WNI or telnet for windows platforms.
To make the solution more portable you can run
wget THE-JNLP-URL
on target machine using SSH for unix like platforms.
I do not know built-in command like wget for windows. But you can implement this in VBS or JS and then invoke the script using cscript over WMI or telnet.
Good luck.
Either you can distribute it out with rsync, or you can use Java WebStart to let the user JVM download and invoke the software as needed. For Windows based clients this is usually the easiest, especially when you want people to update to a newer version.