completely new to this so apologise for the question.
I have current been asked to deploy a jar on a linux server at work. I have sucessfully logged into ther server using ssh and transferred my jar on to it. However when I run any java command it says command not found.
I ran
locate java
and
locate jar
which both return, so im guessing java is installed? What do i need to do?
Thanks in advance
It sounds like your path has not been set up to fit your Java needs. You can do either of two things:
Type out the full path of where java is located, and use this full path instead of "java".
Edit your PATH to include java. Here's some information on how this is done: http://www.java.com/en/download/help/path.xml
I think you have to check to make sure that java is installed and the path for it is set too.
Whe you type locate jar it's most likely going to return any other jar including the one you have just added. To know if java is installed, you should instead use the following command java, if the result is something like the program cannot be found... then it means there is not java. You could also use java -version which will also tell you which version is installed. If it's for running purposes then you will be good with that.
First try the command which java, it would show you if you have java installed if not download it and install,run it. Then you can run the jar file as per you requirement. This link shows you how to install and configure java.
http://www.java.com/en/download/help/linux_install.xml
Thanks & Regards,
Alok Thaker
Related
I have installed OpenJML tool (http://openjml.org/) for the Eclipse and was using it and it worked quite well.
However, now I need to call the jmlc and jmlunit tools from command line. As I see from the search in Internet these tools should be located at some directory of JML,I should add them to PATH and use normally by calling the corresponding commands. But once I download OpenJML I have only 3 jar files and no directory at all. Also, from the official JML page there is no other link to download some other version rather than OpenJML. It seems to me that I don't get something obvious.
So, the question is how I can find these tools to run them on command line?
Thanks in advance.
For jmlc, use the -compile flag.
You can also add it as in alias in your ~/.bash_profile:
alias jmlc="java -jar $JML_HOME/openjml.jar -compile"
I already have a working code to download certain file from my server. This file is in an executable (a patch installer). I would like to know if it is possible to launch the executable after my java application has downloaded in its own directory. If it is, may I pleas know how?
Also, I know I am asking for too much here, but is it possible to then delete this installer from the computer after it has installed the patch?---I've been working on this but have stumbled upon a lot of nothing...
Thanks a lot in advance!
Look at the java docs for the class RunTime, this should allow you to run an executable providing you have permissions to do so.
Runtime.getRuntime().exec("command") will execute the input as if you entered it in the command line. So, if you know the path of the exe file (which you should, since you downloaded it), you can launch it like this:
Runtime.getRuntime().exec(executablepath);
Normally you can delete a file by using File.delete(), but in this case the command will still be running if you add delete() right after exec() and it won't be able to delete. Hope that helps!
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.
So I am trying to start with Java (as in, trying to get the dang thing to accept code). I download all the needed things (the SDK) from Java and such, but when it gets to the point where I have to do "javac" in Command Prompt to compile the notepad file, I just get the message saying that there is no command called "javac".
Anybody wanna share some insight?
To set the environment variable PATH: http://www.java.com/en/download/help/path.xml.
Also I recommend using an IDE such as netbeans or eclipse. They make it much easier when starting off in java, plus when getting into advanced projects with many classes, they help greatly.
You need to set the path to your java compiler for it to be found when you use the command prompt. This page explains how.
I would suggest setting the following environment variable:,
JAVA_HOME to point to the root of your java installation e.g. C:\Program Files\Java
than append the following to your PATH environment variable:
;%JAVA_HOME%\bin
than you will be able to use java and javac from the command line.
Also see this article from Microsoft on setting environment variables if your not familiar with it.
You need to add the Java bin directory (where javac.exe is located, assuming you're on Windows), to your system PATH.
Right click on "My Computer", go to Environment Variables, and add the bin directory where Java is installed to your PATH variable.
You will need to have the java bin directory on your path. So, on windows, if installed at c:\java, and bin is c:\java\bin (normally you have version number, jre vs sdk, etc), you will need to add that to your PATH environment variable. set PATH=c:\java\bin;%PATH% -- you could do this in a setlocal/endlocal block or set it permanatly for your machine.
Also, the JRE may not have javac -- you may need to dowload the SDK.
Starting with java by typing 'javac' at the command line satisfy my mother's definition of the phrase 'starting with' ... as in,
"Don't start with me, buddy."
You are likely to end up with a punch in the nose.
For your own sanity, pick one of Eclipse, or NetBeans, or IntelliJ, or the other popular IDEs, and start from there.
I am running a Java application from the command line. Can I specify a command line argument to set the current running directory to something other than where the application is actually going to run?
There is a JVM argument -Duser.dir which can be used to set working directory for JVM.
If it all possible I would rather use a script to run the java application and set the directory in the script:
#!/bin/sh
cd <your dir>
java <some arguments>
The JNI-solution may affect all kinds of relative paths in your application; for examples the classpath you put in.
If you want to change the current directory, you'll have to use JNI and invoke a native API from your Java code. For example, for Windows you would use SetCurrentDirectory
I found this SO post and it helped me solve my problem. Though I wanted to share something specific about IntelliJ that might trip somebody else up.
I have posted a picture below where the -Duser.dir flag is used and also the Working Directory text field is filled in.
In this situation, the Working Directory will be set to "JarLearning" rather than "2ndTry".