Thursday, August 18, 2016

JNI and the Java library path (JVM java.library.path system property)

Sometimes I have to use native libraries (.so libraries under Linux or .dll libraries under Windows) in Java programs. That's where you use the Java Native Interface (JNI). It allows you to call functions implemented in native libraries from Java code. And almost every time I forget to remember how the JVM tries to locate the referenced native libraries.

A caveat when trying to load a JNI library in a Java program is that the Java Virtual Machine does not use the default mechanism of the operating system to locate dynamic libraries. A C/C++ program running on a GNU/Linux based operating system would normally use the dynamic linking loader to load dynamic libraries. To be able to load a dynamic library from within Java, the so-called "Java libary path" must contain the path to the directory of the library. Inside the Java Virtual Machine the Java library path is stored in the java.library.path property (see JavaDoc of java.lang.System class). The Java library path can be set using the appropriate command line option when starting the Java Virtual Machine (e.g. java -Djava.library.path=~/lib HelloJNI).

Under Unix-based operating systems, the content of the LD_LIBRARY_PATH environmental variable is merged with the Java library path. Furthermore the Java library path contains the directories /lib/ and /usr/lib/ per default. According to the Filesystem Hierachy Standard the /lib/ directory should contain essential shared libraries and kernel modules. The /usr/lib/ directory should contain libraries for programming and packages.

When running under Windows the Java library path is merged with the content of the PATH environmental variable.

Naturally, a JNI library can reference other dynamically linked libraries. The Java Virtual Machine will then locate the "initial" JNI library using the Java library path, but the "secondary" libraries are loaded using the default mechanism of the operating system.

Wednesday, July 27, 2016

How to manually increase version numbers in software projects (recusively replacing strings in a directory)

I have a project for which I have to create a new release from time to time. At the moment we have no facilities in place to increase the version numbers automatically (e.g. maven-release-plugin). Therefore I have to increase the version numbers manually (e.g. from 1.0.6 to 1.0.7). For this task I prefer using GNU command line tools instead of an IDE (e.g. Eclipse or IntelliJ IDEA) for various reasons:
  • The project consists of many sub-projects and I don't always have all the sub-projects opened in the IDE.
  • I can use the GNU command line tools on all OS platforms. When you are a developer and you are using Windows I heavily suggest that you install Cygwin. Cygwin enables you to use all sorts of GNU command line tools under Windows.
  • Sometimes I have projects where I don't use an IDE at all.

At first I search for all occurences of the current version number to see where I will have to increase it:

$ egrep -Hir '1\.0\.6' | less

Then I run the following command to do the actual replacement:

$ find . -not \( -path ./.git -prune \) -type f -iregex ".*\.\(MF\|xml\|e4xmi\|java\|product\)" -print0 | xargs -0 sed -i 's/1\.0\.6/1.0.7/g'

  • We don't want sed (the GNU Stream Editor which does the actual replacement) to mess around with the .git folder under any cirumstances. Therefore we exclude it from the search results (-not \( -path ./.git -prune \)). To read more about the different ways of  how to exclude certain directories from a find search see here. The method above should work under any circumstances.
  • We don't want sed to search for version number string in e.g. binary files (egrep omits binary files by default). Therefore we only include files with certain file extensions in the search results (-iregex ".*\.\(MF\|xml\|e4xmi\|java\|product\)"). 
To review the changes made by sed I use the following command (see here for an exaplanation and possible variants):

$ git diff --color-words=.

This way you can easily spot the changed characters:

Example output of git diff --color-words=..

Example output of git diff when omitting the --color-words=. option.

Thursday, July 14, 2016

Steam client crashes when running under Linux (locale problem)

My prefered platform for running Steam is Arch Linux at the moment. I have to start steam using the following command:

[user@host ~]$ LC_ALL=C steam

Otherwise I get a segmentation fault:

[user@host ~]$ steam                                         
/home/user/.local/share/Steam/steam.sh: line 154: VERSION_ID: unbound variable
/home/user/.local/share/Steam/steam.sh: line 154: VERSION_ID: unbound variable
Running Steam on arch  64-bit
/home/user/.local/share/Steam/steam.sh: line 154: VERSION_ID: unbound variable
STEAM_RUNTIME is enabled automatically
Installing breakpad exception handler for appid(steam)/version(1468023329)
Installing breakpad exception handler for appid(steam)/version(1468023329)
/usr/share/themes/Breeze/gtk-2.0/widgets/entry:70: error: unexpected identifier `direction', expected character `}'

(steam:1477): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita",
/usr/share/themes/Breeze/gtk-2.0/widgets/styles:36: error: invalid string constant "combobox_entry", expected valid string constant
/usr/share/themes/Breeze/gtk-2.0/widgets/entry:70: error: unexpected identifier `direction', expected character `}'

