Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme


Download 22.93 Kb.
NameSigning app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme
A typeDocumentation

Building app package from java project



Main



To create an app bundle for your mac from a java project, do the following:

Create the jar of the project (build the project).

Download the AppBundler tool from: https://java.net/projects/appbundler . Documentation for this tool can be found under: https://java.net/downloads/appbundler/appbundler.html.

Add the appbundler-x.x.jar to your projects' lib folder.

Edit your build.xml file, insert the following within your
tags:



classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-.jar" />





name="
"


displayname="
"


identifier=""

mainclassname="">







Run "ant " from the high-level project directory to invoke the appbundler. The app package should be in you dist folder.

Bundling java runtime environment with your app package


The Apple Store requires the use of an embedded JRE as a prerequisite for Mac App Store distribution.

Make sure your java home evironment variable is configured correctly, google how to set this variable on mac using bash.

Add the following to you project in the build.xml:




And the following to your :



After running the appbundler again, the JRE should now be in the app's Contents/plugins directory.

Signing app


Note: signing the app is only necessary when you intend to publish the app on the Apple App store.

Creating a java application which can use a custom URI-scheme


If an application can use a custom URI-scheme, you can start the application by, for example, clicking on a button with the following html:



(Or just by typing the link in you url bar)

Where bos: is the initiator, if set up correctly your pc/mac should know to start up your application. At the time of writing this (15-06-2016), this way of starting an application works for pretty much all browsers. Chrome is known to sometimes have issues with this, but there are ways to get it to work with some javascript code and it's been said to be fixed in the near future.

You can also pass parameters to your java application by using these uri-schemes. This works however very differently for either Pc or Mac, for details see the next two chapters.

Windows


To let your Pc use your application for links with a custom URI-scheme, all you have to do is edit (or rather have an windows installer edit) the Pc's registry.

The registry should have the following under the HKEY_CLASSES_ROOT key:

bos

(Default) = "URL:Bos Protocol"

URL Protocol = ""

DefaultIcon

(Default) = "UniversalBosEditor.exe,1"

shell

open

command

(Default) = "C:\ProgramData\Oracle\Java\javapath\javaw.exe" -jar "C:\Program Files\Initworks\Bos Editor\UniversalBosEditor.jar" "%1"

Here "bos" is the key added to the root. It has a default key, a URL Protocol key which holds an empty string as value, a DefaultIcon key which hold the file name of the icon to use for this uri-scheme and a shell key. The shell key holds an open key, in it a command key with as default value the path to your latest java version to start the application with, a –jar parameter, then the path to your project's runnable jar file and at the end of it "%1", which indicated that the application should get 1 parameter from after the Uri-scheme's initiator sent to your application as the main args[].

If you manually edit the registry, the custom uri-scheme should now start up your application and send the text after the initiator to your application as the main's args[]. Which text you should check for malicious input and then parse them to suit your needs.

To publish the application you'll ofcourse want an installer to install your files and edit your Pc's registry, see chapter "Windows Installer which edits registry".

Extra information by microsoft:

https://msdn.microsoft.com/en-us/library/aa767914%28v=vs.85%29.aspx

Mac




On a Mac, letting your java application start by using a custom Uri-scheme isn't that hard, but to make it use your parameters requires some extra code (osx doesn't automatically send the parameter to your main's args[]).

Using a custom uri-scheme


To let Osx start your application with a custom Uri-scheme, you need to find the generated Info.plist file in your bundled app package's Contents. Inside this info list you should add the following inside the dictionary:

CFBundleURLTypes


CFBundleURLName
Bos Editor
CFBundleURLSchemes

bos




Where Bos Editor is just the name of the uri scheme or application and bos is the custom URI which should initiate your application.

If the app bundle with the edited Info.plist is placed in the Mac's applications directory, the Mac should recognize your application as the program to start when the custom URI is called in your browser.

Installing the app on a Mac is just placing the bundle in the applications directory, no installer needed. Except ofcourse when you want a fancy UI telling the user to drag the app to their applications directory.

Using the parameters of your custom uri-scheme


Since Osx does not automatically send the text after the custom uri-scheme's initiator, you have to add some code to your project to let it get the parameter's text.



