How to implement the Linux top command UI using JAVA? - java

How to implement the Linux 'top command' style UI using JAVA?
And How to run jar in server side itself, and i can see the state of the program after i log in SSH.

For your second question:
java -jar jarfile.jar
Will run a jar file that is written to be run at the command line. Anything this program prints to standard out will be displayed for you to see.
This entry talks a bit about building a jar file that can be run in this way:
http://en.wikipedia.org/wiki/JAR_%28file_format%29

You could give this a try. I'm assuming that you're looking for an ASCII terminal UI toolkit... which I'd recommend, because terminal codes are rather painful to write by hand.

You might be looking for a Java Curses Framework like this:
http://javacurses.sourceforge.net or CHARVA

Related

Execute grep on remote site to detect running process

I have searched all over but found no luck yet, I am using linux ubuntu flavour and need to know that how can I check that whether the java jar file is running at remote end or not using pgrep. As the pgrep -f "someProcess" returns the Process ID.
Note: Both systems are linux based, and I only need to done it through terminal. Any ideas would be appreciated.
I've used Ant to do this.
I can't remember which task I used unfortunately....
But we executed a command or script remotely using an ant task.
I think we used ExecTask.
Notice you can specify an output file.
You can read that to process the output of your command.
Ant is pretty awesome in that anything you can do with an Ant script, you can do with Java.
And it's a lot easier than you'd think.
I believe this is a good starting pont to learn how to do it.
Here is the Javadoc overview page for the Ant classes.
Here are some more links to helpful Javadoc pages:
Project
Task (the base class for all Ant tasks)
SSHExec task (looks like this is what you want)
ExecTask
Copy task (this is a nice simple one for "Hello, World" purposes
FTP task
I'm sure there other ways, but as they say here Ant makes things very easy for you.
I can think of one way to do this.
Assuming you have servers A and B, A performs the process check on B. You can use ssh and setup no-password login from A->B and use command below:
ssh root#12.34.56.78 "pgrep [whatever keyword]"
You'll get the same result as executing the command on B.
You could use plink.exe to do this. You can pass commands to plink in the form of a .txt file input.

running an external jar using java

so, I've been doing some searching, and i can find somethings on how to run an external application, but i cant get them to work! I've been working on this for a while, and its really annoying.
what i want to do is run a .jar file in the directory
C:\Program Files\AVTECH\NPS\Files\bin\NPS.jar
and I've tried a bunch of different things with the code
Process p = Runtime.getRuntime().exec("dir goes here");.
also
Process p = Runtime.getRuntime().exec("C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar");.
if i'm correct, it uses command prompt to do this? or at least the MS-DOS language. i did some of that kind of thing a few years ago, but i don't remember how one would do this... I've never worked with this kind of thing in java before...
could someone help please? thanks in advance.
Runtime.exec() is working just like if you were typing a command.
Launching a jar file is not working : you have to invoke
java -jar /path/to/my/jar
Check Oracle's documentation on how to execute a jar file.
The actual command should be java -jar C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar. I mean -- if the jar file is indeed executable, this doesn't mean it will run, by just trying to invoke it. You need to tell Java to run it as shown above.
In addition, MS-DOS is not a language -- it stands for Microsoft Disk Operating System. Nowadays, you have this as a Command-line Prompt (Shell) built into Windows.
You need to run the command as a call to the executable and a set of arguments. Check this version of Runtime.exec(String[] cmdarray). If need be, there's also a version of Runtime.exec() that takes a base directory in which to start the executable.

Running JARs without java -jar unix & windows?

I want to run a jar file in both unix and windows without have to call it directly with java like:
java -jar myjar.jar parameters
i want :
myjar.jar parameters
I've been reading allready -
Running a JAR file without directly calling `java`
Which seems like a very nice hack for unix .
Howerver , this wont work in windows.
I'm looking for a uniform solution that will work both on unix and windows , but I'm not sure there is such.
The solution has to be only once , and it has to include changes related to the jar only ,and not the operation systems - because this is a file to I'm suppling to a client.
What you are asking can't be done: Windows will load executable files only in the PE/COFF format used in .exe in .dll files.
What you can do instead is supply the users a "wrapper" program that starts the actual Java program. You could create the wrapper in C, which has several benefits: you can set an icon on the executable and associate the program with file types in the Windows Explorer. Batch files are a popular alternative; they are easier to create.
You can provide a script that starts your application for both Unix (.sh) and Windows (.bat). This seems to be the preferred approach for many companies. An example would be JBoss Server where a run.bat is provided for Windows and a run.sh is for Unix. These scripts set the appropriate environment variables, classpath, etc and then call java.
You can write your own bash and batch/powershell scripts. As for windows, you can try Launch4J. It should be easier than writing elaborate scripts from scratch.
Be aware that you can only provide wrappers to make the execution simpler (one click). Java has to be run anyway. Either explicitly, by the user, or as part of a script. You can't do without it.

Cuda-memcheck and JOCL, can a java executable make use of it? (OpenCL)

I love JOCL, Java bindings for OpenCL. I would like to run Cuda-memcheck on an executable from Java, but whenever I make Java applications, they are always just JAR files that point to a Main-Class. Is there a way to create a .exe file like C++ does and feed that to Cuda-memcheck?
This link could be useful: http://jsmooth.sourceforge.net/index.php
You could probably also the jvm executable directly and provide all the arguments necessary to run your java application. If you normally run your java applications through an IDE, check the console output to see what command the IDE uses to launch your app. This command should resemble something like: <path-to-java-exe> [JVM arguments] main_class [application arguments].
You might try looking into one of the Windows ports of the gcc toolchain. I know that gcc has the capability to turn java code into compiled binary, which is what Cuda-memcheck is looking for. If you aren't afraid of a lot of unnecessary output, attaching Cuda-memcheck to the call to the JVM should also work.

Can my Java software be transformed to .exe software?

Without learning new programing languages, can we using Java get .exe (executable windows file) software directly? And is there away to make .jar (Java ARchive) software transform to.exe (executable windows file)?
Would this conversion effect the performance of the software?
One of the important points of Java is that it'll run on any platform (e.g. Windows, Linux, etc) that has a suitable Java Virtual Machine (JVM) installed. A .exe file is compiled to work on only one platform.
What you think you want is to turn a .jar into an .exe so you can launch it easily. What I expect you really want is just an easy way of launching a Java app that anybody can understand, including your parents.
The easiest way of doing this is to create a Windows batch file that launches your Java app. One of line of script, one new file, one new instruction to your users - "Double click on runme.bat"
There are ways of turning a .jar into an .exe, but you should think about whether that's really what you want, and if so, why.
Note: you can launch a .jar in Windows by just double clicking on it, as long as the main class is specified in the manifest. You might want to look into tools like Apache Ant to simplify building .jars and their manifests. Just a thought.
EDIT:
A batch file in Windows is a simple text file that contains commands. You can test the commands by running them in the command prompt (Start -> Run -> cmd). When you run a batch file the commands in it are just fed to the command prompt one at a time.
How to run a Jar from the command prompt: "java -jar myfile.jar"
If you create a batch file (.bat - use Notepad or your favourite text editor) containing "java -jar myfile.jar" (without the quotes!) then double-clicking it will launch the main class specified in the manifest of myfile.jar. myfile.jar has to be in the same folder as the batch file, though.
If you use the command "java -jar lib\myfile.jar" (again, without the quotes) then your batch file will run myfile.jar, which needs to be in a folder called lib that's in the same folder as the batch file. Use this approach when you have a whole load of Jars with your application and you don't want to shove them in the user's face :)
Note that moving the batch file will break it, unless it uses absolute paths to the jar file - e.g. "java -jar C:\dev\myfile.jar". Of course, if you use absolute paths then moving the Jar will break the batch file anyway :)
Also, note that you should be able to run a Jar file just by doubling clicking on it in Windows, as long as the main class is specified in the manifest. Give it a try. Of course, convincing your users that they can double click on it is another matter entirely...
As a final note, if you use a batch file, your users will get a nice command prompt window sitting in the background until your Java app closes. That is, unless you start your batch file command with "start". E.g. "start java -jar myfile.jar". If you have your app configured to log to System.out or System.err, you will still get a command prompt when your app writes to either of those streams, though.
Final final note, in the Linux world the equivalent of batch files are shell scripts.
You can launch a .exe from java with Runtime.exec() or ProcessBuilder.
You can make a .exe launcher with http://launch4j.sourceforge.net/
Yes, it is possible: http://www.excelsior-usa.com/articles/java-to-exe.html
I'm not sure if this is an appropriate answer because I don't work with Java but could you not using a shortcut file pointing to the java runtime and pass the jar as an argument, this
I realise this is not the only way, nor probably the best way but to me it seams a little better than creating a batch or converting to an exe file if all you're looking for is a convienient way to launch a java app
The very simplest way is to write a windows batch (.bat) file which will start the application.
I was using a wrapper for java to make exe files for a pretty long time:
JStart32
It is just a wrapper for *.jar files.
But ask yourself:
Wouldn't an exe kill the purpose of javas platform independency?
Check out jsmooth (free) and exe4j and you might want to read make your swing app go native

Categories