Run jar files - FlowDroid on mac terminal - java

I need to run a Java lib called FlowDroid in the Mac terminal.
I followed the documents and download the nighty build version of FlowDroid project.
After that, I use the commands that provided in the website but it does not work.
java -cp soot.jar;soot-infoflow.jar;soot-infoflow-android.jar;slf4j-api-1.7.5.jar; slf4j- simple-1.7.5.jar;axml-1.0.jar soot.jimple.infoflow.android.TestApps.Test "D:\Callbacks_Button1.apk" D:\Tools\AndroidSDK\sdk\platforms
I think it is a Java classpath problem, but I cannot figure it out. Whats wrong with the above commands?

As we don't have your exact error, that's pretty difficult to help. Anyway, on Mac OS X you should use the : as a classpath separator instead of ; which is for Windows systems.
Your command line should then look like:
java -cp soot.jar:soot-infoflow.jar:soot-infoflow-android.jar:slf4j-api-1.7.5.jar:slf4j-simple-1.7.5.jar:axml-1.0.jar soot.jimple.infoflow.android.TestApps.Test "D:\Callbacks_Button1.apk" D:\Tools\AndroidSDK\sdk\platforms

Related

How to create very small JRE using jrecreate in ejdk for windows 10?

I want to ship my java application (command line tool) along with a small jre. I tried a lot using jrecreate options of ejdk but, I am unable to create jre for windows 10. Please help me in this regard. I referred the following links. It is always creating for linux. How to do it for Windows ?
I used the the following command:
jrecreate.bat --profile compact2 --dest compact2-client --vm all
https://blogs.oracle.com/jtc/introducing-the-ejdk
https://www.oracle.com/technetwork/java/embedded/embedded-se/downloads/index.html
https://docs.oracle.com/javase/8/embedded/develop-apps-platforms/installing.htm
Assumption:
You already know what you are going to package into your JRE.
Like you have a list of dependencies or you have a jar file and you need to extract the dependencies and create a JRE with only those dependencies
If Java version is not of concern then you can stick to Java 9 and follow this post here.
https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4
I tried this a couple of weeks ago and it worked.
Regarding Win or Linux, it depends upon where you are running the jlink command
I used the following command to get compacted jre with profile compact1 in MAC.
jrecreate.sh -d ./compact1-jre/ -p compact1

run jar on mac with arguments

I have a bioinformatics related tool can be found here. The tool can be download from the link under that page.
It is a Java packaged files for which on Windows I can run
a compiled version (see the readme, need to change name of Mold2.doc to Mold2.exe) using the following command line:
Mold2 -i TestCompounds.sdf
(I have moved the TestCompounds.sdf file to same path as that exe)
It will produce some message and output 2 files output.txt and report.txt.
The trouble is that this package doesn't have any pre-compiled version executable for Mac OS.
However, since Java is supposedly cross-platform and since I also have the java Mold2.jar file, I think it would work for me if I can execute under Mac OS. But I can find the way how to do that...
I have tried with:
java -cp Mold2.jar Mold2
But it only invoke the GUI, and I can't find how to execute this program with only arguments under terminal without invoking the GUI, which is what I want is for integration purpose.
So how can I run this tool on Mac OS on terminal?

Simple way to run java classfile (Terminal)

I wanted to put a java classfile up for download recently, which people could run in Terminal. It's a Minecraft command generator, so the people downloading it won't necessarily have the greatest mental capacity (I'm referring to 8-year-olds who have no idea what they're doing, of course).
Anyway, I wanted to provide a simple, single command, both for the Mac / Linux terminal and the Windows command line, that ran the classfile without any complications. The problem is, I don't want to execute it by doing /cd path, and then doing java someFolder.someClass. I just want to have a single command to open the file. If anyone could provide these commands for me, both in Mac / Linux and Windows, that would be great.
Sorry for the super long explanation :P
A jar file with a main class in the manifest would probably be the easiest thing. Then the command is java -jar myjarfile.jar.
A swing application would probably be easier as the default way of running executable jars doesn't open a command prompt (it uses javaw instead of java).
You will have to first start a terminal and then run java in that terminal, which can be a bit tricky.
How to open a command terminal in Linux?
Why not create an interface (Swing) and pack everything in a jar?

Unable to run threaded java jar file on Mac OS X 10.6.8 with Java 1.7.0.45 using pacifist

