I am writing an app that uses the .scpt file to execute a jar in the same directory. I know how to use applescript to get the current directory, and I know that I did it correctly because when I print how my command, which looks like this:
do shell script "/usr/bin/java -jar /Users/name/Desktop/test.app/Contents/Resources/Scripts/myJarFile.jar"
Now the problem is, if I copy and paste this into a terminal, it runs properly, but in applescript it gives me this error:
error "Exception in thread \"main\" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1347)
at Runner.main(Runner.java:22)" number 1
Also, I have tried executing a shell script that runs the above command, but to no avail (when it is called from applescript of course).
Related
I have a jar file that I would like to run. I originally was running it in a batch script but now I want to run it as a shell script. (I did not write this code so I do not have access to the main class)
My jar file is called MyFile.jar and I am using
java -jar MyFile.jar
However, I get an error saying:
ArrayIndexOutofBoundsException: Index 0 out of bounds for length 0
This is the only error I get.
In the batch script, the file is executed using
java -cp MyFile.jar com.mycomapnny.example.Main "path of where to put output"
I think it has something to do with needing arguments. But I am not sure what arguments to pass in since I can't look at the main class.
Any help would be appreciated. I can try to provide any additional information I can.
I have an .exe file on MyDocuments folder. I can't seem to run the program in the command prompt if I run C:\User\User\MyDocuments\Sample.exe. This gives me an error Failed to execute script.
But when I'll have the command prompt opened on the MyDocuments folder and only run Sample.exe, the programs runs perfectly.
What I want to do with this is I want to have a java program and execute Process p = Runtime.getRuntime().exec("C:\\User\\User\\MyDocuments\\Sample.exe"); and it will give me the Failed to execute script error.
Any I ideas what I missed?
As suggested by Application will not launch from command line full path, but will after CDing to directory I would make sure your executable does not depend on the current working directory.
Try Running:
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
before your try and execute your executable.
I want to try to e2fsck on Windows with Cygwin exe and dll files.
Fortunately, it works fine when I try to execute it with Windows command line(such as "e2fsck.exe -f test.img").
However, I failed to execute it with JAVA API, Runtime.getRuntime().exec("e2fsck.exe -f test.img").
Exit value of process is 8, and it means operational error of e2fsck. The exit value seems to be returned when e2fsck can not access target file, or target file is invalid.
I found the below things :
It's not caused by diffrence of string handling way of cmd.exe and exec().
Any other cmds on API call, such as ...exec("echo test! >> test.img"), work fine.
It means that exec() API put the right file path to e2fsck or any other processes.
It's not caused by permission deny. As I mented above, test.img is writable by exec().
ProcessBuilder could not solve this problem.
I couldn't find actual reason of my problem.
Did I miss somthing else?
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
I am using a .bat file, which is reliant on a .jar file. I have java (jdk/jre) installed on my system. If I run a command on this command line api via cmd (e.g. nscmd --help), everything works fine.
However, I want to run commands inside another program (Automise www.automise.com). If I do so, with the command line tools in another folder to Java, I get the infamous "java is not a recognised keyword...etc" error. If I put the command line tools in the same folder as Java, I get this error:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Program returned code : 1
How can I successfully run the command line tools?The tool is this: http://www.newservers.com/language/en/documentation/reference-nscmd.html
Thanks
Add the directory java is in to your path variable.