(steam:1477): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita",
/usr/share/themes/Breeze/gtk-2.0/widgets/styles:36: error: invalid string constant "combobox_entry", expected valid string constant                                                                               
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Fontconfig error: "/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", line 72: non-double matrix element                                                                                                              
Fontconfig error: "/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", line 72: non-double matrix element                                                                                                              
Fontconfig warning: "/etc/fonts/conf.d/10-scale-bitmap-fonts.conf", line 80: saw unknown, expected number                                                                                                         
[0714/135234:ERROR:main_delegate.cc(779)] Could not load cef_extensions.pak                                                                                                                                       
[0714/135234:ERROR:browser_main_loop.cc(217)] Running without the SUID sandbox! See https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the sandbox on.                                                                                                                                                                                          
Installing breakpad exception handler for appid(steamwebhelper)/version(20160708214346)                                                                                                                           
Installing breakpad exception handler for appid(steamwebhelper)/version(1468014226)                                                                                                                               
[0714/135235:ERROR:main_delegate.cc(779)] Could not load cef_extensions.pak                                                                                                                                       
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Installing breakpad exception handler for appid(steamwebhelper)/version(20160708214346)                                                                                                                           
Installing breakpad exception handler for appid(steamwebhelper)/version(1468023329)                                                                                                                               
Installing breakpad exception handler for appid(steamwebhelper)/version(1468023329)                                                                                                                               
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Created shared memory when not owner SteamController_Shared_mem                                                                                                                                                   
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
                                                                                                                                                                                                                  
** (steam:1477): WARNING **: Could not initialize NMClient /org/freedesktop/NetworkManager: Unit dbus-org.freedesktop.NetworkManager.service not found.                                                           
Steam: An X Error occurred                                                                                                                                                                                        
X Error of failed request:  BadValue (integer parameter out of range for operation)                                                                                                                               
Major opcode of failed request:  18 (X_ChangeProperty)                                                                                                                                                            
Value in failed request:  0xffffffb8                                                                                                                                                                              
Serial number of failed request:  132                                                                                                                                                                             
xerror_handler: X failed, continuing                                                                                                                                                                              
Installing breakpad exception handler for appid(steam)/version(1468023329)                                                                                                                                        
assert_20160714135230_1.dmp[1528]: Uploading dump (out-of-process)                                                                                                                                                
/tmp/dumps/assert_20160714135230_1.dmp                                                                                                                                                                            
/home/user/.local/share/Steam/steam.sh: line 713:  1477 Segmentation fault      (core dumped) $STEAM_DEBUGGER "$STEAMROOT/$STEAMEXEPATH" "$@"                                                                
assert_20160714135230_1.dmp[1528]: Finished uploading minidump (out-of-process): success = yes                                                                                                                    
assert_20160714135230_1.dmp[1528]: response: CrashID=bp-1cba6a06-f4ab-4f26-8467-1f9f52160714                                                                                                                      
assert_20160714135230_1.dmp[1528]: file ''/tmp/dumps/assert_20160714135230_1.dmp'', upload yes: ''CrashID=bp-1cba6a06-f4ab-4f26-8467-1f9f52160714''                                                               
[user@host ~]$

The problem is that not all locales supported by the host system are also supported by X (also see Valve GitHub Issue 1420). And a quick fix is to run LC_ALL=C steam.

It really took some time for me to figure this out. The problem is that the console output of the program does not give any hints about the cause of the segmentaton fault. Using Google did not help either because most Steam client crash reports out there do not have anything to do with system locale settings. I also tried to get to the root cause of the problem using tools like strace.

In the end I just had luck and found Valve GitHub Issue 1420 while browsing through Valves issue list for the Linux Steam client over at GitHub. This issue contained the information I needed to understand and finally run the Linux Steam client on my Arch Linux system.

My Steam client currently contains the following versioning information:
  • Built: Jul 8 2016, at 21:44:35
  • Steam package versions: 1468023329
Now I have to get back to kick some zombie ass :-) Dead Island: Definitvie Edition has been release on Linux a few weeks ago...




Thursday, July 7, 2016

Eclipse WindowBuilder: JavaDoc tags reference

Documentation about the WindowBuilder JavaDoc tags is sparse. I have found only two resources so far. First the source code and second the DesignerCustomizationAPI.pdf. Though the DesignerCustomizationAPI.pdf is part of the official WindowBuilder documentation it's a little bit hard to find. As a quick reference I have listed all WindowBuilder JavaDoc tags which I know so far in this blog post. Most of the information is taken directly from DesignerCustomizationAPI.pdf.


@wbp.factory


Description


Specifies if method is a factory method. If this tag is used on a class, then all methods of this class are considered as factories. Designer will automatically exclude methods that return «null» (such as setters) and getters, i.e. methods that starts with «set» and have no parameters.

@wbp.factory.parameter.source parameterName expressionSource


Description


Sets the default source for parameter. This source will also be used when adding component using this factory method. If no such source is specified, the default value for this type will be used – zero for numerics and «null» for objects.

@wbp.factory.parameter.property parameterName propertyTitle


Description


Specifies that the parameter with given name is bound to some component property. This is useful for example if you want to set the text of a button directly in a factory method, without additional setText() invocation.


@wbp.factory.parameters.noBinding



Description


