This page shows you, step by step, how to convert a simple Java application to a version you can distribute on a Mac. To follow along, download the ButtonDemo (.zip) example from the Java Tutorial. This example was created using NetBeans which uses the Ant utility. You can run all necessary tools and make all necessary edits from the command line, without launching NetBeans. Mac OS X Version 10.6 and below. Use Software Update available on the Apple menu to check that you have the most up-to-date version of Java 6 for your Mac. Java 7 and later versions are not supported by these older versions of Mac OS X. If you have problems with Java 6, contact Apple Technical Support.
- Run Java App As Admin
- Run Java App Mac Ios
- Run Java App Mac Download
- Run Java App Mac Os
- Cannot Launch Java Application Mac
You can run applications right from IntelliJ IDEA if you have an SDK set up for your project/module.
Quick way
If you are not going to pass any parameters to your program, and your program does not require any specific actions to be performed before start, you can run it right from the editor.
The class that you are going to execute must contain a
main()
method with a valid signature, for example: public static void main(String[] args)
.
-
Click in the gutter near the class declaration and select Run.
Customizable way
If you are going to pass parameters to your program, add VM options (for example, to allow remote debugging), or otherwise customize the startup of your program, use a run/debug configuration.
-
Create a run/debug configuration.
-
On the main toolbar, select the run/debug configuration you are going to use.
-
Click or press Shift+F10.
When the application starts, you can view its output in the Run tool window. Every run/debug configuration creates a separate tab when you run it.
To learn more about tool windows and how to manage them, see the Tool windows topic.
Re-run applications
-
On the toolbar of the Run tool window, click or press Shift+F10
If you re-run an application, the output of the previous run is lost. To preserve the output of an application, click the Pin Tab button on the toolbar of the Run tool window. When a tab is pinned, new sessions are opened in another tab.
Stop and pause applications
When you stop a program, its process is interrupted and exits immediately. When you pause a program, it continues running in the background, but its output is suspended.
Stop a program
-
In the Run tool window, click on the toolbar. Alternatively, press Ctrl+F2 and select the process to stop. Yamaha apps for mac.
Pause a program
-
Right-click in the Run tool window and select Pause Output from the context menu. Use the same toggle to resume the program.
Only the output is suspended. Pausing the output does not affect the execution of the program.
Show running processes
You can view the list of all active run or debug sessions and navigate between them.
-
From the main menu, select Run | Show Running List. In the top-right corner of the editor, IntelliJ IDEA shows a list with all active applications.
Before You Begin
Purpose
In this tutorial, you create and build a Java Platform, Standard Edition (Java SE) application using Maven. You install, configure, build, and create an executable Java Archive (JAR) file with Maven.
Time to Complete
Approximately 90 minutes
Background
Maven is a build management tool that is central to project build tasks such as compilation, packaging, and artifact management. Maven uses a strict XML-based rule set to promote consistency while maintaining flexibility. Because most Java-centric continuous integration systems integrate well with Maven, it's a good choice for an underlying build system.The primary goal of Maven is to provide:
-
A project model that is reusable, maintainable, and easier to comprehend
-
Plug-ins or tools that interact with the declarative model
pom.xml
file. The Project Object Model (POM) is the fundamental unit of the entire Maven system.Maven contains three types of repositories for storing JARs, plug-ins, and other project-related artifacts:
-
Local Repository: The location created on your machine when you run your first instance of a Maven command in your machine
-
Central Repository: The Maven community-owned repository that contains commonly used libraries
-
Remote Repository: A developer-owned custom repository that contains project-related libraries and JARs
What Do You Need?
- Download and install the latest Java SE Development Kit. For this tutorial, the available version is Java SE 8.
- Download the Apache Maven. For this tutorial, the available version is 3.2.2.
Setting Up the Maven Environment
In this section, you extract the downloaded archive and install the latest Maven version to a directory of your choice. You verify the Java installation, set the Maven environment, and verify the Maven installation.
- Verify the Java installation:
java -version
The output displays the Java version that you installed. -
Extract the downloaded Maven x.x.x archive to a local directory.The archive names are:
-
Windows OS: apache-maven-3.2.2-bin.zip
-
Linux OS: apache-maven-3.2.2-bin.tar.gz
-
Mac OS: apache-maven-3.2.2-bin.tar.gz
Note: This OBE shows you how to install and create a Java SE application using Maven in a Windows operating system. -
- Click Start, right-click Computer, and select Properties.
-
On the Control Panel home page, click Advanced system settings.
-
In the System Properties dialog box, click the Advanced tab, and then click Environment Variables.
The Environment Variables dialog box is displayed. -
Click New, add
M2, M2_HOME,
andMAVEN_OPTS
to the environment variables, and click OK. -
Under System variables, click New, enter the following values in the Edit System variable dialog box, and click OK:
-
Variable name:
Path
-
Variable value:
%M2%
(Enter the value afterbin
in the system path)
-
-
Verify the Maven installation:
mvn -version
The output displays the installed Maven version, the Java version, the Java home, the Default locale, and the OS name.
Creating a Java SE Project from a Maven Template
-
Open the command prompt, navigate to the directory where you installed Maven, and create
Maven_app,
a Maven-based Java application folder:mvn archetype:generate -DgroupId=com.example.bank
-DartifactId=OracleBanking
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=falseAn archetype is an original pattern/model for creating similar projects. In Maven, an archetype is a template of a project that is combined with user input to produce a working Maven project. The following table describes what the template does:
Archetype ArtifactIds Description mvn archetype:generate
Creates a project -DgroupId=com.example.bank
Creates the com.example.bank
dependency package structuremaven-archetype-quickstart
Creates a Java project -DinteractiveMode=false
Sets interactive mode to false
The Java project namedOracleBanking
is created. The following table presents the project details:
Project Structure Description OracleBanking
Contains src
folder andpom.xml
src/main/java
Contains Java code files under the package structure
(com.example/bank
)src/test
Contains test code files under the package structure
(com.example/bank
)pom.xml
Contains information about the project and details of various configurations used by Maven to build the project -
Open the
OracleBanking
project and verify the Java source file:App.java
-
Verify Java test file:
AppTest.java
By default, Maven adds theApp.java
source file and theAppTest.java
test file to the default directory structure. -
Open the
pom.xml
file and review the code.Each project has a singlepom.xml
file, and eachpom.xml
file has a project element and three mandatory fields:groupId, artifactId,
andversion.
Notice that Maven has already added JUnit as the test framework. The following table describes what each node does:Node Description project
Top-level element in all Maven pom.xml
filesmodelVersion
Object model version that this POM is using groupId
Project groupId (for example, com.example.bank
)artifactId
Project ID (for example, OracleBanking
)packaging
Project files converted into a JAR file version
Project version used in the artifact's repository to separate each version (for example, 1.0-SNAPSHOT
)name
Project display name url
Location of the project site
Creating and Modifying Java Source Files
In this section, you calculate simple interest by creating the
SimpleInterest.java
source file and modifying the App.java
source file.-
Navigate to the directory where you created your Maven project, and then open the specified location: https://agetree275.weebly.com/mac-osx-timer-app.html.
**Maven_appOracleBankingsrcmainjavacomexamplebank
-
Create a Java source file named
SimpleInterest.java.
-
Edit the
SimpleInterest.java
file with the following code:ThecalculateSimpleInterest
method calculates the interest rate on the loan amount, the tenure of the loan, and the rate of interest per annum. -
Press Ctrl+S and close the file.
-
Modify
App.java
with the following code: -
Review the code. It should look like the following:
-
Press Ctrl+S and close the file.
Creating a Manifest with Maven
In this section, you learn how to use
maven-jar-plugin
to create a manifest file and package it by adding it to the JAR file.
- Defines the entry point of the project and creates an executable JAR file.
- Adds the class path of the project dependencies.
-
Edit the
pom.xml
file:
You definedmaven-jar-plugin
inpom.xml,
and configured it within the configuration tag. -
Review the code. It should look like the following:In the Maven project, you specify the main class details by updating the
pom.xml
file. Thecom.example.bank.App
class in the project is the main class that will be executed when you execute the JAR file. -
Press Ctrl+S and close the file.You successfully updated your
pom.xml
file.
Testing, Building, and Running the Application Using Maven
Testing the Application
In this section, you learn how to test your application with
AppTest.java
using the Maven command-line interface (CLI).
-
Import the package into
AppTest.java:
import junit.framework.Assert;
-
Edit the
AppTest
method: -
Review the code. It should look like the following:You modified the simple interest value, and then verified the value by using assert statements in the JUnit test case. Ripcurl search macos app.
-
Press Ctrl+S and then run the test cases in
AppTest.java
inside theOracleBanking
project.mvn test
-
Review the output.The test case failed and the assert failed message is displayed.
- Modify
AppTest.java:
You modified the simple interest value, and then verified the value by using assert statements in the JUnit test case. -
Press Ctrl+S and then run the test cases in
AppTest.java:
mvn test
The test case executed successfully, and a build success message is displayed.
Building the Application
In this section, you learn how to clean and build your application using the Maven CLI.
Run Java App As Admin
-
Clean and build your Maven project, and review the output:
mvn clean package
You successfully built theOracleBanking
Java SE application using Maven. -
Navigate to the directory where you created
OracleBanking
and notice that atarget
folder was created. -
Open the
target
folder, and review the folder structure.Folder name Description classes
Contains .class
files of Java source filestest-classes
Contains .class
files of Java test filesmaven-archiver
Contains the pom.properties
filesurefire-reports
Contains the report of the application when mvn
command is executed.java
Empty Java file OracleBanking-1.0-SNAPSHOT.jar
Contains all the project related details in a single zip file. This is the executable JAR file used to run the application
Run Java App Mac Ios
Packaging and Running the Application
In this section, you learn how to package and run the Java SE project using the Maven CLI.
Run Java App Mac Download
-
Navigate to the directory where you installed Maven, and open the
settings.xml
file.The<localRepository>
tag specifies the local repository location on your machine. By default, the local repository is created in the%USER_HOME%
directory. You can specify another location by updating it in thesettings.xml
file. If you need to set proxy details for the application, then update it in thesettings.xml
file. -
Clean and package the files, plug-ins, and libraries before running the application:
mvn clean package
-
Use the Maven Local repository to run your Java SE Maven application:
mvn exec:java -Dexec.mainClass='com.example.bank.App' -s '*****location of settings.xml file.********'
-
Review the output.You successfully executed the Java SE application named
OracleBanking
using Maven. The simple interest is calculated and displayed in the Maven CLI. -
Execute the JAR file with following commands:
cd target
java -jar OracleBanking-1.0-SNAPSHOT.jar
-
Review the output.You successfully executed the
OracleBanking
Java SE application by using Maven. The simple interest is calculated and displayed in the Maven CLI.
Want to Learn More?
- Installing and Configuring Maven for Build Automation and Dependency Management in Oracle Fusion Middleware Developing Applications Using Continuous Integration
Run Java App Mac Os
Credits
To navigate this Oracle by Example tutorial, note the following:
- Topic List:
- Click a topic to navigate to that section.
- Expand All Topics:
- Click the button to show or hide the details for the sections. By default, all topics are collapsed.
- Hide All Images:
- Click the button to show or hide the screenshots. By default, all images are displayed.
- Print:
- Click the button to print the content. The content that is currently displayed or hidden is printed.
Cannot Launch Java Application Mac
To navigate to a particular section in this tutorial, select the topic from the list.