java bad version number in .class file in browser - macos

I am receiving java bad version number in .class file when I try to open a simple applet in my browser (I have tried Firefox and Safari). My browsers stat that I am using a 1.5.X JRE, but my command line compiler is 1.6.x. I can't quite figure how to sync the two of these VM's, as I am not the most adept Mac user. I have tried the native software update feature, but there is no Java update available there. I've also tried updating in each browser, but I just get redirected to the Mac OS X Software Update feature.

while compiling files, you have to use -target option.
Example, javac -target 1.5 [source file]
More explanation is available at http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html

For an Oracle JDK, you'd simply use the cross-compilation options of javac.
Note that is important to specify -source, -target & -bootclasspath for the compilation. That last one requires a JRE of the target version, to check the classes, methods & attributes used in the code actually existed in the target version.

Related

Issues with codesigning and notarization for Mac M1

I'm working to correctly distribute a software bundle for Mac ARMS (M1, M2...) which consists in a zip containing a bunch of command line utilities and dynamic libraries built using the command line tools (cc, c++ etc).
So far I've been able to sign all my executable files and my dynamic libraries with codesign using my company Developer ID certificate and to successfully notarize the zip.
Unfortunately when I download the zip using the browser my command line tools show a strange behavior: if I double click on of them from finder I get an error message saying that the identity of the developer can't be confirmed but if I run from the terminal most of the utilities work. I've noticed that if I download the last jdk as .tar.gz the behavior with the java executable is the same so I'm wondering if it's the expected behavior for command line utilities.
Still one of the utilities is not working because it is supposed to load the dynamic libraries I get an error saying that relative paths are not allowed in hardened programs.
My questions are:
Is the behavior described above for command line executable files expected?
Is there a way to allow my program that loads dynamic library to work by loading dynamic libraries as it used to do with our unsigned bundles for Intel Macs?
Does anyone knows if it's possible to notarize and distribute such a bundle in .tar.gz format rather than zip?
Thanks!
For macOS notarized software that means the executable is going to have the hard-coded path to the library and won’t work with a relative path. Usually that means setting RPATH to the hardpath
/Applications/myapp.app/Contents/Frameworks/
and aliasing your binaries from
/Applications/myapp.app/Contents/MacOS
But that is just the most common arrangement.
The hard-coded path is part of the “hardened runtime” which is a requirement to pass apple notary, an anti-malware scanner. Changing the assigned RPATH with otool is possible but invalidates the code signature, blocking execution on machines with default security without code signing at least ad hoc.
See
https://wiki.lazarus.freepascal.org/Code_Signing_for_macOS
Launching the executable directly from terminal does not run thru launchservices the way it does when you launch in finder. Launchservices begins by checking the signature against the ticket and checking the ticket, so a bare executable will be missing that info.
Thanks to the suggestions of Richard Barber I've finally understood how to correctly code-sing, notarize and deploy our bundles on Mac with hardened runtimes.
I'm leaving the steps I've taken below for future reference.
Here are the steps I needed to run:
Made sure all the dynamic executable files and libraries have referenced their dependencies without using relative paths. The relative paths may be substituted with macros like #rpath using install_name_tool
Code-singed all executable files and all the dynamic libraries suing the codesign tool with a valid Apple Distribution certificate and developer/organization key
Once signed put everything in a ZIP and sent for notarization using xcrun notarytool submit command
If the notarization succeeds the contents of the ZIP can be extracted and put in a .tar.gz without losing the validity
Once the tar.gz is downloaded on a testing machine our command line tools can be correctly used by the terminal. As suggested by Richard Barber they can't be run from Finder, but even the JDK in tar.gz format shows the same behavior, so happy with that.

Is there a Windows equivalent for the UNIX ldd command?

I have a list of DLLs and I would like to know the versions of all other DLLs, used by those files. In UNIX this is very simple:
ldd *.dll
But in Windows this does not work (I tried using my Ubuntu WSL).
Does anybody know a commandline command for this? (Powershell is good, too)
dumpbin.exe /imports will list the immediate static load dependencies, but not attempt to resolve them (which implies no version numbers nor transitive dependencies)
depends.exe will resolve dependencies (including dynamic load ones if you run in "profiler" mode which supports a variety of different methods for hooking LoadLibrary(Ex) and GetProcAddress) but is not a command-line tool. For each dependency it lists the path and version number, along with a lot of other information such as link date and required OS version -- you should be able to save this list to a file for command-line processing.
Neither of these is included in the OS distribution, you'll need a Windows SDK tools package.

mac app requires newer version of sqlite but uses the old one