Specifies that Designer should not bind parameters to properties by names.

Usually parameters are bound to corresponding properties, but if there are many methods and parameters, it is tedious to describe each binding. Instead, you can just name the parameters with the same name as the title of the components property. For example, if you name the parameter «text», it will be bound to a property with title «text». Note that title is used, not id of the property (because id is a complex string).

One special name of parameter is reserved for SWT support, parameter with
name «parent» is considered as parent parameter (i.e. in same way if it would be
marked as parent in *.wbp-factory.xml).

@wbp.parser.entryPoint


Description


If you want to edit a GUI in a standalone class, which is not a subclass of a known component, such as Swing JPanel or SWT Composite, then you should tell WindowBuilder which method to use as the entry point for execution flow. In this case WindowBuilder will not look in the constructor and superclass, it will design only this specific method.


Example

/**
 * @wbp.parser.entryPoint
 */
public void someMethod(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
}


@wbp.parser.preferredRoot


Description


Specifies that marked component should be used as root component, even when there are other possible roots, may be with bigger hierarchy (by default WindowBuilder chooses root component with biggest hierarchy).


Example

mainPanel = new JPanel(); // @wbp.parser.preferredRoot

@wbp.parser.constructor


Description

If «this» component has only one constructor, then Designer will select it as entry point for execution flow. If «this» container has several constructors and one of them marked with this tag, then it will be used. If no tag and container has a default constructor (without parameters), then it will be used implicitly. If all constructors are non-default, error will be generated.


@wbp.eval.method.parameter parameterName expressionSource


Description


If the constructor, (or other entry method), has a parameter whose value is used for creating some component or as part of some property (method invocation or field assignment), then Designer requires hint about value that will be passed with this parameter. This tag can be used to specify any statically evaluable expression.


Example

/**
 * @wbp.eval.method.parameter _int 1 + 2
 * @wbp.eval.method.parameter _true true
 * @wbp.eval.method.parameter _false false
 * @wbp.eval.method.parameter _string "ab" + "c"
 * @wbp.eval.method.parameter _null null
 */
public Test(int _int, boolean _true, boolean _false, String _string,
        Object _null) {
    super(_int, _true, _false, _string, _null);
}


@wbp.eval.method.return parameterName


Description


Sometimes code may use some instance methods declared in the same class. Designer can not evaluate these methods (at least in current implementation), so it requires some hint. In our experience, the value of one of the parameters (usually even single parameter) is enough.

Example

public int root() {
    return instancePublicMethod(5);
}
 /**
  * @wbp.eval.method.return value
  */
public int instancePublicMethod(int value) {
    return 2 * value;
}
/**


@wbp.gwt.Request


Description


GWT specific tag for RemoteService interface method that specifies that com.google.gwt.http.client.Request should be returned from «async» of this method.

Example


@wbp.gwt.Request
public interface MyService extends RemoteService {
    /** @wbp.gwt.Request */
    int getValue() throws Exception;
}


@wbp.nls.resourceBundle test.messages


Description


JavaDoc tag that tells the parser where to find the resource files.


Example

/**
 * @wbp.nls.resourceBundle test.messages
 */
private static final ResourceBundle m_bundle = MyResourceBundleFactory.getMainBundle();

Eclipse WindowBuilder documentation

The WindowBuilder documentation was part of the Eclipse documentation. It was included till Eclipse Kepler. You can find the Window Builder documentation which shipped as part of the Kepler release here.

The documentation is maintained in the WindowBuilder git repository. Besides the HTML sources for the documentation this repository also contains various PDF documents which contain useful informations when dealing with WindowBuilder (the PDF files are also linked from within the HTML documentation):

Monday, July 4, 2016

Microsoft Windows Media Creation Tool: Error Code 0x800704DD - 0x90016

The Microsoft Windows Media Creation Tool (MediaCreationTool.exe) can be used to download Windows 10 ISO image files. You have to run this program with administrative privileges. But it may not be sufficient to start the program using the "Run as Administrator..." option when being logged on as a user without administrator privileges:

"Error Code 0x800704DD - 0x90016" when running the media creation tool without sufficient privileges.
To be able to use the tool successfully I had to start a desktop session using my administrator account. I have noticed this strange behaviour a few times before when dealing with other programs which required administrator privileges. And to be honest I really don't have a clue what's the cause of this strange behavior. If you have any hints please drop me a few lines in the comments section below.

Microsoft also provides direct download links for the Windows 10 ISO files. But your browser will only get redirected to the page with the direct download links if it sends a user agent string indicating that you are using an operating system other than Microsoft Windows (e.g. Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/31.0).

To quickly change the user agent string of Mozilla Firefox there exist dozens of addons. At the moment I use an Add-on called User-Agent Switcher.

https://www.microsoft.com/en-us/software-download/windows10
when the browser's user agent string indicates an OS other than Windows.
Direct download links to Windows 10 disc images are served.


https://www.microsoft.com/en-us/software-download/windows10
when the browser's user agent string indicates a Windows OS.
User can only download the Microsoft Windows Media Creation Tool.