Mac Java! • Tutorial: Create a Mac OS X Installer for a Java Application (.Jar)

Total Page:16

File Type:pdf, Size:1020Kb

Mac Java! • Tutorial: Create a Mac OS X Installer for a Java Application (.Jar) How to Create a Mac OS X Installer for a Java Application (Updated for Mac OS X 10.6 — Snow Leopard) With some simple steps you can turn your Java Swing program (.jar) into a proper Mac OS X application with a native installer. The instructions below step you through the process from scratch with a sample program called "Show Time" which simply displays the current time. Once you have SCREENSHOT successfully completed the tutorial with the sample Java program, ICONS modify the steps to work for your Java program. ↓ 1) Launch Unix Terminal Using "Finder" go into "Applications" and then open the "Utilities" folder. Scroll down until you see "Terminal". Open "Terminal" and you're now at the Unix prompt. 2) Make Project Folder At the Unix prompt, enter these two commands: mkdir showtime cd showtime The first command creates a folder called "showtime", and the second command moves you into the new folder. 3) Write Some Java Code Mac OS X comes with a simple but effective text editor called Pico. Use the following command to create and edit a new Java file: pico ShowTime.java Enter the following code: ShowTime.java import java.util.Calendar; import javax.swing.*; public class ShowTime { public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle("It's Showtime!"); f.getContentPane().add(new JLabel( Calendar.getInstance().getTime().toString())); f.pack(); f.setVisible(true); } } view/download code Use <control-x> to exit Pico. 4) Compile Java Program Back at the Unix prompt, compile the Java program into a class file: javac ShowTime.java ls -l We could run the class file directly, but a class file is cumbersome. Instead we will create an executable JAR file. 5) Make Executable JAR Before we make an executable JAR file, we need a manifest file to indicate which class contains the "main" function. We'll use Pico again: pico MainClass.txt Our manifest file will only have one line: MainClass.txt Main-Class: ShowTime Exit Pico and use the following "jar" command to create the "ShowTime.jar" file: jar cmf MainClass.txt ShowTime.jar *.class ls -l Now test your executable JAR with the following command: java -jar ShowTime.jar The "It's Showtime!" window with the current time should display in the upper left corner of the screen. Click the red dot to exit the program. While the manual commands above for steps #4 and #5 work fine, you could automate them using Ant with this build.xml file. 6) Install Xcode for Mac Development Apple's Xcode suite includes the developer tools you'll need to create an icon and installer. Download Xcode for Mac Development and open the downloaded .dmg file. Then run the "XcodeTools.mpkg" file and complete the Xcode installation with all the default options. 7) Create Application Icon The default icon for an executable JAR is a coffee cup. To add a custom icon, we need to use the "Icon Composer". Download and save (<control-click>) this sample PNG image to your "Desktop": ShowTime.png Then move the file into the "showtime" folder with the "mv" command: mv ../Desktop/ShowTime.png . ls -l Now we can create the icon file. Steps: a. Use "Finder" to navigate into the "/Developer/Applications/Utilities" folder and double- click "Icon Composer". b. Go back to "Finder" and navigate to your "showtime" folder (which is in your home folder). c. Drag the "ShowTime.png" image file into the "128" box on the "Icon Composer" screen. d. Go into the "File" menu and select the "Save" option. e. Click the down triangle button to show the file navigation options and navigate to the "showtime" folder. f. Deselect the "Hide extension" option and save as "ShowTime.icns". g. Quit "IconComposer". With our new icon, we can now create a Mac application. 8) Bundle the JAR Using "Finder", navigate into the "/Developer/Applications/Utilities" folder and double-click "Jar Bundler". Steps: a. For the "Main Class:", use the "Choose..." button and go to and choose "ShowTime.jar". b. Check the "Use Macintosh Menu Bar" option. c. Use the "Choose Icon..." button to choose the "SnapBackup.icns" file (you'll need to navigate to the very top-level folder and then into the "Users" folder and your home folder to eventually find the "showtime" folder). d. Click the "Properties" tab and enter "1.0" into the "Version:" field. e. Also enter "1.0" into the "Get-Info String:" filed. f. Click the "Create Application..." button. g. Navigate into the "showtime" folder. h. In the "File:" field, enter "Show Time". i. Click the "Create" button. j. Quit "Jar Bundler". We now have a proper Mac application. Next we'll create an installer for the application. 9) Create Mac Installer Using "Finder", navigate into the "/Developer/Applications/Utilities" folder and double-click "PackageMaker". Steps: a. In the "Organization:" field on the "Install Properties" window, enter "com.centerkey". Then click "OK". b. Click on the "Configuration" tab, and in the "Title:" field enter "Show Time". c. Go to the "Project" menu and select "Add Contents...". Navigate to "showtime" folder and then select and choose "Show Time". d. Deselect "Allow Relocation" (to prevent the build version from being confused with the installed version). e. Click on the "Contents" tab. Check the "Include root in package" option and click the "Apply Recommendations" button. f. Now click the "Build" (hammer) button. In the "Save As:" field, enter "ShowTimeInstaller.pkg". Click the "Save" button and then the "Return" button. g. Go to the "File" menu and select "Save". In the "Save As:" field, enter "ShowTime.pmdoc" and then click "Save". h. Quit "PackageMaker". Our installer is done, but it's not yet download friendly. 10) Put Installer on a Web Page Before putting the installer on the web, we need to zip it up into a single file. Use "Finder" to navigate to the "showtime" folder. Create a zip of "ShowTimeInstaller.pkg" using the "Compress" option on the <control- click> menu. Back at the Unix prompt in the "Terminal", create a test web page: pico download.html The HTML for the test page is: download.html <html> <body> Download: <a href="ShowTimeInstaller.pkg.zip"> ShowTimeInstaller.pkg.zip</a> </body> </html> After exiting Pico and saving the web page (.html) file, copy it and the .zip file to your personal web server folder with the command: cp *.html *.zip ../Sites Now we need to turn on the Mac's Apache web server. Steps: a. Go to the "Apple" menu ( ) and choose "System Preferences...". b. In the "Internet & Wireless" section, click "Sharing". c. Check the option for "Web Sharing" service. d. Quit "System Preferences". Your Apache web server is now running. Launch Safari and go to http://localhost/~you/download.html where "you" is your user name. Click the "ShowTimeInstaller.pkg.zip" link and the install should automatically start within a few seconds. After completing the installation, go into the "Applications" folder and run the "Show Time" application. Be sure to check out the "About Show Time" option on the "Show Time" menu. Troubleshooting If your application does not install and run properly, the first place to look is step 5, which creates the JAR file. Try double-clicking the JAR file to launch your application. If it fails to launch, you need to fix that before continuing. The next place to look is step 7, which creates the application file. Try double- clicking the .app file. If it fails to launch, you need to fix that before continuing. Do the same for step 9, which creates the installer file (.pkg). Wrap-Up Here's the finished installer you can try out yourself: ShowTimeInstaller.pkg.zip For an example of how you might distribute your installer, take a look at: Snap Backup If you want to add a "Visit Web Site" button to your application, check out: Bare Bones Browser Launch for Java That's it. Comments or Questions Send Us a Message Message: Name: E-Mail: Submit Powered by PERFECT All the fields are optional. However, if you want a response, make sure to provide your e-mail address. Random • Elsewhere • "Great tutorial." — W.C., October 8, 2009 Google Development Guide "Great tutorial! Many thanks, this is really Integration Java to Mac | 2 | 3 helpful for a programming assignment in a About Box computer network class I'm taking." — Z.L., October 6, 2009 • Versions • "Great tut omg thanks so much!" — S., Mac Java! for Snow Leopard (10.6) October 4, 2009 Mac Java! for Leopard (10.5) Mac Java! for Tiger (10.4) "I love this tutorial! Thank you!" — S.R., March 4, 2009 "Fantastic!!!!! Thank you very muchhhhh!! I can start mac programing now. The tutorial is great!!!" — F., November 8, 2008 "Incredibly clear to follow, Thanks very much" — J.G., October 1, 2008 More... Mac Java! Dem Pilafian http://www.centerkey.com/mac/java.
Recommended publications
  • Programming Java for OS X
    Programming Java for OS X hat’s so different about Java on a Mac? Pure Java applica- tions run on any operating system that supports Java. W Popular Java tools run on OS X. From the developer’s point of view, Java is Java, no matter where it runs. Users do not agree. To an OS X user, pure Java applications that ignore the feel and features of OS X are less desirable, meaning the customers will take their money elsewhere. Fewer sales translates into unhappy managers and all the awkwardness that follows. In this book, I show how to build GUIs that feel and behave like OS X users expect them to behave. I explain development tools and libraries found on the Mac. I explore bundling of Java applications for deployment on OS X. I also discuss interfacing Java with other languages commonly used on the Mac. This chapter is about the background and basics of Java develop- ment on OS X. I explain the history of Java development. I show you around Apple’s developer Web site. Finally, I go over the IDEs commonly used for Java development on the Mac. In This Chapter Reviewing Apple Java History Exploring the history of Apple embraced Java technologies long before the first version of Java on Apple computers OS X graced a blue and white Mac tower. Refugees from the old Installing developer tan Macs of the 1990s may vaguely remember using what was tools on OS X called the MRJ when their PC counterparts were busy using JVMs. Looking at the MRJ stands for Mac OS Runtime for Java.
    [Show full text]
  • Eclipse Project Briefing Materials
    [________________________] Eclipse project briefing materials. Copyright (c) 2002, 2003 IBM Corporation and others. All rights reserved. This content is made available to you by Eclipse.org under the terms and conditions of the Common Public License Version 1.0 ("CPL"), a copy of which is available at http://www.eclipse.org/legal/cpl-v10.html The most up-to-date briefing materials on the Eclipse project are found on the eclipse.org website at http://eclipse.org/eclipse/ 200303331 1 EclipseEclipse ProjectProject 200303331 3 Eclipse Project Aims ■ Provide open platform for application development tools – Run on a wide range of operating systems – GUI and non-GUI ■ Language-neutral – Permit unrestricted content types – HTML, Java, C, JSP, EJB, XML, GIF, … ■ Facilitate seamless tool integration – At UI and deeper – Add new tools to existing installed products ■ Attract community of tool developers – Including independent software vendors (ISVs) – Capitalize on popularity of Java for writing tools 200303331 4 Eclipse Overview Another Eclipse Platform Tool Java Workbench Help Development Tools JFace (JDT) SWT Team Your Tool Plug-in Workspace Development Debug Environment (PDE) Their Platform Runtime Tool Eclipse Project 200303331 5 Eclipse Origins ■ Eclipse created by OTI and IBM teams responsible for IDE products – IBM VisualAge/Smalltalk (Smalltalk IDE) – IBM VisualAge/Java (Java IDE) – IBM VisualAge/Micro Edition (Java IDE) ■ Initially staffed with 40 full-time developers ■ Geographically dispersed development teams – OTI Ottawa, OTI Minneapolis,
    [Show full text]
  • Language Interoperability in Control Network Programming
    International Journal of Science and Engineering Investigations vol. 7, issue 78, July 2018 ISSN: 2251-8843 Language Interoperability in Control Network Programming Kostadin Kratchanov1, Efe Ergün2 1,2Yaşar University, Izmir, Turkey ([email protected], [email protected]) Abstract - Control Network Programming (CNP) is a There is a number of reasons why language interoperability programming paradigm which is being described with the is highly desirable. For example, if a programmer has to maxim “Primitives + Control Network = Control Network implement a specific feature that has been already implemented program”. It is a type of graphic programming. The Control in another language the corresponding program component can Network is a recursive system of graphs; it can be a purely simply be reused. Some languages are especially fit and descriptive specification of the problem being solved. Clearly, effective in implementing specific features and often have ‘drawing’ the control network does not include any emerged to target particular problem domains. Rich third-party programming. The Primitives are elementary, easily packages for certain languages are available. Also, every understandable and clearly specified actions. Ultimately, they programmer usually has a preferred language in which their have to be programmed. Historically, they are usually coded in expertise and efficiency is better. There are hundreds of Free Pascal. The actual code of the primitives has never been programming languages used and constantly being developed considered important. The essence of an “algorithm” is thus making language interoperability a necessity. represented by its control network. CNP was always meant to Programmers with experience and preferences in different be an easy and fast approach for software application programming languages can easier team up for solving development that actually involves very little real complex tasks.
    [Show full text]
  • Using the Java Bridge
    Using the Java Bridge In the worlds of Mac OS X, Yellow Box for Windows, and WebObjects programming, there are two languages in common use: Java and Objective-C. This document describes the Java bridge, a technology from Apple that makes communication between these two languages possible. The first section, ÒIntroduction,Ó gives a brief overview of the bridgeÕs capabilities. For a technical overview of the bridge, see ÒHow the Bridge WorksÓ (page 2). To learn how to expose your Objective-C code to Java, see ÒWrapping Objective-C FrameworksÓ (page 9). If you want to write Java code that references Objective-C classes, see ÒUsing Java-Wrapped Objective-C ClassesÓ (page 6). If you are writing Objective-C code that references Java classes, read ÒUsing Java from Objective-CÓ (page 5). Introduction The original OpenStep system developed by NeXT Software contained a number of object-oriented frameworks written in the Objective-C language. Most developers who used these frameworks wrote their code in Objective-C. In recent years, the number of developers writing Java code has increased dramatically. For the benefit of these programmers, Apple Computer has provided Java APIs for these frameworks: Foundation Kit, AppKit, WebObjects, and Enterprise Objects. They were made possible by using techniques described later in Introduction 1 Using the Java Bridge this document. You can use these same techniques to expose your own Objective-C frameworks to Java code. Java and Objective-C are both object-oriented languages, and they have enough similarities that communication between the two is possible. However, there are some differences between the two languages that you need to be aware of in order to use the bridge effectively.
    [Show full text]
  • Oracle® Fusion Middleware 1 Oracle Jdeveloper System Requirements
    Oracle® Fusion Middleware Installation Guide for Oracle JDeveloper 11g Release 1 (11.1.1) E13666-08 January 2011 This document provides information on: ■ Section 1, "Oracle JDeveloper System Requirements" ■ Section 2, "Installing the Oracle JDeveloper Studio Edition" ■ Section 3, "Installing the Oracle JDeveloper Java Edition" ■ Section 4, "Using Oracle JDeveloper on Windows" ■ Section 5, "Using Oracle JDeveloper on Linux and UNIX Systems" ■ Section 6, "Using Oracle JDeveloper on Mac OS X Platforms" ■ Section 7, "Migrating from a Previous Version" ■ Section 8, "Enabling Oracle JDeveloper Extensions" ■ Section 9, "Installing Additional Oracle Fusion Middleware Design Time Components" ■ Section 10, "Setting the User Home Directory" ■ Section 11, "Using Oracle JDeveloper in a Multiuser Environment" ■ Section 12, "Using Oracle WebLogic Server with Oracle JDeveloper" ■ Section 13, "Oracle JDeveloper Certification Information" ■ Section 14, "Oracle JDeveloper Accessibility Information" ■ Section 15, "Uninstalling Oracle JDeveloper" ■ Section 16, "Oracle on the Web" ■ Section 17, "Documentation Accessibility" 1 Oracle JDeveloper System Requirements This release of Oracle JDeveloper is tested and supported on the specific versions Windows, Linux, and Mac OS X, as listed in Section 1.1, "Recommended CPU, Memory, Display, and Hard Drive Configurations". In addition, it is supported on any operating system that supports Sun Java SE Development Kit (JDK) 6 Update 21 or later. ORACLE CONFIDENTIAL. 1.1 Recommended CPU, Memory, Display, and Hard Drive
    [Show full text]
  • Xcode Chapter.Indd
    Chapter 1 Xcode Many computer books use Chapter 1 to cover introductory material. Xcode Tools Sensei is not one of those books. I want you to start learning immediately. After reading this chapter you’ll know how to create a project, add files to your project, edit source code, model data, read developer documentation, configure the compiler, and build your project into a working Mac OS X program. Creating a Project Every program you write with Xcode requires a project, no matter how small the program is. An Xcode project contains your program’s source code files and other files Xcode needs to build a working program, such as Interface Builder nib files. To create an Xcode project, choose File > New Project, and the Project Assistant window opens. Xcode has the following project categories: n Action n Application n Audio Units n Bundle n Command-Line Utility n Dynamic Library n External Build System n Framework n J2EE n Java n Kernel Extension n Standard Apple Plug-Ins n Static Library I will go into greater detail on the types of projects shortly, but most of you will be making application projects. After choosing the type of project you want to make, click the Next button. Tell Xcode the name of your project and where you want to store it, then click the Finish button. Congratulations! You’ve created an Xcode project. What Xcode includes in a project depends on the type of project you create. Xcode includes the following files for a Cocoa application: n An Objective C source code file, main.m.
    [Show full text]
  • Tutorial on Building a Web Application with Jdeveloper Using EJB, JPA and Java Server Faces by Phaninder Surapaneni
    Tutorial on Building a web Application with Jdeveloper using EJB, JPA and Java Server Faces By Phaninder Surapaneni This Tutorial covers: 1.Building the DataModel using EJB3.0. 2.Creating aMasterDetail JSF Page. 3. Creating an Edit Page. 4.Customizing the layout. In this tutorial model is provided by EJB components, view and controller are provided by JavaServer Faces. We will be building the user interface using ADF Faces set of JSF compatible component. Establishing DataBase Connection Step1: Open Jdeveloper ,click on the connections tab and right click on the Database and click on theNew Database Connection. Step2 : Enter the username and password and then enter the Host Name = oracle.cis.ksu.edu And SID = ORACLE and click on next. After the connection is established , test whether the connection works or not and click on finsih. Building a Data Model with EJB 3.0 Step1: Click on the Applications tab and right click on the applications and select New Application. Then a create Application dialog box will appear. Enter the Application name as Ejbapp and enter oracle as Application Package info and select Web Application [JSF, EJB]. Now click on Manage Templates. Step2 : In the Application templates select the view and controller in web Application [JSF, EJB] and in the view and controller pane enter the project name to UserInterface.jpr Step3 : In the Application templates select the Data Model in web Application [JSF, EJB] and in the Data Model Pane enter the project name to EJBModel.jpr. Then click on ok. Creating the Persistence Model Step 1: In the Application Navigator, right click on the EJBModel node and select new Step 2: In the New Gallery dialog box, in the Business Tier, Click on the EJB node then, select Entities from Tables (JPA/EJB 3.0) and click on next.
    [Show full text]
  • Xcode Setup Department of Computer Science & Electrical Engineering
    Xcode Setup Department of Computer Science & Electrical Engineering Xcode is an Integrated Development Environment (IDE) provided for free by Apple Inc. to develop Apple Macintosh and Apple iOS applications. While it is optimized for those scenarios, it works well for the types of projects we do in the Computer Science program. An IDE is a development tool consisting of three components: Editor. An editor is a tool designed to help the user create and make changes to a document. A code editor is specifically designed to facilitate writing code. Other common code editors include emacs and vi. Compiler. A compiler translates source code (such as Java or C++) into machine language (such as an .exe or a.out). We use g++ as the compiler in CS 124 and CS 165. Debugger. A debugger is a program that allows the developer to pause execution of program while it is running to see what is going on inside. A debugger enables the developer to look at local variables, see which functions were called (called the “call stack”), peek at memory, and even make changes to the data of the program while it is running. Xcode is an IDE designed to support a wide variety of languages. The “first class” languages include Objective C, C++, and Java. Setup In order to get up-and-running with Xcode, you will need to copy your code to your Mac, install Xcode on your Mac, create a project, link relevant libraries, and run. 1. Copy your files The easiest way to copy your Linux program files to your Mac is with a thumb drive.
    [Show full text]
  • Java (Software Platform) from Wikipedia, the Free Encyclopedia Not to Be Confused with Javascript
    Java (software platform) From Wikipedia, the free encyclopedia Not to be confused with JavaScript. This article may require copy editing for grammar, style, cohesion, tone , or spelling. You can assist by editing it. (February 2016) Java (software platform) Dukesource125.gif The Java technology logo Original author(s) James Gosling, Sun Microsystems Developer(s) Oracle Corporation Initial release 23 January 1996; 20 years ago[1][2] Stable release 8 Update 73 (1.8.0_73) (February 5, 2016; 34 days ago) [±][3] Preview release 9 Build b90 (November 2, 2015; 4 months ago) [±][4] Written in Java, C++[5] Operating system Windows, Solaris, Linux, OS X[6] Platform Cross-platform Available in 30+ languages List of languages [show] Type Software platform License Freeware, mostly open-source,[8] with a few proprietary[9] compo nents[10] Website www.java.com Java is a set of computer software and specifications developed by Sun Microsyst ems, later acquired by Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment . Java is used in a wide variety of computing platforms from embedded devices an d mobile phones to enterprise servers and supercomputers. While less common, Jav a applets run in secure, sandboxed environments to provide many features of nati ve applications and can be embedded in HTML pages. Writing in the Java programming language is the primary way to produce code that will be deployed as byte code in a Java Virtual Machine (JVM); byte code compil ers are also available for other languages, including Ada, JavaScript, Python, a nd Ruby.
    [Show full text]
  • Visual Studio Code
    Visual Studio Code Tips & Tricks Vol. 1 1st Edition – March 2016, Revision 1 (April 2016) © Microsoft 2016 All rights reserved. This document is for informational purposes only. Microsoft Deutschland GmbH · Konrad-Zuse-Str. 1 · D-85716 Unterschleißheim Tel. +49 (0)89 31760 · www.microsoft.com · www.techwiese.de Authors: Tobias Kahlert and Kay Giza · Microsoft Germany Editor: Mathias Schiffer Localization: textoso · www.textoso.com Page 1 of 26 This book expresses the authors’ views and opinions. This document always up-to-date at: http://aka.ms/VSCodeTipsTricks Contents Visual Studio Code? ................................................................................................................................. 4 Preface ..................................................................................................................................................... 5 What is Visual Studio Code? .................................................................................................................... 6 Tip 1 – Getting the Latest and Greatest as a VS Code Insider ................................................................. 6 Tip 2 – Multiple Cursors .......................................................................................................................... 8 Tip 3 – Using the Command Palette to Control VS Code ........................................................................ 8 Tip 4 – Selecting a Language for a File ...................................................................................................
    [Show full text]
  • Using Free Pascal to Create Android Applications
    Using Free Pascal to create Android applications Michaël Van Canneyt January 19, 2015 Abstract Since several years, Free pascal can be used to create Android applications. There are a number of ways to do this, each with it’s advantages and disadvantages. In this article, one of the ways to program for Android is explored. 1 Introduction Programming for Android using Free Pascal and Lazarus has been possible since many years, long before Delphi unveiled its Android module. However, it is not as simple a process as creating a traditional Desktop application, and to complicate matters, there are several ways to do it: 1. Using the Android NDK. Google makes the NDK available for tasks that are CPU- intensive (a typical example are opengl apps), but warns that this should not be the standard way of developing Android apps. This is the way Delphi made it’s Android port: Using Firemonkey – which uses OpenGL to draw controls – this is the easiest approach. There is a Lazarus project that aims to do things in a similar manner (using the native-drawn widget set approach). 2. Using the Android SDK: a Java SDK. This is the Google recommended way to create Android applications. This article shows how to create an Android application using the Java SDK. 2 FPC : A Java bytecode compiler The Android SDK is a Java SDK: Android applications are usually written in Java. How- ever, the Free Pascal compiler can compile a pascal program to Java Bytecode. This is done with the help of the JVM cross-compiler. Free Pascal does not distribute this cross-compiler by default (yet), so it must be built from sources.
    [Show full text]
  • Modern Object Pascal Introduction for Programmers
    Modern Object Pascal Introduction for Programmers Michalis Kamburelis Table of Contents 1. Why ....................................................................................................................... 3 2. Basics .................................................................................................................... 3 2.1. "Hello world" program ................................................................................. 3 2.2. Functions, procedures, primitive types ....................................................... 4 2.3. Testing (if) ................................................................................................... 6 2.4. Logical, relational and bit-wise operators ................................................... 8 2.5. Testing single expression for multiple values (case) ................................... 9 2.6. Enumerated and ordinal types and sets and constant-length arrays ......... 10 2.7. Loops (for, while, repeat, for .. in) ............................................................ 11 2.8. Output, logging ......................................................................................... 14 2.9. Converting to a string ............................................................................... 15 3. Units .................................................................................................................... 16 3.1. Units using each other .............................................................................. 18 3.2. Qualifying identifiers with
    [Show full text]