I need to run a .jar in MATLAB, exactly as described in this original question I found in my search of Stack Overflow: how do I run a java .jar in Matlab I was having the same issues as the user here (got the same errors, did the same troubleshooting) The only difference is that I am running Java 1.8.0_144-b01 vs Java 1.8.0_121-b13 in the linked example.
However, when I tried the solution that worked in the above situation...
system ('java -jar C:\My\Java\Class\Path\To\MyJar.jar')
...I got the following message: "'java' is not recognized as an internal or external command,
operable program or batch file. "
The .jar is in my static path. The current directory is set to where the .jar file is located. Any help greatly appreciated.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I got a new computer and I'm trying to get Notepad++ to run how it did on my old one. I got the NPPExec plugin. When I click Execute, it brings up the commands I want to enter. My goal here is to have the code save, compile, and run in the console of Notepad++. Currently I have what I thought used to work on my old laptop.
cd $(CURRENT_DIRECTORY)
javac $(FILE_NAME)
java $(NAME_PART)
Whenever I try and execute it though, I get
Current directory: C:\Directory
javac HelloWorld.java
; about to start a child process: "javac HelloWorld.java"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
java HelloWorld
; about to start a child process: "java HelloWorld"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
I've tried it on files I used to have, and just a basic Hello World
class HelloWorld
{
Public static void main(String args[])
{
System.out.println("Hello World");
}
}
I don't get what the problem is, and would love if someone would be able to help.
Edit: I am using Windows
After checking here: https://beginnersbook.com/2013/05/first-java-program/ and seeing the Set Path section, I reinstalled Java, did the set path command, although the file path ended at \Java and did not have that whole JDK bit in it. I'm not sure if that's part of the issue and Java is not installed properly.
Edit 2: Tried to Find where I can install JDK, and everything sent me to Oracle's website. Is this needed?
Edit 3: Well, I tried just executing the javac command through command prompt and got
'javac' is not recognized as an internal or external command, operable program or batch file.
So I'm pretty sure it's the issue with JDK not being in the folder. I went to check my old laptop, and it didn't have JDK in the folder either. It gives the same error when using the javac command, but for some reason the java command works fine to execute the file. Do I really have to create an Oracle account just to get JDK? When I went to sign up it wanted my work phone number, so it definitely didn't seem like a free thing.
Edit 4: I tried following the Oracle documentation on installing a jdk. I did the download from there, but following that, I didn't see the file I needed. In the Java folder, there is now the jdk-16 folder. In the bin folder there, there are a number of .exe files, but I don't know if any of them are the ones I'm supposed to run. Now that I've installed it though, I'm still getting an error with javac command, but the java command will run files I'd previously compiled.
I am sure this is a stupid question and it must have been asked by every java programmer before. But I cannot find a related question at all.
This talks about subdirectories but I don't have any subdirectories as they are all in the same directory as the java file and the directory I executed the command line from Executable jar file error
This solution gives me the same error as I am writing below: Java command line with external .jar
Others (I don't have links to) talk about Eclipse and other IDE but I am not using an IDE, just a Linux terminal.
I am trying to import a public jar file from http://www.hummeling.com/IF97. The downloaded jar file has been renamed to if97.jar.
I have a java file called steam.java with these commands inside the file:
'
import com.hummeling.if97.IF97;
IF97 H2O = new IF97(IF97.UnitSystem.ENGINEERING);
System.out.println("test H2O table PSpecificEnthalpy(1): "+H2O.specificEnthalpyPT(1,300));
System.out.println("test H2O table PSpecificEnthalpy(5): "+H2O.specificEnthalpyPT(5,300));
'
But I do not know how to run this file in the command line.
I successfully compiled by typing:
'javac -cp if97.jar ~/test/steam.java'
Now I have a file called steam.class
But when I execute it with:
'java steam -cp if97.jar'
or
'java steam -jar if97.jar'
I get error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/hummeling/if97/IF97
at steam.start(steam.java:364)
at steam.main(steam.java:341)
Caused by: java.lang.ClassNotFoundException: com.hummeling.if97.IF97
I am trying to execute this in Linux Ubuntu 16.04 using Terminal. Both the files (steam.java and if97.jar) are in the same Home directory where I execute the javac & java command on.
I believe (or I'm mistaken) that the problem is that java isn't able to find the jar file. But I don't know why.
Please advise, thank you in advance.
You need to specify the class name after the JVM options, because whatever coming after the class name are considered arguments for the class, not the JVM.
Try this:
'java -cp if97.jar steam'
I have a Java jar of which I would like to turn into a .exe file for Windows. Only problem is that I get the following error when building it through Launch4j on Linux net.sf.launch4j.ExecException: java.io.IOException: Cannot run program "/Desktop/launch4j/bin/windres": error=2, No such file or directory. I am not completely sure what is wrong, as I have tried to use the same Launch4j setup along with the same jar with Launch4j but on a Mac instead, which worked perfectly.
I have tried to search for the error on Google, but I wasn't able to get any results and on the Source-forge page with the actual download link, there are no one who have mentioned this error, at least it seems.
To me it appears as if there is something missing in the Launch4j folder? When launching the Launch4j jar to use the program, I am using the following command in the Linux terminal Java -jar launch4j and the program does open, the error first appears when trying to build the executable.
I had the same problem with launch4j on MACOS while using the launch4j ant task. I could solve the problem by copying (not moving) the macos executable located in the launch4j/bin to a newly created sub director launch4j/bin/mac. So I have got:
-launch4j/bin
ld
windres
-mac
ld
windres
I'm having a strange issue trying to run classes from an executable .jar file on Linux that none of the existing question threads I've sorted through seem to be able to resolve. I'll preface this in that I've never had to use Linux before and am only using it in this situation out of necessity, so it's possible I have overlooked something simple that I just didn't know could be causing the problem.
I can launch the classes from my .jar file without any issues on Windows via a .bat file with the following settings:
start "MyServer1" java -classpath ./*;Server.jar infoServer/StartInfoServer
start "MyServer2" java -classpath ./*;Server.jar loginServer/StartLoginServer
start "MyServer3" java -classpath ./*;Server.jar chatServer/start
start "MyServer4" java -classpath ./*;Server.jar gameServer/start
However, when I move to trying to launch these classes from the .jar on Linux, I get a "could not find or load main class" error. My .sh file is set up like this, and is placed in the same directory as my .jar file:
echo Starting Servers
java -cp Server.jar infoServer.StartInfoServer
java -cp Server.jar loginServer.StartLoginServer
java -cp Server.jar chatServer.start
java -cp Server.jar gameServer.start
echo All Done Starting Server
I've used ls from the Terminal to verify the .jar and .sh were being recognized as existing where they should be. (For future note, I'm using the Terminal from inside the directory containing my files.) I've made sure to make use of chmod to be sure both the .jar and the .sh have read/write/execute permissions and used ls -l to verify those permissions were indeed present. I've tried various forms of explicitly defining the classpath, such as using "/home/machine/Desktop/Folder/MyJar.jar", using pwd from the Terminal to ensure I'm getting the filepath correct. I've checked over my Java compatibility. (1.7.0_65 on Linux, 1.8.0_45 on Windows, with the .jar being created in Eclipse using 1.7 Compliance settings.) I can use unzip MyJar.jar from the Terminal and it will properly extract all my class files, allowing me to verify that my .jar isn't corrupted on my Linux machine and that the paths to the classes I'm trying to run are still the same on Linux as they are on Windows.
I do apologize if this is just a problem of inexperience overlooking something, but I can't think of or find any indication of what the problem could possibly be.
EDIT:
I've updated the question with some screenshots related to the problem:
https://gyazo.com/0ae2a2701aae734db21ef7c29200283b - General File Setup.
https://gyazo.com/d735d9cee57b4a92078c4b624d012b8c - Running the Shell via Terminal.
Other notes: jar -tf Server.jar works from the Terminal but not from inside the Shell script, which leads me to believe this may be some kind of visibility or pathing error, but I can't find any reason why that would be the case.
I am having some serious trouble installing and running Jython. I am completely new to how jython runs, so I am pretty lost. I have downloaded Jython 2.5.3 and java jre 1.8.0_25. I believe I have succesfully run the jython.jar file using this command in cmd:
C:\java\jre1.8.0_25\bin\java -jar C:\jython2.5.3\jython.jar
I have beginner-intermediate (closer to beginner) knowledge of programming in jython, but that is on a computer with jython already installed. My main problem is being able to run jython so I can see the actual function/program area where you would type out your functions then run them. I appreciate any help someone can give.
That command is exactly how you run Jython, and without providing any additional arguments, the Jython interpreter will start (where you can type out functions and run them).
If you want to run Jython with a single command, there should be a jython.bat file located somewhere under the Jython installation directory. Jython does not have a true executable because it is run through Java. The jython.bat file is the closest you'll get to an executable because it is a batch script which runs the jython.jar file using a command nearly identical to yours with Java. jython.bat should be located at one of the following locations:
C:\jython2.5.3\jython.bat
C:\jython2.5.3\bin\jython.bat
NOTE: The jython.bat file requires a standard Java installation.