I made a program which runs fine on windows. When I moved it over to CentOS, I got this error:
Error: Could not find or load main class org.wbc.WBCController
This is the file setup and .sh on linux:
And this is the file setup and .bat on windows:
Does anybody know what the problem is, and how I can fix it?
Java will respond with this error even if it cannot find the file wbc.jar. I am guessing that that is your problem. You might want to see that your are executing the shell script from within the right working directory.
Check to see if you can run wbc.sh from the console or put this in wbc.sh to make sure it searches for the jar in the same directory as the shell script:
#!/bin/sh
java -cp `dirname $0`/wbc.jar org.wbc.WBCController
Related
I am running a java program using a .bat file. It works well after double clicking direcctly on the .bat, that's not the problem.
What I want now, is to run that .bt file (and the java program by extends) from the cmd at first, and then to be able to compile it from any other machine.
I have followed at first the following answer : How do I run a java program from a different directory? , but it didn't work for me.
Here is my .bat file :
#echo on
set CLASSPATH=%CLASSPATH%;.;lib/console.jar;lib/log4j-1.2.13.jar;lib/prog1.jar;lib/prog1_newOption.jar;lib/org.hamcrest.core_1.3.0.v201303031735.jar;lib/RXTXcomm.jar;lib/trace.jar;lib/xercesImpl.jar;lib/xml-apis.jar
java -cp "$/prog1_newOption/src/main/Main" %UsersCommand%
pause
exit
%cmd%
Maybe have I to look for the main path in the .bat file and then parse it the the "java command programm" line?
Thank you so much for your help
I cant execute java jar file from cmd windows 10.
I have generated a jar file using Intellji.
when I run the command Java -jar I got this error
Error: Unable to access jarfile
I tried running the cmd with administration right but same error. the class path is set correctly. the jar file is located in the right directory .
What could be causing the problem?
Thank you
make sure you use
java -jar TestJar.jar
instead of
java -jar TestJar
If this is not your error, the file might not exist or you donĀ“t have permission to open it.
So, I am trying to run a program from jar files. It uses javaswing and has a gui.
The program runs fine in netbeans and in eclipse.
When I try to run it from the exported jar file it says this:
Unable To Install Java
There are errors in the following switches:
"C:\Users\CNC Department\Desktop\ValveConversion.jar";.
Check that the commands are valid and try again.[java installation not complete
Now, I also tried doing it from the command prompt. Here is what came up:
[cmd prompt attempt][1] [1]: https://i.stack.imgur.com/7reZ3.png
So, I reinstalled the java JDK, java SDK, netbeans and eclipse. The issue is still occurring in both command prompt and from running the jar file directly.
What am I doing incorrectly here? What do you recommend that I do to get this to run from a .jar file?
You need to set the java path
Open a cmd with elevated privileges and run this command to set the JAVA_HOME environment variable using setx command:
setx JAVA_HOME -m "C:\Program Files\Java\jdk-11.0.2"
Then restart the cmd and run java -version to check if it's all ok.
For reference setx command documentation
Or simply use the following snippet if you prefer to use java without setting the PATH variable:
"C:\Program Files\Java\jdk-11.0.2\bin\java" -jar "C:\Users\CNC Department\Desktop\ValveConversion.jar"
I wrote a little java program and now I want to execute this .jar file from a .sh script.
my script:
#! /bin/bash
java -jar /var/spool/sms/sentSMS.jar
then i run the command: sudo bash sentSMS.sh
an get following error:
ERROR: Unable to access jarfile /var/spool/sms/sentSMS.jar
I am using a Raspberry with raspian-jessie, if this important to solve it.
Sorry, but I'm new in scripting with linux.
Take into account that the user must have at least READ permissions on that file.
Also, as you say you are new in linux, make sure the name is correct. sentSMS.jar is different from sentsms.jar
I've written a java program and I'm trying to run it from cmd both in Windows and Linux.
I first compiled and then run it , and it worked just fine on Windows.
The problem comes up when I'm trying to do the same thing on Linux. The commands I've used on Linux are :
javac -cp aspose-cells.jar:aspose-words.jar:aspose-slides.jar ConvertToPdf.java
java -cp aspose-cells.jar:aspose-words.jar:aspose-slides.jar ConvertToPdf
The first command , which starts with javac, works just fine and outputs the ConvertToPdf.class file. The problem comes up after running the second one , which outputs the following error:
Error: Could not find or load main class ConvertToPdf
I'd like to know what am I doing wrong , and I'd be grateful if anyone could point me to the solution.
Thanks in advance.
Add the current directory . to the classpath:
java -cp aspose-cells.jar:aspose-words.jar:aspose-slides.jar:. ConvertToPdf
your working directory is not included in class path.
do this :
export CLASSPATH=$CLASSPATH:<your-jars>:.
it should work !!!