I tried 7-zip-jbindings on Mac OS X and it worked for Java. Any hints on what to do for C# .NET using Mono on Mac OS X, for 7-zip library (7z, rar, zip, etc)? Can I use 7-zip-jbindings somehow via C#, or do I need something else? I also saw SevenZipSharp, but I think it's only for Windows. Any leads greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not a .NET expert, but I think there is no way to use 7-Zip-JBinding or any other Java library directly from .NET. I'm sorry. The good news is, that there are some third party Java<->.NET bridges. Just take a look at:
If you are seriously interested in something like 7-Zip-.NETBinding or 7-Zip-NBinding, you could start a new project and try to port 7-Zip-JBinding to .NET ;-) You can count on my support.
Regards,
Boris Brodski
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was hoping that SevenZipSharp (or some other C# wrapper) might be able to support Mac OS X… Or be modified to support Mac OS X. Must be some equivalent of 7z.dll for Mac OS X (and Linux)? I haven't looked at the 7-zip-jbindings source yet, but I don't see the 7z.dll, so maybe it links statically… Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are right, there is no 7z.dll (not any more). The trick of the cross-platform version of 7-Zip-JBinding is, that Windows versions make use of 7-zip code, whether all other versions make use of p7zip code. 7-Zip-JBinding native part consists of the single shared library (DLL/.so file). 7-Zip/p7zip .c and .cpp files are compiled together with 7-Zip-JBinding .cpp files.
I think, that SevenZipSharp uses 7z.dll and there are no equivalent in the Mac OS X world.
If you have questions considering 7-Zip-JBinding source code or build issues or something else please fill free to ask questions here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A) Compile 7-zip/p7zip code directly, and write C++ code wrappers for it, to interface with (map to) C# / .NET, using whatever is the C# / .NET / Mono equivalent of JNI
B) Wrap 7-zip-jbindings with a (Java <-> .NET / C# / Mono) bridge. So the interface / functions / types will map to .NET
Sounds like more work than I was expecting O:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hm, I wonder if the IKVM.NET project (www.ikvm.net) is a reasonable 3rd option… Like, to run 7-zip-jbindings on top of IKVM.NET, via (dynamic mode) or more likely via (static mode - statically compile 7-zip-jbindings libraries into .NET assembly). ( http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=FAQ )
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't tried it yet. But thought maybe could use IKVM.NET (I think static mode, to compile the 7-jbindings libraries into .NET assemply)… Then call that .NET version of 7-zip-jbindings from C# code. Not sure if the idea makes sense.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This should work this way. But the way, I think there will be no big difference in performance between static and dynamic mode, since the most CPU-time will be spend in the native code anyway.
I'm currently busy with a Version 2.0 of 7-Zip-JBinding with a archive creation support, so I will appreciate very much, if you could try to get 7-Zip-JBinding to work with IKVM. We could publish a little tutorial, than. I could also write new tests to make sure future versions of 7-Zip-JBinding work with IKVM as well.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried this today (on Windows 7, 64-bit / x64, Visual Studio 2008), using latest ikvm.net (0.42.0.3). I ran (ikvmc.exe -target:library lib\sevenzipjbinding-AllPlatforms.jar) and (ikvmc.exe -target:library lib\sevenzipjbinding.jar) . Both compiled without any error/warning messages, resulting in sevenzipjbinding-AllPlatforms.dll and sevenzipjbinding.dll.
I created a new Visual Studio project, and added these 2 dll files as a reference. Then wrote this code:
Here are the 3 run-time errors I get (depending on what I pick for init):
The above code (using no init*()'s) gives:
Unhandled Exception: java.lang.RuntimeException: SevenZipJBinding couldn't be initialized automaticly using initialization from platform depended JAR and the default temporary directory. Please, make sure the correct 'sevenzipjbinding-<Platform>.jar' file is in the class path or consider initializing SevenZipJBinding manualy using one of the offered initialization methods: 'net.sf.sevenzipjbinding.SevenZip.init*()'
Changing it to use initSevenZipFromPlatformJAR(strJar) or initSevenZipFromPlatformJAR(strDll) also gives a run-time error:
Unhandled Exception: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: Error loading SevenZipJBinding native library into JVM: error loading property file '/C:\ikvm_generated_7-zip-jbinding\sevenzipjbinding-AllPlatforms.dll/sevenzipjbinding-lib.properties' from a jar-file 'sevenzipjbinding-<Platform>.jar'. Is the platform jar-file not in the class path?
Changing it to use initLoadedLibraries() also gives a run-time error:
> As Volker said, you should combine both jars (I used "ikvmc -out:7zip.dll *.jar"), but doing that still doesn't result in something that works. On x64 I get a stack overflow (I didn't look into this) and on x86 it failed because sevenzipjbind uses JNI in a way that isn't supported by IKVM (and what I believe to be in violation of the spec). They use CallIntMethod to call a method that returns a long. After I added a workaround for that to IKVM (just for testing this), your sample worked (i.e. I could print the number of entries in a RAR).
So based on that, it sounds like he says to modify 7-zip-jbindings to allegedly match the spec?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for this bug report! I will try to find and fix this bug.
The upcoming version (with archive creation support) has a build-in type check, but not the current released version.
About your post 10 and 11:
If you look into sevenzipjbinding-AllPlatforms.jar you will find a couple (one or two) DLLs for each supported platform, but no java code. So it's just resource jar. I don't know, how resources are handled by ikvmc, probably it is 7-ZIp-JBinding's fault, I don't know for sure.
What you could do to exclude this possible source of errors: you could just extract two DLLs for your Win64 platform and forget about sevenzipjbinding-AllPlatforms.jar. Then you should do:
1. Call System.load() for first and then second DLL. (Try it in both orders)
2. Call SevenZip.initLoadedLibraries()
I think, you need either patched IKVM or patched 7-Zip-JBinding. I will try to fix the bug in 7-Zip-JBinding as soon as possible and then build a test version for Win64 for you. If you find it suitable, I will make a bug-fix release.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks, I will hopefully try out this patch sometime tonight, at least on my Win64 machine.
Of course my hope is for Windows / Mac OS X / Linux support… I see that sevenzipjbinding-AllPlatforms.jar is just these 6 libs (x64 / x86 Linux, x64 / x86 Mac OS X, x64 / x86 Windows).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I will make a normal 1.04 release for all those platforms, as long all needed changes are done. Do you need a build for Win32 or Mac OS X as well for test purposes?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am hoping to use sevenzipjbinding-AllPlatforms.jar and sevenzipjbinding.jar (with IKVM), to support Windows, Mac OS X, Linux (both 32-bit and 64-bit). Will the official 1.04 release be soon?
I'm now attempting to download the file via rapidshare.com… It keeps timing out, but I'll keep trying.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I still have not been able to download the file from rapidshare.com … It keeps timing out. Maybe upload to sourceforge, or to somewhere else? Or, if the 1.04 binary release will be within the next 24 hours, I could just wait for that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Btw, did you see the IKVM developer referenced (long net.sf.sevenzipjbinding.impl.RandomAccessFileInStream.seek(long, int)) ? Was that the bug you fixed?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is this what you meant? First, I ran (ikvm.exe sevenzipjbinding.jar) to create sevenzipjbinding.dll. Then, I referenced sevenzipjbinding.dll in my Visual Studio project as a Reference. I unzipped sevenzipjbinding-Windows-amd64.jar to get the 2 dll files. Then I ran with this code:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'ikvm-native': The specified module could not be found. (Exception
from HRESULT: 0x8007007E)
at java.lang.ClassLoader.loadLibrary0(Class , File )
at java.lang.ClassLoader.loadLibrary(Class , String , Boolean )
at java.lang.Runtime.load0(Class , String )
at java.lang.System.load(String filename, CallerID )
at java.lang.System.load(String filename)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The KVM developer said to compile the 2 jar files as 1 dll file, so I tried that, sevenzip
jbinding_withNativeLibs.jar. Then I reference that dll from my Visual Studio project, and ran this code:
I also tried the alternative of adding to the solution the reference to sevenzipjbinding.dll (which only compiles sevenzipjbinding.jar). Then running this code:
Unhandled Exception: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: Error loading SevenZipJBinding native library into JVM: error loading property file '/C:\ikvm_generated_7-zip-jbinding\sevenzipjbinding-Windows-amd64.jar/sevenzipjbinding-lib.properties' from a jar-file 'sevenzipjbinding-<Platform>.jar'. Is the platform jar-file not in the class path?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To 20: java.lang.System.load(<fullpath>) should be the right thing to do. But there are a possibility, that IKVM has some special method to load native library.
To 21: yes, that was the bug I fixed.
To 22: As you can see, the IKVM version of java.lang.System.load() can't file the native library. (Are you sure your strDir is correct and ends with a '/'?)
To 23: That means, that the native library wasn't loaded
To 24: That means, that resources (properties and dll files) couldn't be found.
I will try to talk to IKVM people in order to find out, how to load a native library from C#.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried 7-zip-jbindings on Mac OS X and it worked for Java. Any hints on what to do for C# .NET using Mono on Mac OS X, for 7-zip library (7z, rar, zip, etc)? Can I use 7-zip-jbindings somehow via C#, or do I need something else? I also saw SevenZipSharp, but I think it's only for Windows. Any leads greatly appreciated.
Hi!
I'm not a .NET expert, but I think there is no way to use 7-Zip-JBinding or any other Java library directly from .NET. I'm sorry. The good news is, that there are some third party Java<->.NET bridges. Just take a look at:
http://it.toolbox.com/blogs/daniel-at-work/calling-java-from-microsoftnet-21813
If you are seriously interested in something like 7-Zip-.NETBinding or 7-Zip-NBinding, you could start a new project and try to port 7-Zip-JBinding to .NET ;-) You can count on my support.
Regards,
Boris Brodski
I was hoping that SevenZipSharp (or some other C# wrapper) might be able to support Mac OS X… Or be modified to support Mac OS X. Must be some equivalent of 7z.dll for Mac OS X (and Linux)? I haven't looked at the 7-zip-jbindings source yet, but I don't see the 7z.dll, so maybe it links statically… Thanks
You are right, there is no 7z.dll (not any more). The trick of the cross-platform version of 7-Zip-JBinding is, that Windows versions make use of 7-zip code, whether all other versions make use of p7zip code. 7-Zip-JBinding native part consists of the single shared library (DLL/.so file). 7-Zip/p7zip .c and .cpp files are compiled together with 7-Zip-JBinding .cpp files.
I think, that SevenZipSharp uses 7z.dll and there are no equivalent in the Mac OS X world.
If you have questions considering 7-Zip-JBinding source code or build issues or something else please fill free to ask questions here.
Oh… Sounds like the suggested choices are:
A) Compile 7-zip/p7zip code directly, and write C++ code wrappers for it, to interface with (map to) C# / .NET, using whatever is the C# / .NET / Mono equivalent of JNI
B) Wrap 7-zip-jbindings with a (Java <-> .NET / C# / Mono) bridge. So the interface / functions / types will map to .NET
Sounds like more work than I was expecting O:-)
Hm, I wonder if the IKVM.NET project (www.ikvm.net) is a reasonable 3rd option… Like, to run 7-zip-jbindings on top of IKVM.NET, via (dynamic mode) or more likely via (static mode - statically compile 7-zip-jbindings libraries into .NET assembly). ( http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=FAQ )
IKVM.NET looks very nice. The JNI support is there. I think, this is a very good solution, in case it works as expected.
Did you already test it?
I haven't tried it yet. But thought maybe could use IKVM.NET (I think static mode, to compile the 7-jbindings libraries into .NET assemply)… Then call that .NET version of 7-zip-jbindings from C# code. Not sure if the idea makes sense.
This should work this way. But the way, I think there will be no big difference in performance between static and dynamic mode, since the most CPU-time will be spend in the native code anyway.
I'm currently busy with a Version 2.0 of 7-Zip-JBinding with a archive creation support, so I will appreciate very much, if you could try to get 7-Zip-JBinding to work with IKVM. We could publish a little tutorial, than. I could also write new tests to make sure future versions of 7-Zip-JBinding work with IKVM as well.
I tried this today (on Windows 7, 64-bit / x64, Visual Studio 2008), using latest ikvm.net (0.42.0.3). I ran (ikvmc.exe -target:library lib\sevenzipjbinding-AllPlatforms.jar) and (ikvmc.exe -target:library lib\sevenzipjbinding.jar) . Both compiled without any error/warning messages, resulting in sevenzipjbinding-AllPlatforms.dll and sevenzipjbinding.dll.
I created a new Visual Studio project, and added these 2 dll files as a reference. Then wrote this code:
// CODE BEGIN
string strDll = @"C:\ikvm_generated_7-zip-jbinding\sevenzipjbinding-AllPlatforms.dll";
string strJar = @"C:\sevenzipjbinding\sevenzipjbinding-AllPlatforms.jar";
//net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJAR(strJar);
//net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJAR(strDll);
//net.sf.sevenzipjbinding.SevenZip.initLoadedLibraries();
string fileName = @"C:\testfile.cbr";
java.io.RandomAccessFile randomAccessFile = new java.io.RandomAccessFile(fileName, "r");
ISevenZipInArchive archive = net.sf.sevenzipjbinding.SevenZip.openInArchive(
net.sf.sevenzipjbinding.ArchiveFormat.RAR,
new net.sf.sevenzipjbinding.impl.RandomAccessFileInStream(randomAccessFile));
System.Console.WriteLine(archive.getNumberOfItems());
archive.close();
randomAccessFile.close();
// CODE END
This compiled. However, when I run, I always get a run-time error…
Here are the 3 run-time errors I get (depending on what I pick for init):
The above code (using no init*()'s) gives:
Unhandled Exception: java.lang.RuntimeException: SevenZipJBinding couldn't be initialized automaticly using initialization from platform depended JAR and the default temporary directory. Please, make sure the correct 'sevenzipjbinding-<Platform>.jar' file is in the class path or consider initializing SevenZipJBinding manualy using one of the offered initialization methods: 'net.sf.sevenzipjbinding.SevenZip.init*()'
Changing it to use initSevenZipFromPlatformJAR(strJar) or initSevenZipFromPlatformJAR(strDll) also gives a run-time error:
Unhandled Exception: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: Error loading SevenZipJBinding native library into JVM: error loading property file '/C:\ikvm_generated_7-zip-jbinding\sevenzipjbinding-AllPlatforms.dll/sevenzipjbinding-lib.properties' from a jar-file 'sevenzipjbinding-<Platform>.jar'. Is the platform jar-file not in the class path?
Changing it to use initLoadedLibraries() also gives a run-time error:
Unhandled Exception: java.lang.UnsatisfiedLinkError: net/sf/sevenzipjbinding/SevenZip.nativeInitSevenZipLibrary()Ljava/lang/String;
Here's the mail archive link of the replies I got about this from the ikvm-developers mailing list:
http://sourceforge.net/mailarchive/forum.php?thread_name=D395C7FC996C944EBD345AB36164F4B231A5D64B%40woyla.sumatrasoftware.com&forum_name=ikvm-developers
Here's the part from the IKVM developer:
> As Volker said, you should combine both jars (I used "ikvmc -out:7zip.dll *.jar"), but doing that still doesn't result in something that works. On x64 I get a stack overflow (I didn't look into this) and on x86 it failed because sevenzipjbind uses JNI in a way that isn't supported by IKVM (and what I believe to be in violation of the spec). They use CallIntMethod to call a method that returns a long. After I added a workaround for that to IKVM (just for testing this), your sample worked (i.e. I could print the number of entries in a RAR).
So based on that, it sounds like he says to modify 7-zip-jbindings to allegedly match the spec?
Thanks for this bug report! I will try to find and fix this bug.
The upcoming version (with archive creation support) has a build-in type check, but not the current released version.
About your post 10 and 11:
If you look into sevenzipjbinding-AllPlatforms.jar you will find a couple (one or two) DLLs for each supported platform, but no java code. So it's just resource jar. I don't know, how resources are handled by ikvmc, probably it is 7-ZIp-JBinding's fault, I don't know for sure.
What you could do to exclude this possible source of errors: you could just extract two DLLs for your Win64 platform and forget about sevenzipjbinding-AllPlatforms.jar. Then you should do:
1. Call System.load() for first and then second DLL. (Try it in both orders)
2. Call SevenZip.initLoadedLibraries()
I think, you need either patched IKVM or patched 7-Zip-JBinding. I will try to fix the bug in 7-Zip-JBinding as soon as possible and then build a test version for Win64 for you. If you find it suitable, I will make a bug-fix release.
I found the bug! Here is a patched version:
http://rapidshare.com/files/357615933/download.php_filename_sevenzipjbinding-4.65-1.04rc-extr-only-Windows-amd64.zip
thanks, I will hopefully try out this patch sometime tonight, at least on my Win64 machine.
Of course my hope is for Windows / Mac OS X / Linux support… I see that sevenzipjbinding-AllPlatforms.jar is just these 6 libs (x64 / x86 Linux, x64 / x86 Mac OS X, x64 / x86 Windows).
Yes, I will make a normal 1.04 release for all those platforms, as long all needed changes are done. Do you need a build for Win32 or Mac OS X as well for test purposes?
I am hoping to use sevenzipjbinding-AllPlatforms.jar and sevenzipjbinding.jar (with IKVM), to support Windows, Mac OS X, Linux (both 32-bit and 64-bit). Will the official 1.04 release be soon?
I'm now attempting to download the file via rapidshare.com… It keeps timing out, but I'll keep trying.
I still have not been able to download the file from rapidshare.com … It keeps timing out. Maybe upload to sourceforge, or to somewhere else? Or, if the 1.04 binary release will be within the next 24 hours, I could just wait for that?
er, okay, it finally let me download the file from rapidshare.com… Maybe I was just being impatient O:-)
In post 13, what do you mean System.load()? There is no C# method System.load()…
Btw, did you see the IKVM developer referenced (long net.sf.sevenzipjbinding.impl.RandomAccessFileInStream.seek(long, int)) ? Was that the bug you fixed?
Is this what you meant? First, I ran (ikvm.exe sevenzipjbinding.jar) to create sevenzipjbinding.dll. Then, I referenced sevenzipjbinding.dll in my Visual Studio project as a Reference. I unzipped sevenzipjbinding-Windows-amd64.jar to get the 2 dll files. Then I ran with this code:
java.lang.System.load(strDir + "libgcc_s_sjlj-1.dll");
java.lang.System.load(strDir + "lib7-Zip-JBinding.dll");
net.sf.sevenzipjbinding.SevenZip.initLoadedLibraries();
string fileName = @"C:\test.cbr";
java.io.RandomAccessFile randomAccessFile = new java.io.RandomAccessFile(fileName, "r");
ISevenZipInArchive archive = net.sf.sevenzipjbinding.SevenZip.openInArchive(
net.sf.sevenzipjbinding.ArchiveFormat.RAR,
new net.sf.sevenzipjbinding.impl.RandomAccessFileInStream(randomAccessFile));
System.Console.WriteLine(archive.getNumberOfItems());
archive.close();
randomAccessFile.close();
Here is the error I get:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'ikvm-native': The specified module could not be found. (Exception
from HRESULT: 0x8007007E)
at java.lang.ClassLoader.loadLibrary0(Class , File )
at java.lang.ClassLoader.loadLibrary(Class , String , Boolean )
at java.lang.Runtime.load0(Class , String )
at java.lang.System.load(String filename, CallerID )
at java.lang.System.load(String filename)
The KVM developer said to compile the 2 jar files as 1 dll file, so I tried that, sevenzip
jbinding_withNativeLibs.jar. Then I reference that dll from my Visual Studio project, and ran this code:
net.sf.sevenzipjbinding.SevenZip.initLoadedLibraries();
It gives me this error:
Unhandled Exception: java.lang.UnsatisfiedLinkError: net/sf/sevenzipjbinding/SevenZip.nativeInitSevenZipLibrary()Ljava/lang/String;
I also tried the alternative of adding to the solution the reference to sevenzipjbinding.dll (which only compiles sevenzipjbinding.jar). Then running this code:
net.sf.sevenzipjbinding.SevenZip.initSevenZipFromPlatformJAR(strDir + "sevenzipjbinding-Windows-amd64.jar");
net.sf.sevenzipjbinding.SevenZip.initLoadedLibraries();
This causes this error:
Unhandled Exception: net.sf.sevenzipjbinding.SevenZipNativeInitializationException: Error loading SevenZipJBinding native library into JVM: error loading property file '/C:\ikvm_generated_7-zip-jbinding\sevenzipjbinding-Windows-amd64.jar/sevenzipjbinding-lib.properties' from a jar-file 'sevenzipjbinding-<Platform>.jar'. Is the platform jar-file not in the class path?
To 20: java.lang.System.load(<fullpath>) should be the right thing to do. But there are a possibility, that IKVM has some special method to load native library.
To 21: yes, that was the bug I fixed.
To 22: As you can see, the IKVM version of java.lang.System.load() can't file the native library. (Are you sure your strDir is correct and ends with a '/'?)
To 23: That means, that the native library wasn't loaded
To 24: That means, that resources (properties and dll files) couldn't be found.
I will try to talk to IKVM people in order to find out, how to load a native library from C#.