Java: Unable to access jarfile when running as an admin - java

I have a jar file named test.jar, which I am running with a batch script from the same folder.
Here's the batch code:
java -jar test.jar
pause
The jar itself works with no problems, and I can run it just fine.
However, if I try to run the batch file as an administrator (by right clicking it and choosing "Run as Administrator"), I get the following error:
Error: Unable to access jarfile test.jar
I'm using Windows 8.1, but this also happened on a machine running Windows 7.
What can I do to be able to run this as an Administrator?

i had the same problem that you and i solved it by changing
java -jar test.jar
to
java -jar %~dp0test.jar
%~dp0 holds the directory of your bat file (AFAIK) so %~dp0 will give Java the full path to the jar file solving the problem.

You could also ad a temp path to java
path=C:\Program Files\Java\jre1.8.0_40\bin
Java script
path=

Related

How to run jar file on shell script in linux terminal?

I made a java project.
The project is....output log message and system.out.println message. just simple.
So I changed into a jar file(the name is LinuxSample.jar).
and I wrote a shell script to run this jar file.
Look at this shell script. (speakee is package name and PrintLinux is main class name)
#!bin/bash
CLASSPATH=/home/tangooc/TANGOOC/test/libs/*
CLASSPATH="${CLASSPATH};/home/tangooc/TANGOOC/test/linux/LinuxSample.jar"
java speakee.PrintLinux
this jar file and this shell script work in Window.
but linux didn't work. I don't know why
this is error message.
Could not find or load main class
Hi Best way to run a java application is to set CLASS_PATH and PATH variable first. If your current jar file depends on external jar files you will face lots of problem. Better set your path variable like below and run the application:-
#!/usr/bin/ksh
export PATH=/usr/java/bin:$PATH
# =/usr/java/bin is your java bin folder
#set environment variable CP with all the jar libraries
CP=/home/flussi/xmlEncoder/encoder.jar
CP=${CP}:/other/jar/somejar.jar
java -Xmx256M -classpath "$CP" "com.myproj.Example"
I made it
I changed the shell script.
CLASSPATH=/home/tangooc/TANGOOC/test/client/LinuxSample.jar
LIB_TOTAL=/home/tangooc/TANGOOC/test/libs/*
echo ${LIB_TOTAL}
echo ${CLASSPATH}
java -cp ${LIB_TOTAL}:${CLASSPATH} speakee.PrintLinux
also there is another way.
CLASSPATH=/home/tangooc/TANGOOC/test/client/LinuxSample.jar
CLASSPATH=${CLASSPATH}:/home/tangooc/TANGOOC/test/libs/*
echo ${CLASSPATH}
java -cp ${CLASSPATH} speakee.PrintLinux
If the someone like me change the shell script.
and check a line, a line, a line...

Open Jar through batch file through PATH

I made a batch file that executes commands through a jar:
#java -jar commands.jar %*
This is the file tree:
C:\
Commands\
commands.bat
commands.jar
I have my PATH variable set to "C:\Commands\" so that I can access the commands from anywhere on the PC. I can successfully run the batch file, but for some reason it won't open the jar. When I type
commands
or
commands help
it says
Error: unable to access jarfile commands.jar
I have tried using quotes around the jar name, I have tried moving the jar... nothing works...
%~dp0 gives bat file path so
#java -jar %~dp0commands.jar %*
See call /? for help (even though we aren't using call).
By using ftype, assoc, and editing with setx the variable pathext to add jar files you can just type the jar's name and have it run without a batch file needed.

Cannot Find Javax.Comm.Properties in Ubuntu 13.04

I have developed an application which results serial ports in combobox, but when I am running .jar file of my application using command terminal using command:
Java -jar Serial_Send.jar //where Serial_Send is name of my jar file
It is resulting into an error Cannot find javax.comm.properties.
But javax.comm.properties file is present in java_home/jre/lib directory.
What else I have to do in order to resolve this.
Try the following command:
java -jar -Djava.class.path=java_home/jre/lib Serial_Send.jar
This will put the lib directory in class path of program explicitly.

command line: Unable to access jarfile eps2pgf.jar

I'm working with a Mac OSX version 10.9.5 and I am a complete newbie to using the command line and running java files in it.
I just downloaded the eps2pgf folder, I unzipped it and I downloaded JDK8.
However when I try to run the command (thats given in the manual) in my Terminal, I get the following error:
Unable to access jarfile eps2pgf.jar
The exact command I use is:
java -jar eps2pgf.jar Bifurcatiediagram.eps -o Bifurcatiediagram.pgf
So in total the command before I run it is (with what is automatically there as well):
mbpvanasteyaert:~ Aranka$ java -jar eps2pgf.jar Bifurcatiediagram.eps -o Bifurcatiediagram.pgf
What am I doing wrong? Should the eps2pgf unzipped folder be in a specific folder/directory or...?

Running .jar file - Double click vs. command line execution

I have a java desktop application that contains the following code:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
System.out.println("check1");
int intResult = compiler.run(System.in, System.out, foutErrorFile, strvalidatePath);
System.out.println("check2");
When I run the corresponding .jar file of this application by executing "java -jar name.jar", both check1 and check2 gets printed and app works fine.
But when i try to run the jar by double clicking the .jar file, I found that ToolProvider.getSystemJavaCompiler() is returning null. "check2" does not get printed. I dont get proper result from compiler.run().
I did modify the registry entry "\HKEY_CLASSES_ROOT\jarfile\shell\open\command" from
"C:\Program Files\Java\jre1.6.0\bin\javaw.exe" -jar "%1" %* to
"C:\Program Files\Java\jre1.6.0\bin\java.exe" -jar "%1" %*.
This way I'm able to see the console when the app is running.
So why is my program (which runs fine while run using java -jar command) malfunctioning when I run the .jar file by double-clicking?
I got my problem solved. While double-clicking, the command that gets executed is the one specified in registry entry. In my case the registry entry "\HKEY_CLASSES_ROOT\jarfile\shell\open\command" is:
"C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
This means its uses the javaw.exe app in the JRE directory to execute the program. My JRE directory lacked one .jar file named Tools.jar in its lib folder. This was essential to acquire the compiler during the program execution.
I copied the missing jar file from the JDK directory lib folder to the same in JRE directory. This solved my problem. Thank you to all for helping.
I think the best way is create a .bat file who calls java -jar name.jar

Categories

Resources