Trying to execute jar using cygwin, arguments not recognized - java

I have a makefile that calls a java parser to process some files before compilation. While in linux works perfectly when I am running that on a Windows 7 machine using cygwin my input are recognized as jar files.
My command inside my make is something like
java -jar ${MY_DIR}/myParser.jar -arg1 -arg2 -arg3 input.file output.file ;\
and I get an error that input.file is not a valid jar file... I assume it has something to do with my paths and how cygwin handles java but I can't make it work.
Thanks in advance

Try putting up ()
exec java -jar $(cygpath -w /path/to/myParser.jar) -arg1 -arg2 -arg3 input.file output.file
Srry not enough rep to add comment .

Related

How to import external jars in command line or Atom?

I have been using IntelliJ to run my java programs that require some external jars. I also learned that if I want to compile and run my program from the command line I should do the following:
java -classpath someJar.jar YourMainClass
or for many libraries:
java -classpath someJar.jar;myJar.jar YourMainClass
However, while placed in the src folder where my class it doesn't seem to find my class.
I also like using the Atom text editor but I don't know any package that can import external libraries like an IDE does. So how do I do it in Atom or in cmd in Windows 10? I am kind of a newbie to java dev outisde my beloved IDE, so I would really appreciate some help.
If you're on a Windows system then try compiling (with the jar) using the following command in cmd:
javac -cp .;jar-name.jar *.java
To run the command with the jar use:
java -cp .;jar-name.jar JavaCodeName
If you're on a Unix system then you can try the following to compile in terminal:
javac -cp jar-name.jar:. *.java
And to run it use:
java -cp jar-name.jar:. JavaCodeName
I'm not too familiar with Atom so I don't know if there is an attachment to do this, but it should work for terminal / command prompt.

Can't run java from PHP's exec

I've been trying to run a JAR file that would read from input.txt and write to output.txt this way in console:
java -jar file.jar input.txt output.txt
And it works 100% fine on my machine. I need to run it inside a php script, and this code works 100% fine for me (Mac OS, php built-in server):
exec("java -jar file.jar input.txt output.txt");
But once I deploy it (CentOS server) where the exec function is allowed, it fails, it returns an empty string and the jar does not work, running it directly from shell is OK.
How can I fix that?
Thanks in advance!
The problem with your exec() is that PHP doesn't know where Java is on the server. Update your command to specify the full path to the Java executable and it should work, though you should also use full paths to the jar and text files while you're at it.

java: "Unable to access jarfile ..."

I have downloaded RoboMind (http://robomind.net) and try to make it run on a Linux Mint12
Knowing that Min12 is not the newest release, I still would like it to run...
When I use the .sh file that comes in the pack I get an error:
"Unable to access jarfile ..."
if I type the exact same command at the same prompt, in the same directory, it works:
here is a copy paste from the commanline:
magnus#martin-HP-625 ~/Downloads/RoboMind $ ./robomind.sh
Unable to access jarfile RoboMind.jar
magnus#martin-HP-625 ~/Downloads/RoboMind $ cat ./robomind.sh
java -jar -Djava.ext.dirs=lib -Dsun.java2d.ddscale=true -Dsun.java2d.noddraw=true RoboMind.jar
magnus#martin-HP-625 ~/Downloads/RoboMind $ java -jar -Djava.ext.dirs=lib -Dsun.java2d.ddscale=true -Dsun.java2d.noddraw=true RoboMind.jar
java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1076)
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1053)
at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1347)
at robo.RoboMind.startGui(RoboMind.java:168) ... <snip>
Now it works ... ?
Whats the difference?
I messed around with javapath etc. as suggested in other posts, but nothing makes any difference to the situation illustrated above.
Why can't the .sh script find the .jar file when the exact same command at the prompt have no problems?
I'll give you the "solution", and I will let you discover "why".
Just launch:
# dos2unix robomind.sh
..after then it will work. If you do not have dos2unix installed, apt-get install dos2unix

Running a jar file from cygwin is throwing error where from commad prompt it is running, why? (in windows)

this is the command.
java -cp clojure.jar;sum.jar CalculateSum
sum.jar is a jar file made from clojure and java code.
CalculateSum is file which contains main method of java.
error from cygwin
can't execute binary file, Error 126
Cygwin provides you with a *nix environment within Windows, so that you might have to change the classpath separator to colons:
java -cp clojure.jar:sum.jar CalculateSum
Try:
java -cp clojure.jar:sum.jar:. CalculateSum
If you execute in the place you have the root of packages for CalculateSum.class
java -cp "clojure.jar;sum.jar" CalculateSum this is working

How to pass Properties to jar from Powershell?

I've been using Powershell-1.0 for command line needs for a while, instead of cmd.exe. Unfortunately, there are still some caveats when using Java. I need to pass a property to a jar, like that:
java -jar -Duser.language=en any.jar
This line works fine in cmd.exe, but not in Powershell as it searches for another jar:
Unable to access jarfile user.language=en
Using quotes doesn't help.
Is it doable in Powershell-1.0, or do I miss something in Java?
Take a look at my answer to this question. Note how you can use echoargs.exe to diagnose these sort of problems. Most likely the fix would be to quote the parameter e.g.:
java -jar "-Duser.language=en" any.jar
You can test that using echoargs (from PowerShell Community Extensions):
echoargs -jar "-Duser.language=en" any.jar
Arg 0 is <-jar>
Arg 1 is <-Duser.language=en>
Arg 2 is <any.jar>
Using quotes works fine for me in PowerShell on Windows 7.
java "-Dmy.property=value" -jar myjar.jar
Be careful: the jar name must be placed right after -jar, and arguments placed after -jar myjar.jar will be passed to the program inside the jarFile.
Try launching instead using the following pattern:
java -Duser.language=en -jar any.jar
That assumes that user.language is meant as a system property. If you meant it as a command line argument, change that to:
java -jar any.jar -Duser.language=en
I am actually surprised that the command line you mentioned works at all outside of powershell (though I have confirmed that it works fine for me too, even on Linux) and it is also a little strange that things would work differently inside and outside of powershell.
From java -help:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
...
-D<name>=<value>
set a system property
...
So basically you should always put the JAR filename directly after the -jar command line option, and any JVM options (such as setting system properties with -D) before.

Categories