Trying to run / debug an app on mac (Mavericks), that has to use sqlite 3.8.6.
I have the .h and .c files in the project. I have the dylib added as a build resource
LIBS += sqlite3/libsqlite3.0.dylib
But I also must place the dylib somewhere and tell the program at run-time to use this version.
There is a SQLite version 3.7.13 installed on the system (in /usr/lib). It seems to be used preferentially. If I had admin rights (which I don't) I could move it to a different location... But the user system may have it in the default location so that would be useless.
I have tried to place MY sqlite3 in a place that will be used preferentially - like in myapp.app/Contents/Frameworks or myapp.app/Contents/MacOs... also tried to change the dependency with install_name_tool... no success.
Checking the dependencies with otool -L shows a dependency on sqlite3.0.dylib in /usr/local/lib (which does not contain any sqlite3)... even after running install_name_tool it still shows the same. Perhaps I am doing it wrong...
install_name_tool -id #executable_path/Frameworks/libsqlite3.0.dylib myapp.app/Contents/Frameworks/libsqlite3.0.dylib
install_name_tool -change myapp.app/Contents/Frameworks/libsqlite3.0.dylib #executable_path/Frameworks/libsqlite3.0.dylib myapp.app/Contents/Frameworks/mylib.dylib
install_name_tool -change myapp.app/Contents/Frameworks/libsqlite3.0.dylib #executable_path/Frameworks/libsqlite3.0.dylib myapp.app/Contents/MacOs/myapp
I am getting an SQL error that is caused by having the wrong (older) version of sqlite3, which does not support certain required features.
How can I force the app to see the version I added ?
Update: I added the c file and removed the dylib as a dependency...
I got the error no such module: fts4
I added the following in the .c file (from http://www.sqlite.org/fts3.html) - as suggested in comments below
#define SQLITE_ENABLE_FTS4
#define SQLITE_ENABLE_FTS4_PARENTHESIS
Adding the same in windows and linux, the effect is double the size of the library + sqlite3. And queries on a database run significantly slower (I actually thought they were not even performed).
If this is the only option I have on mac, I will have to use it... I am either stuck with very slow build, very large libs, and VERY SLOW QUERIES, or ... there must still be an option to use the sqlite3.dylib without building it into the lib I am creating.
You can just add the original (Amalgamation) files sqlite3.c and sqlite3.h (look for version 3.8.6) to your Xcode project. That's basically it.
If you need to change/add some compile options
you can do that at the top in sqlite3.c.
Here an example to activate FTS3/FTS4:
#define SQLITE_ENABLE_FTS4
All the compile options are here: http://www.sqlite.org/compile.html

Qt, Google BreakPad and MacOs

Is here anyone who successfully build Google Breakpad on MacOS using standard Qt tool chain without xcode?
I'm trying to get work this library for two days now and still without success. I already successfully compiled it and ran it on Windows and Linux. (from original Google-git repository).
But MacOS version of library has missing makefile for libbreakpad_client.a and generated libbreakpad.a does not contain the exception handler.
http://screencast.com/t/V0mNiM3kZ
I found few topic about this issue on here on a stackoverflow but advice with updated makefiles didn't work for me (or I didn't copy makefiles correctly).
I also tried to download updated version directly from Mozilla repository (version 10 and 11beta). But when I tried to compile Mozilla version, there was another errors with undefined symbols (on Mac and also on Linux).
I also found AlekSi - breakpad-qt but this version also works correctly only under Win and Linux. Under Mac there is some errors about "Unknown architecture -- are you on a PDP-11?"
I will be gratitude to anyone who can point me how to compile it and get it work under Mac or who can send me a packed version of breakpad which can be compiled under MacOS using standard make and used in Qt application.
Thank you
Ludek
AlekSi's breakpad-qt is three years old, and the breakpad source in it doesn't support 64 bits on OSX.
Failing to detect your processor type is what makes it complain about "Unknown architecture -- are you on a PDP-11?".
You definitely need a more recent breakpad version, either from their svn, or from my breakpad-qt fork at: https://github.com/webitup/qt-breakpad
Now, if you intend on supporting 10.6 (MACOSX_DEPLOYMENT_TARGET=10.6) as well, you need to patch breakpad source using this https://github.com/webitup/qt-breakpad/commit/71a9fdedd827e5939ba66bfcc0cd6c1c9fbbc87b (-> I don't think 10.6 has PPC support)
Then:
You apparently managed to compile directly from source, so, good for that way.
Now, if you want to build a framework from breakpad instead, and link to that from your qt app/lib, then Dave Mateer suggestion is the way to go (and he deserves the credit). The following worked for me:
cd $BREAKPAD_SOURCE_TREE
xcodebuild -sdk macosx10.7 -project src/client/mac/Breakpad.xcodeproj -configuration Release -target Breakpad ARCHS=x86_64 ONLY_ACTIVE_ARCH=YES MACOSX_DEPLOYMENT_TARGET=10.6 GCC_VERSION=com.apple.compilers.llvmgcc42
Note that I'm only building target Breakpad instead of All (it seems you only need that - and a test is failing for me using All, though it does produce a usable framework either way).
And note that you don't require XCode per-se - just the command line builds tools.
In order to use that framework in your QT project:
mac {
QMAKE_LFLAGS += -F$$BREAKPAD_PATH/client/mac/build/Release/
LIBS += -framework Breakpad
}
And you should be set.
Finally: I also pushed a number of changes in my breakpad-qt fork source itself to have it at least compile (on OSX!) against the updated breakpad version, but I have no idea yet if it does work properly.
I'm just starting with that fork - if you want to share experience and/or commit some stuff in there, just ask.

Compile the most recent version of a package in an old system for local use

I need to know if it is possible to compile the best and newest package in an old, ancient system. Why? Well I'm limited at my company: I need to develop an application in an old Debian 3.0 server and I would prefer to use newer software to accomplish my task. Unfortunately, I'm not allowed to upgrade nor install any package.
Specifically, I want to parse XML files comfortably using xmlstarlet to do so. This server doesn't have it installed; if I download an older version of xmlstarlet supported by the system it's too old that I just lost the functionality I need. It just has three dependencies: libc6, libxml2 and libxslt1.1 (which are installed but are too ancient for a newer version of xmlstarlet)
So the question is: is there a way I can download this package and its dependencies (I think they are few and simple) and somehow compile them to work locally (not necessarily on the system's path, just in a working directory) without affecting in any way the legacy packages of the same name?
This system doesn't has PEAR either, nor PHP5, nor xmllint and I want to avoid coding in PHP4 to parse these XMLs. I really would like to work with xmlstarlet.
The answer to How to specify non-default shared-library path in GCC Linux? Getting "error while loading shared libraries" when running looks like it should work fine.
Or you could try static linking:
./configure --enable-static-libs

Resources