[(It's sad this question has already been asked.)]
I've the batchfile D:\Hydroper\Projects\Java\ASC\bin\asc.cmd that executes a JAR file .\target\asc-1.jar in the same directory. Absolute path: D:\Hydroper\Projects\Java\ASC\bin\target\asc-1.jar.
However, when I execute my batchfile, I get the Unable to access jarfile error:
asc -strict Main.as
but my JAR is there. Even adding a .jar or executing with admin privileges the error persists. It was automatically built with Maven.
Here my batch:
java -jar "D:\Hydroper\Projects\Java\ASC\bin\target\asc-1" %*
It works when I do java -jar ... args manually in the command-line, but I don't like that. I prefer aliasing that command.
ClassPath
I've instead also tried something like:
java macromedia.asc.embedding.Main "%*"
It works fine, but ASC doesn't. asc -help works fine, but asc -help Main.as says my AS file cannot be found, but I'm in the right directory.
Simply do the below:-
cd D:\Hydroper\Projects\Java\ASC\bin
copy the asc.cmd file to bin folder and modify the batch file like below
java -jar target\asc-1.jar
First execute the above command from command prompt first before executing the same from batch file like below:-
cd D:\Hydroper\Projects\Java\ASC\bin
java -jar target\asc-1.jar
When we use a batch file or shell script to run a java application do it like below:-
in your batch file
CP="C:\lib\example1.jar;C:\lib\example2.jar;D:\Hydroper\Projects\Java\ASC\bin\target\asc-1.jar"
java -cp %CP% com.your.java.class.MyExample
Related
I store jar files in C:\Users\myuser\javatools\avro-tools
And added them to my PATH:
echo %PATH%
...;
C:\Users\myuser\javatools\avro-tools;
I can run them by specifying the full path:
java -jar C:\Users\myuser\javatools\avro-tools\avro-tools-1.8.1.jar
But cannot run them without the full path:
java -jar avro-tools-1.8.1.jar
Error: Unable to access jarfile avro-tools-1.8.1.jar
I need to run jar files without changing to the directory, nor specifying these full paths.
UPDATE: Added %*
I'd recommend creating a batch file and run that instead.
avro-tools-1.8.1.bat
#echo off
java -jar C:\Users\myuser\javatools\avro-tools\avro-tools-1.8.1.jar %*
Place .bat file somewhere in PATH, and run by simply typing:
avro-tools-1.8.1.bat -abc def
The %* in the .bat file gets replaced with any argument passed to the .bat file, so the -abc def arguments are passed to the avro-tools program in the args array to the main method.
If you have multiple versions of Java installed, you can then choose which one to use when running that .jar file, by also qualifying the java command.
avro-tools-1.8.1.bat
#echo off
"C:\Program Files\Java\jdk1.8.0_181\java.exe" -jar C:\Users\myuser\javatools\avro-tools\avro-tools-1.8.1.jar %*
Now that code will run with Java 8, even if Java 8 is not the default Java on your machine.
I'm trying to run a script from an Amazon Linux machine. The script invokes checkstyle like this (in a script called eval.sh):
CHECKSTYLE="java -jar /home/ec2-user/grader/ext/checkstyle-6.15-all.jar"
CHECKSTYLE_RULES="/home/ec2-user/grader/config/checks.xml"
CHECKSTYLE_OUT="quality.log"
"${CHECKSTYLE}" -c "${CHECKSTYLE_RULES}" -f xml -o "${CHECKSTYLE_OUT}" $(find "${_toCheck}" -name "*.java") 2>"quality.err"
When I run this, I get the following error in quality.err:
./grader/eval.sh: line 10: java -jar /home/ec2-user/grader/ext/checkstyle-6.15-all.jar: No such file or directory
I have tried to run the same command directly in the terminal and it is working. Both checkstyle-6.15-all.jar and checks.xml are where they should be.
What could cause this problem?
Change "${CHECKSTYLE}" to ${CHECKSTYLE} (without the quotes).
You are passing the entire value of the CHECKSTYLE variable as a single word (that's what the quotes do), so the shell is looking for a relative directory named java -jar, and is trying to find a file under that (nonexistent) directory with the path home/ec2-user/grader/ext/checkstyle-6.15-all.jar.
When you envoke "${CHECKSTYLE}" the shell thinks that is the command you are running. There is no such file name with the spaces and options have you have included there. If you envoke it simply as ${CHECKSTYLE} (drop the quotes) the shell will process it for whitespace as normal and split it into the appropriate pieces for creating the process.
I am trying to launch a jar file on Windows Server 2008 R2 startup.
I tried to add a key\value to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
I tried as a value several alternatives:
java -jar c:\jcm\jcm.jar
"java -jar c:\jcm\jcm.jar"
c:\program files(x86)\java\jre1.8.31\bin\java.exe -jar c:\jcm\jcm.jar
"c:\program files(x86)\java\jre1.8.31\bin\java.exe -jar c:\jcm\jcm.jar"
"c:\program files(x86)\java\jre1.8.31\bin\java.exe" -jar c:\jcm\jcm.jar
But none of them launched the program.
Can you advise please?
EDIT: Fixed exe to jar of course
You probably have a problem in the command line. I think it should be something like that last row that you have used but with jar and not exe.
"c:\program files(x86)\java\jre1.8.31\bin\java.exe" -jar c:\jcm\jcm.jar
You just need to test it in command line first and if it works it will work in the registry. You can also make a .bat file to start the java program and copy that to windows Startup Folder instead of using the registry.
The startup folder you can find here:
http://windows.microsoft.com/en-us/windows/run-program-automatically-windows-starts#1TC=windows-7
If it is Windows 10 then you may try this way-
Create a batch file e.g. (my-batch.bat with below statements.)
#echo off
title my-app batch script!
echo my-app welcomes you!
:: If your JAR contains GUI then use-
start javaw -Xmx200m -jar D:\Softwares\JAR\my-app-v1.0.jar
:: Otherwise use-
start java -jar D:\Softwares\JAR\my-app-v1.0.jar
Copy this my-batch.bat file at
C:\Users\pc\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Restart your PC to execute your JAR on startup.
Now, You may check your running JAR using Command Prompt with below commands-
1. jps -l
Output will look like-
8120 sun.tools.jps.Jps
13276 D:\Softwares\JAR\my-app-v1.0.jar
2. tasklist /V
After having used NetBeans to create a Java program call it Addition and then having successfully cleaned and built an Executable Jar File in a folder c:\Users\Ben\Doc\NetBeansProjects\Addition\dist
WHY is it that when executing, from command prompt,
c:\Users\Ben Java -Jar -cp "c:\Users\Ben\Doc\NetBeansProjects\Addition\dist" Addition.jar
it does NOT work (i get 'unable to access jarfile Addition.jar)
BUT if i use cd to change my current dir to c:\Users\Ben\Doc\NetBeansProjects\Addition\dist and THEN run 'java -jar Addition.jar' from there, the Addition program runs fine
The -classpath argument is ignored when you use the -jar option. See the documentation.
because java doesn't look in classpath to launch jar file for this command it needs file as input
so if you set the directory where your jar file is placed and try to execute java -jar command and expect it to pick up jar from that directory because it is in classpath it is not valid
you can give full path to jar like from any directory
java -jar c:\Users\Ben\Doc\NetBeansProjects\Addition\dist\Addition.jar
I'm having the following situation.
I have a java programm packed in a jar file. If I call java -jar myProgramm.jar everything is working fine. The file is reading some values from build.xml (ant file). This file is in the same directory where myProgramm.jar is located.
In our company we wrap everything in shell scripts to have a uninfied way to call our scripts.
So my shell script myProgrammWrapper.sh looks like this:
#!bin/bash
java -jar $(cygpath -w ~/path/to/tools/myProgramm.jar) "$#"
The cygpath command is there because the sh is executed within cygwin and otherwise the path would not be found.
The"$#" passes the arguments to the program.
Following is the problem:
Our cygwin environment has been setup in a way that I can call myProgrammWrapper.sh from every directory. But of course when I call it from any random location, the build.xml is not found.
Is there a way to reference the build.xml in the shell script. It is located in ~/path/to/tools/ ?
First I was thinking about copying the build file to the current directory and deleting it afterwards. This is working fine but has one fundamental flaw. We are working a lot with ant and have build.xml files. So if someone would execute myProgrammWrapper.sh in a directory where there is already a build.xml file. It would be overwritten.
Maybe the problem can be tackled from the Java side. Any ideas and input is appreciated.
Why not make the Bash script change the working directory to where the XML file is contained?
Try:
(cd $(cygpath -w ~/path/to/tools/) && java -jar $(cygpath -w ~/path/to/tools/myProgramm.jar) "$#")