I have installed Java 1.7.0_45 on Mac OS X 10.6.8 using Pacifist [http://www.charlessoft.com/] however I am unable to run a jar file which I have downloaded. The jar file is a threaded application.
The error message I am getting is:
java -jar context.jar
2013-10-31 14:14:41.898 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement methodSignatureForSelector: -- trouble ahead
2013-10-31 14:14:41.900 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement doesNotRecognizeSelector: -- abort
Trace/BPT trap
Is there anyway I can run the jar. I have set the JAVA_HOME path properly and java -version is showing 1.7.0_45 as the version.
The same application works properly on Windows Java 1.7.0_45 and also on Linux Java 1.7.
The web search for the solution and the given keywords return very few results and none of them have any specific solution in it. I am new to mac so I am not fully able to understand the issue.
Alternatively, is there anyway I can run Java from folder in Mac like I can do in windows and Linux by just extracting the Java contents and changing the JAVA_HOME. If that is possible then I should be able to run my JAR.
I had kind of same problem while installing an application through jar file, my Java was not detected by the jar application installer,
Over here I see that one of the method is not accessible, could be a same problem. But I am not very sure of it.
make sure you have rt.jar in your JAVA_HOME/jre/lib/ folder
In case you don't have then you are required to have it through the process of creation of symbolic link.
In the command below replace your_java_version with proper version matching your requirement.
sudo mkdir -p /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib
Go into the directory:
cd /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib/
Create symbolic link :
sudo ln -s ../../../Classes/classes.jar rt.jar
Hope this solves your problem.
I get the exact same problem with MacOS 10.6.8 and JDK 7. In order to run the jar I had to use the System JRE which is 1.6.x (In my case I wanted to install Squirrel
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar >squirrel-sql-3.6-MACOSX-install.jar

What causes "Unable to access jarfile" error?

I want to execute my program without using an IDE.
I've created a jar file and an exectuable jar file. When
I double click the exe jar file, nothing happens, and when I try to use the command in cmd it gives me this:
Error: Unable to access jarfile <path>
I use the command: java -jar Calculator.jar
How I created the jar:
Right click on project folder (Calculator)
Select
Click on Java Folder and select "Exectuable Jar File", then select next
Launch Configuration: Main - Calculator
Create Export Destination
Hit "Finish" and profit! Well, not really.
I had encountered this issue when I had run my Jar file as
java -jar TestJar
instead of
java -jar TestJar.jar
Missing the extension .jar also causes this issue.
Fixed
I just placed it in a different folder and it worked.
[Possibly Windows only]
Beware of spaces in the path, even when your jar is in the current working directory. For example, for me this was failing:
java -jar myjar.jar
I was able to fix this by givng the full, quoted path to the jar:
java -jar "%~dp0\myjar.jar"
Credit goes to this answer for setting me on the right path....
I had this issue under CygWin in Windows. I have read elsewhere that Java does not understand the CygWin paths (/cygdrive/c/some/dir instead of C:\some\dir) - so I used a relative path instead: ../../some/dir/sbt-launch.jar.
I had the same issue when trying to launch the jar file. The path contained a space, so I had to place quotes around. Instead of:
java -jar C:\Path to File\myJar.jar
i had to write
java -jar "C:\Path to File\myJar.jar"
Just came across the same problem trying to make a bad USB...
I tried to run this command in admin cmd
java -jar c:\fw\ducky\duckencode.jar -I c:\fw\ducky\HelloWorld.txt -o c:\fw\ducky\inject.bin
But got this error:
Error: unable to access jarfile c:\fw\ducky\duckencode.jar
Solution
1st step
Right click the jarfile in question. Click properties.
Click the unblock tab in bottom right corner.
The file was blocked, because it was downloaded and not created on my PC.
2nd step
In the cmd I changed the directory to where the jar file is located.
cd C:\fw\ducky\
Then I typed dir and saw the file was named duckencode.jar.jar
So in cmd I changed the original command to reference the file with .jar.jar
java -jar c:\fw\ducky\duckencode.jar.jar -I c:\fw\ducky\HelloWorld.txt -o c:\fw\ducky\inject.bin
That command executed without error messages and the inject.bin I was trying to create was now located in the directory.
Hope this helps.
None of the provided answers worked for me on macOS 11 Big Sur. The problem turned out to be that programs require special permission to access the Desktop, Documents, and Downloads folders, and Java breaks both the exception for directly opened files and the permission request popup.
Fixes:
Move the .jar into a folder that isn’t (and isn’t under) Documents, Desktop, or Downloads.
Manually grant the permission. Go to System Preferences → Security and Privacy → Privacy → Files and Folders → java, and check the appropriate folders.
I had a similar problem and I even tried running my CMD with administrator rights, but it did not solve the problem.
The basic thing is to make sure to change the Directory in cmd to the current directory where your jar file is.
Do the following steps:
Copy jar file to Desktop.
Run CMD
Type command cd desktop
Then type java -jar filename.jar
This should work.
Edit: From JDK-11 onwards ( JEP 330: Launch Single-File Source-Code Programs )
Since Java 11, java command line tool has been able to run a single-file source-code directly. e.g.
java filename.java
If you are using OSX, downloaded files are tagged with a security flag that prevents unsigned applications from running.
to check this you can view extended attributes on the file
$ ls -l#
-rw-r--r--# 1 dave staff 17663235 13 Oct 11:08 server-0.28.2-java8.jar
com.apple.metadata:kMDItemWhereFroms 619
com.apple.quarantine 68
You can then clear the attributes with
xattr -c file.jar
It can also happen if you don't properly supply your list of parameters. Here's what I was doing:
java -jar test#gmail.com testing_subject file.txt test_send_emails.jar
Instead of the correct version:
java -jar test_send_emails.jar test#gmail.com testing_subject file.txt
This worked for me.
cd /path/to/the/jar/
java -jar ./Calculator.jar
For me it happens if you use native Polish chars in foldername that is in the PATH.
So maybe using untypical chars was the reason of the problem.
sometime it happens when you try to (run or create) a .jar file under /libs folder by right click it in android studio. you can select the dropdown in top of android stuio and change it to app. This will work
My particular issue was caused because I was working with directories that involved symbolic links (shortcuts). Consequently, trying java -jar ../../myJar.jar didn't work because I wasn't where I thought I was.
Disregarding relative file paths fixed it right up.
In my case the suggested file name to be used was jarFile*.jar in the command line. The file in the folder was jarFile-1.2.3.jar . So I renamed the file to jarFile. Then I used jarFile.jar instead of jarFile*.jar and then the problem got resolved
It can happen on a windows machine when you have spaces in the names of the folder. The solution would be to enter the path between " ".
For example:
java -jar c:\my folder\x.jar -->
java -jar "c:\my folder\x.jar"
To avoid any permission issues, try to run it as administrator. This worked for me on Win10.
I know this thread is years ago and issue was fixed too. But I hope this would helps someone else in future since I've encountered some similar issues while I tried to install Oracle WebLogic 12c and Oracle OFR in which its installer is in .jar format. For mine case, it was either didn't wrap the JDK directory in quotes or simply typo.
Run Command Prompt as administrator and execute the command in this format. Double check the sentence if there is typo.
"C:\Program Files\Java\jdk1.xxxxx\bin\java" -jar C:\Users\xxx\Downloads\xxx.jar
If it shows something like JRE 1.xxx is not a valid JDK Java Home, make sure the System variables for JAVA_HOME in Environment Variables is pointing to the correct JDK directory. JDK 1.8 or above is recommended (2018).
A useful thread here, you may refer it: Why its showing your JDK c:program files\java\jre7 is not a valid JDK while instaling weblogic server?
For me it happen because i run it with default java version (7) and not with compiled java version (8) used to create this jar.
So i used:
%Java8_64%\bin\java -jar myjar.jar
Instead of java 7 version:
java -jar myjar.jar
I had a similar problem where TextMate or something replaced the double quotes with the unicode double quotes.
Changing my SELENIUM_SERVER_JAR from the unicode double quotes to regular double quotes and that solved my problem.
this is because you are looking for the file in the wrong path
1. look for the path of the folder where you placed the file
2. change the directory cd in cmd use the right path
I use NetBeans and had the same issue. After I ran build and clean project my program was executable. The Java documentation says that the build/clean command is for rebuilding the project from scratch basically and removing any past compiles. I hope this helps. Also, I'd read the documentation. Oracle has NetBeans and Java learning trails. Very helpful. Good luck!
Maybe you have specified the wrong version of your jar.
I finally pasted my jar file into the same folder as my JDK so I didn't have to include the paths. I also had to open the command prompt as an admin.
Right click Command Prompt and "Run as administrator"
Navigate to the directory where you saved your jdk to
In the command prompt type: java.exe -jar <jar file name>.jar
Keep the file in same directory where you are extracting it. That worked for me.
This is permission issue, see if the directory is under your User.
That's why is working in another folder!
Rename the jar file and try
Explanation :
yes, I know there are many answers still I want to add one point here which I faced.
I built the jar and I moved it into the server where I deploy (This is the normal process)
here the file name which I moved already existed in the server, here the file will override obviously right. In this case, I faced this issue.
maybe at the time of overriding there can be a permission copy issue.
Hope this will help someone.
Have you tried to run it under administrator privoleges?
meaning, running the command in "Run As" and then select administrator with proper admin credentials
worked for me
I was trying this:
After giving the file read, write, execute priviledges:
chmod 777 java-repl.jar
alias jr="java -jar $HOME/Dev/java-repl/java-repl.jar"
Unable to access bla bla..., this was on Mac OS though
So I tried this:
alias jr="cd $HOME/Dev/java-repl/ && java -jar java-repl.jar"
This did not work "Unable to access jarfile"
"C:\Program Files\java\jdk-13+33-jre\bin\javaw.exe" -jar "C:\Program Files\Maxim Integrated Products\1-Wire Drivers x64\ OneWireViewer.jar"
This does work
"C:\Program Files\java\jdk-13+33-jre\bin\javaw.exe" -jar "C:\Program Files\Maxim Integrated Products\1-Wire Drivers x64\OneWireViewer.jar"
The difference is the single space in front of OneWireViewer.jar not withstanding that it is surrounded with quotes and even has other spaces.

Categories