First you'll have to check if your application is running on a mac, this can be done by the following snippet:

private boolean isOsx() {
String osName = System.getProperty("os.name").toLowerCase();
return osName.contains("mac");
}

If this returns true you should make an instance of the class you need to make below:



Make a class which implements com.apple.eawt.OpenURIHandler. The class should have the following in the constructor.

private String[] appleArgs;

public AppleMenus() {
com.apple.eawt.Application app = com.apple.eawt.Application.getApplication();
app.setOpenURIHandler(this);
}

The class should also Override the openURI() method:

@Override
public void openURI(final com.apple.eawt.AppEvent.OpenURIEvent oue) {;
this.appleArgs = new String[] {oue.getURI().toString()};
startApplication();
}

Now you can start you original application with the args from the URIHandler:

void startApplication() {
UniversalBosEditor ube = new UniversalBosEditor(this.appleArgs);
}

Important notes:


If you're building this on a Windows Pc, your editor won't recognize the apple package since it's not in the standard java development kit for windows. You'll need to add the AppleJavaExtensions library to your project which you can find the latest version of here: https://developer.apple.com/legacy/library/samplecode/AppleJavaExtensions/Introduction/Intro.html

If you're using NetBeans then you can probably run the code but not build it, getting an error that the apple package(s) don't exist. Apparently this is a NetBeans problem and can be solved by manually adding the rt.jar library (this contains the apple packages) to you project, which is already in the jdk, but hey it solves the issue.

Windows installer which edits registry


A frequently used toolset for making windows installers for java applications is the Wix Toolset, for which you can find the documentation here: http://wixtoolset.org/documentation/

For some nice third-party tutorials on how to make a windows installer, see: https://www.firegiant.com/wix/tutorial/

For all of the details of the attributes and where to put them see the tutorials, but here is a small example and a short explanation of what you’ll have to do.

Making the installer specifications


Install the wix toolset first.

To generate a .msi file for your application you first need to make a .WXS file with some XML data that specifies what the installer should do. The XML will look like this example:



This XML file tells the toolset what the installer should do. It begins with a product element, which will contain everything in the installer. The package element is also needed.

Under this follow the Directories where to install the files. The TARGETDIR and ProgramFilesFolder are reserved directory names. The TARGETDIR can be altered in the installer by the user (if you want them to). Next follow the components which tell where to find the files which should be installed. The second component is the part which edits the registry. For reference this component edits the registry to the same qualifications as the example in the earlier examples.

After the directories come the features (the property which checks if the user has JRE installed may not be necessary for you). The features are the parts which you can select on and off if they are optional in the installer. In most installers there is just 1 features with all the files and registry. The componentRefs have the same id as the components in the directories.

The last part is the UI element, which specifies how the installer’s UI should look. Mondo is just your typical installer with the option to select an install directory. The Publish element just lets you skip the End-user license agreement, since it’s not needed.


Making the installer


To make the final installer, you first go to the install folder of Wix Toolset and run an administrator command prompt. Run “candle.exe
.wxs”, this will generate a .wixobj file.

Then run “light.exe –ext WixUIExtention –cultures:en-us
.wixobj”. You should now have a .msi file which can install your files and edit your registry. As I said earlier, there are many things you can do more with your installer, take a look at the tutorial at the top of this chapter.

Share in:

Related:

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconDownload the app To get started, make sure you are using an iPhone...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconDescription of Product: Outlook Mobile app for ios is the business-class...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconBlind Square is a combination Point of Interest poi and basic navigating...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconIs the app name that appears to users. For this project, use "My First App."

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconWalkthrough: Deploying a SignalR autohosted App to Office 365 Written...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconClaroCom is an ios app designed for aac (Augmentative and Alternative...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconWe assume that you can create a basic Windows Store app using JavaScript as described in

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconIndependent coursework programming Object-oriented programming in...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconAbstract This report contains the functional, design, and structure...

Signing app Note: signing the app is only necessary when you intend to publish the app on the Apple App store. Creating a java application which can use a custom uri-scheme iconCreate google app engine console project Sign up for Google App Engine:...




forms and shapes


When copying material provide a link © 2017
contacts
filling-form.info
search