Running a Java 3D program from the command line - java

I recently installed java 3D in my computer and it all the progras which I created worked from the NetBeans IDE. However when i set the path in the command line, it says that javac is not ercognised.
I set the path to,
C:\Program Files\Java\Java3D\1.5.1\bin
and then typed javac FirstProgram.java
I got the following mesage (please help)
'javac' is not recognized as an internal or external command,
operable program or batch file.

If you have compiled your project in NetBeans already, then to run it you use java not javac.
If you can export your built project as a JAR (would be in dist folder of your project), you can run it with java -jar myProgram.jar
javac is the Java compiler, should be where you have put the JDK, not Java 3D.

Setting the path to Java3D won't help you much. It's important that the Java3D jars (you can find them if you look around the stuff in that directory) are on your classpath when you execute your program. So to augment Bakkal's suggestion, you need something like
java -cp "C:\Program files\Java\Java3d\lib\xxx.jar" -jar myProgram.jar
The path to your 3D jar is in quotes because of the usual trouble with blanks in a directory name. This is one of Microsoft's most stupid mistakes!

Related

.jar file is not working after being published from Eclipse [duplicate]

There was a program that I used that made runnable .jar files.. All the ones I'm finding now are ones that make .exe files.. I remember it also has the option to make the file a .sh script as well. Anyone knows its name? I've been searching for hours with no avail :/
The command line
java -jar file.jar
Will run your jar file if it has a Main-Class defined as explained here.
You can use that command in a shell script.
You can create a runnable jar using NetBeans IDE or Eclipse IDE by just providing the main class to run. Rest of the things it will take automatically. That class must be having a main() method in it. Then you can run that jar file using java -jar yourjarfile.jar
Do you mean actually coding java and then compiling to .jar? If you do try
eclipse code editor
I used eclipse to make minecraft mods. It will work if you want to make .jar programs.
If you want to have a jar that you can execute using the usual syntax ./app.jar (instead of java -jar), here is a post explaining the process: how to create executable jars.
Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it "executable".
Here is a simple example of the process:
# Append a basic launcher script to the jar
cat \
<(echo '#!/bin/sh')\
<(echo 'exec java -jar $0 "$#"')\
<(echo 'exit 0')\
original.jar > executable.jar
# Make the new jar executable
chmod +x executable.jar
With this, you can now run ./executable.jar instead of java -jar original.jar. This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.

Can't run .jar classes from .sh on Linux that work on Windows via .bat

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.

java 'jar' is not recognized as an internal or external command

I'm getting the following error when I try to run the 'jar' command in the command line on windows :
'jar' is not recognized as an internal or external command
The general solution seems to be that I need to add the jdk bin folder to the PATH in environment variables. I have already done this, I added the following to the path variable :
...; C:\Program Files\Java\jdk1.8.0_40\bin\;
Though I'm not sure if having the jdk reside in 'program files' instead of 'program files x86' affects this. I'm on 64 bit windows with 64 bit java.
Thanks
The path should only contain directories where the OS will look for executables. Strip the trailing "\jar.exe" to set your path as:
(old path variables here);C:\Program Files (x86)\Java\jdk1.7\bin
Thanks To : #stevevls
Try using this command:
java -version
If it doesn't work that means you failed to properly add path to jdk.
If it does work, try using:
java -jar
The jar command in command line is used in order to create a JAR file. For example:
jar cf jar-file input-file(s)
See more at: Oracle docs
If you want to run the existed JAR file you should use the java -jar command mentioned by #Aleksandr.
But in your case it looks like you don't have an access to the added directory in your path with JKD binaries so at the beginning try to execute mentioned java --version to check whether you have java in you classpath at all.
Please remember that on Windows you have to restart the console when you change the windows default path. You do not see the changes on the current console.
The x64 version of Java is installed on Program Files. The x86 version is installed on Program Files x86 by default.
Five steps to solve this problem:
check whether in your bin folder jar.exe is availbale or not
check for your environmental setting
download jar file from here http://originaldll.com/file/jar.exe/29248.html and keep in bin folder
now check for jar it will 100% work
keep any jar in your desktop and go to desktop path on cmd prompt and run the command jar xf filename.jar
Now see if it is working

How can I run my java class from the project root directory

I am compiling and running my Java project from the command line rather than eclipse for the first time and have a slight inconvenience that I just can't seem to find a solution too.
My project has a standard structure:
Project Directory
/src
/self
/redway
/myAPP.java
/bin
/libs
So I compiled using:
javac -sourcepath src src/self/redway/myApp.java -d bin
and so far so good...
I can run the program by navigating to the /bin and then just typing
java self.redway.myApp
BUT and this is really annoying. How do I run it from my project root directory?
I tried just
java bin/self.redway.myApp
and some other obvious ideas to no avail. I know it is a minor thing but it is super irritating and I'm sure there is a simple answer which I should have spotted immediately but I just can't find it!
Thanks.
You can add the java -cp option to specify the class path. E.g.
java -cp bin self.redway.myApp
you can write a shell script like the following:
cd [your bin directory]
java self.redway.myApp
call this script for example runProgram.sh, place it in the directory where you want to be when you run your program, and run it using
sh runProgram.sh
that would also save you time if your program is going to use other jars and you have to add them to the class path, then all you have to do is change your java command in the shellscript to become
java -cp [path to the jar]:[path to another jar]:...:[path to your bin folder] self.redway.myApp

.Jar file won't open

I'm trying to open OpenRocket from my downloads folder, but it keeps on defaulting it to my JGrasp IDE. I tried opening with:
C:\Program Files (x86)\Java\jre7\bin\javaw.exe
but it still won't work.
Bottom line. I can't open .jar files anymore because I can't find the right .exe file to open it with! What do I do?
Thanks
According to the openrocket site, running is as simple as java -jar OpenRocket-14.06.jar. Do note, though that the Sun runtime is recommended. Indeed, I just verified the command on my system.
In order to run OpenRocket, you need to provide it to java with the -jar flag. In your case, from the command line:
"C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar OpenRocket-14.06.jar

Categories

Resources