I'm currently working on a java library (binding) which uses some own written native code. This native code is compiled as a .so file for multiple architectures (arm-v7, i686, x86-64, etc).
I know in android you have to create a folder called jniLibs with subfolders for each architecture containing the proper .so file. Then with an Android.mk file and System.loadLibrary I can include these files into my code.
However, I have no clue how to include these .so files in a normal java project/library. I have read online that System.loadLibrary only works for looking through normal files (and not necessarily project files).
You can't have anything other than code in an android .jar file, however, you can have resources in an .aar file.
Android Archive Library (aar) vs standard jar
You will find that the .aar for your library is the redistributable/reusable compiled version of your library.
You can do it as how SWT did it -- extract the library files from your .jar file to user's home directory (so you are sure you have access to write in it) manually by java code.
You can check the source code of org.eclipse.swt.internal.Library, method extract().
I am trying to use sqlite4java in my android project. the following screenshot shows my project's setup:
As you can see i have copied the jar-file into my libs folder and included it in the build path. I have also copied the docs and the src-file as per the docs for sqlite4java. The zip-file i downloaded also contains a library-file called libsqlite4java-android-i686.sothat i included in the libs directory. what i get when i try to run my project (it will compile without complaining) is the follwing error message:
03-04 07:37:13.251: W/System.err(2419):
com.almworks.sqlite4java.SQLiteException: [-91] cannot load library:
java.lang.UnsatisfiedLinkError: Couldn't load sqlite4java-android-i686
from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data
/app/de.redhouse24.android-2.apk"],nativeLibraryDirectories=[/data
/app-lib/de.redhouse24.android-2, /system/lib]]]: findLibrary returned
null
As you can see the file sqlite4java-android-i686.socannot be found. Being wiley, i renamed the libsqlite4java-andriod-i686.so file to sqlite4java-android-i686.so, which is why my project structure shows that name for the file. TBH, i renamed it because i found the suggestion in this discussion:
https://code.google.com/p/sqlite4java/issues/detail?id=42
I also tried to include the so-file in the build path, but that just stopped my project from compiling.
My question: What do i need to do to use sqlite4java in my android project?
Im using a mac and eclipse with adt, if that makes any difference.
First of all, renaming the library will not help you. Do not rename the library, leave the name as it was.
Second, you only have the 686-lib there.
If you intent to run your app on something other than an atom-based device, you will have to add the so-files for the other architectures as well.
Each architecture's so-files resides in a sub-directory under the libs directory, like this:
libs/x86
libs/armeabi
libs/armeabi-v7a
Put your libsqlite4java-android-i686.so file there, and also possible other .so files it might need as a dependency, and it should work.
Including the sources and docs into the libs-folder somewhat eludes me. That will only bloat your final apk file, which should be avoided.
Your users will be thankful.
I downloaded an Open Source tool from www.openempi.org used to find duplicate patients. It is referred to as an EMPI tool (Enterprise Master Patient Index). I am a .Net programmer and not a Java programmer, but I have worked with other Java products where I receive a Jar file and run it like a Windows executable.
The zip file contained several Jar files but when I double-click on them I get Failed to load Main-Class manifest from.... After I Googled this term and reading a few posts about it, including several on this site, this seems to indicate that I should have done something different when creating the Jar file, but I didn't create the Jar file. Will I need to use Eclipse or some other tool to get past this, or is there something I'm doing wrong when try to load the Jar? Could it be a Java version issue?
The zip also contained a ./conf folder with several XML, CSV, and SQL files.
Greg
I don't think you want to execute the .jars found in that .zip file. Instead, you should try using the Application.html found after extracting from the openempi-webapp-web-versionhere.war.
I've been working on a processing application using ControlP5 and Twitter4j. I want to have my project run from a single jar file from any operating system. Basically I want to package up my application. My application uses images. I've been browsing for more than an hour, but I cant find how to do this. Any suggestions?
using
processing 2
twitter4j3
Thanks in advance!
I dont know if you can directly do it from the Processing IDE however, if export your sketch to a Java applet then locate the .java the the sketch folder you can use this in conjunction with Eclipse to export to a jar file.
So, I know that this post is very old but if you are still looking for a solution, or to other people that see this thread, it's relatively simple.
Export the project
In the folder with the exported project (something like application.windows64), navigate to lib and find core.jar and project name.jar (you need to have file name extensions visible)
Rename the files to .zip files
Extract core.jar to whatever folder
Extract project name.jar into the same folder (make sure you don't do it into a subfolder)
Click yes if it asks if it wants you to replace a file (if it doesn't you extracted the files incorrectly)
Delete core.jar and project name.jar
If the project uses images, move them into the same folder as all the other files
Select all of the files in the folder, right click, hover over send to and select compressed (zipped) folder
Rename the .zip file to name of project.jar
This might be old, but i still find other posts about it on processing forums.
This is the best way to run processing project as a jar file.
When exporting application, you will always end up with a lib folder inside exported application(whether for Linux and Windows). For windows, open command prompt(or power shell), you can use right-click+shift and then click on open power shell here.
After that you can run the following command.
java -classpath lib\* DisplayDepthStream
Now DisplayDepthStream is the name of sketch file.
To explain the command, -classpath lib\* tells java to add everything under lib directory to the class path. And DisplayDepthStream is the name of my main class.
Hope this helps~!
Chears
I would like to modify a file inside my jar. Is it possible to do this without extracting and re jarring, from within my application?
File i want to modify are configuration files, mostly xml based.
The reason i am interested in not un jarring is that the application is wrapped with launch4j if i unjar it i can't create the .exe file again.
You can use the u option for jar
From the Java Tutorials:
jar uf jar-file input-file(s)
"Any files already in the archive having the same pathname as a file being added will be overwritten."
See Updating a JAR File.
Much better than making the whole jar all over again. Invoking this from within your program sounds possible too. Try Running Command Line in Java
You can use Vim:
vim my.jar
Vim is able to edit compressed text files, given you have unzip in your environment.
Java jar files are the same format as zip files - so if you have a zip file utility that would let you modify an archive, you have your foot in the door. Second problem is, if you want to recompile a class or something, you probably will just have to re-build the jar; but a text file or something (xml, for instance) should be easily enough modified.
As many have said, you can't change a file in a JAR without recanning the JAR. It's even worse with Launch4J, you have to rebuild the EXE once you change the JAR. So don't go this route.
It's generally bad idea to put configuration files in the JAR. Here is my suggestion. Search for your configuration file in some pre-determined locations (like home directory, \Program Files\ etc). If you find a configuration file, use it. Otherwise, use the one in the JAR as fallback. If you do this, you just need to write the configuration file in the pre-determined location and the program will pick it up.
Another benefit of this approach is that the modified configuration file doesn't get overwritten if you upgrade your software.
Not sure if this help, but you can edit without extracting:
Open the jar file from vi editor
Select the file you want to edit from the list
Press enter to open the file do the changers and save it
pretty simple
Check the blog post for more details
http://vinurip.blogspot.com/2015/04/how-to-edit-contents-of-jar-file-on-mac.html
I have similar issue where I need to modify/update a xml file inside a jar file.
The jar file is created by a Spring-boot application and the location of the file is BOOT-INF/classes/properties
I was referring this document and trying to replace/update the file with this command:
jar uf myapp.jar BOOT-INF/classes/properties/test.xml
But with this, it wont change the file at the given location. I tried all the options also but wont work.
Note: The command I am executing from the location where jar file is present.
The solution I found is:
From the current location of jar file, I created folders BOOT-INF/classes/properties
Copy the test.xml file into the location BOOT-INF/classes/properties.
Run the same command again. jar uf myapp.jar BOOT-INF/classes/properties/test.xml
The xml file has been changed in the jar file.
Basically you need to create a folder structure like where the file is located into the jar file. Copy the file at that location and then execute the command.
The problem with the documentation is that, it does not have enough examples as well as explanation around common scenarios.
This may be more work than you're looking to deal with in the short term, but I suspect in the long term it would be very beneficial for you to look into using Ant (or Maven, or even Bazel) instead of building jar's manually. That way you can just click on the ant file (if you use Eclipse) and rebuild the jar.
Alternatively, you may want to actually not have these config files in the jar at all - if you're expecting to need to replace these files regularly, or if it's supposed to be distributed to multiple parties, the config file should not be part of the jar at all.
To expand on what dfa said, the reason is because the jar file is set up like a zip file. If you want to modify the file, you must read out all of the entries, modify the one you want to change, and then write the entries back into the jar file. I have had to do this before, and that was the only way I could find to do it.
EDIT
Note that this is using the internal to Java jar file editors, which are file streams. I am sure there is a way to do it, you could read the entire jar into memory, modify everything, then write back out to a file stream. That is what I believe utilities like 7-Zip and others are doing, as I believe the ToC of a zip header has to be defined at write time. However, I could be wrong.
Yes you can, using SQLite you can read from or write to a database from within the jar file, so that you won't have to extract and then re jar it, follow my post http://shoaibinamdar.in/blog/?p=313
using the syntax "jdbc:sqlite::resource:" you would be able to read and write to a database from within the jar file
Check out TrueZip.
It does exactly what you want (to edit files inline inside a jar file), through a virtual file system API. It also supports nested archives (jar inside a jar) as well.
Extract jar file for ex. with winrar and use CAVAJ:
Cavaj Java Decompiler is a graphical freeware utility that reconstructs Java source code from CLASS files.
here is video tutorial if you need:
https://www.youtube.com/watch?v=ByLUeem7680
The simplest way I've found to do this in Windows is with WinRAR:
Right-click on the file and choose "Open with WinRAR" from the context menu.
Navigate to the file to be edited and double-click on it to open it in the default editor.
After making the changes, save and exit the editor.
A dialogue will then appear asking if you wish to update the file in the archive - choose "Yes" and the JAR will be updated.
most of the answers above saying you can't do it for class file.
Even if you want to update class file you can do that also.
All you need to do is that drag and drop the class file from your workspace in the jar.
In case you want to verify your changes in class file , you can do it using a decompiler like jd-gui.
As long as this file isn't .class, i.e. resource file or manifest file - you can.