Git is a distributed version control system that currently is widely used. It is distributed in that it can work in a peer-to-peer fashion, rather than needing to synchronize with a central server.
https://git-scm.com/
https://en.wikipedia.org/wiki/Git
Note that Git is a system (or protocol, depending upon how you define it), rather than a specific piece of software. Meaning, that while a client can be downloaded from the above location, there are other clients available, including the one built into Eclipse.
GitHub (https://github.com/) is a site where people can host their projects. Projects hosted here can be public or private.
Obviously Git has a number of commands that support its workflow, but the simplest one to understand and the one that is most useful immediately is “clone”. This does what the name implies, make a copy of a repository.
Basic Java project
Open up the Git Repository view within Eclipse. This is done via Window->Show View->Other->Git->Git Repositories . This should open a pane in the lower left corner of the Eclipse window, under Package Explorer. Since no repositories have yet been added, there should be three links in this view: "Add an existing local Git repository", "Clone a Git repository", "Create a new local Git repository". There are also icons across the top of this view, three of which perform the same functions as the links. (If a repository has been added to this view, the links will be gone, replaced by the repository list and just the icons will remain.)
Click on "Clone a Git repository". This should pop up a dialog box. In the URI field, enter "https://github.com/cajanssen/basictext.git" (without the quotes). This will autofill the Host and Repository path fields. Click Next. The Branch Selection dialog comes up. Master should already be selected, if not select it. Click Next. The Local Destination dialog comes up. The default local directory for the repository is likely C:\Users\<windowsusername>\git\basictext , which should be fine. In the Projects section of this dialog box, check “Import all existing Eclipse projects after the clone finishes”. This will create the project in Package Explorer as well. Click Finish.
This should have added a repository to the Git Repositories view named basictext. It should also have added a project in the Package Explorer. Click on the new project in Package Explorer. In the menus, click on the Run->Run As->Java Application . (This functionality can also be accessed by Right Clicking on the project name in the Package Explorer.) This should run the project which simply outputs two lines of text to the Console window.
JavaFX project
Since Oracle moved JavaFX into a library separate from the base JRE / JDK in version 9 and beyond, there are some additional steps to do to build and run JavaFX projects in Eclipse. This includes projects that are downloaded from a Git repository. Unfortunately, part of this will need to be done individually for each project.
Configure the Eclipse build environment to include JavaFX.
Assumption here is that the JavaFX SDK has already been downloaded, unpacked and placed in an appropriate directory on the local machine. We will be roughly following the instructions that are here: https://openjfx.io/openjfx-docs/ after clicking the "JavaFX and Eclipse" link on the left side. Following the instructions for "Non-modular projects":
1)Create a new User Library via Window->Preferences->Java->Build Path->User Libraries. (You may need to click on the leading “>” on Build Path to get the Build Path subtree to display.) In the User Libraries area, click New... Give the library a name, such as JavaFX11. Click Ok. With that newly created library selected, click Add External JARs... Navigate to the JavaFX SDK lib directory and add the eight JAR files that are there. Click Apply and Close. This User Library is now available to be added to project build paths.
The next steps will need to be done for each project. Therefore, let's pull down another project from Github to work with. This project will include JavaFX functionality. In the Git Repositories view in Eclipse, click the "Clone a Git Repository" icon. This time, enter "https://github.com/cajanssen/basicFXOne.git" (without the quotes). It should work similar to the clone procedure above.
2)Add the newly created user library to the project build path. This would need to be done for JavaFX projects whether they were pulled down via Git or if they were created locally. Select the new project in the Package Explorer and go to Project->Properties->Java Build Path, Libraries tab. Select Classpath in the list and this will cause the buttons on the right to become active. Select Add Library... Select User Library, click Next, select the created library (whatever you named it, probably JavaFX11). Click Finish. Click Apply and Close in the previous dialog box.
3)Run this downloaded project. As above, this can be done by selecting the BasicJavaFXOne project in the Package Explorer and then selecting the command Run->Run As->Java Application. It will likely need you to select the correct application from between a choice of two in the next dialog box. Select the BasicJavaFXOne application. Running the project will result in an error shown in the Console window.
Error: JavaFX runtime components are missing, and are required to run this application
However, Eclipse will have auto-created a new Run Configuration named BasicJavaFXOne that can now be modified specifically for the new project. There is a runtime modification that must be made to include the JavaFX library. Go to Run->Run Configurations... Select the new configuration BasicJavaFXOne. Select the "(x)= Arguments" tab. In the "VM arguments" box, something similar to the following text needs to be added
--module-path "\path\to\javafx-sdk-12.0.2\lib" --add-modules javafx.controls,javafx.fxml
(This text is taken from the openjfx.io page referenced above.) This must be modified, however, to something local to your machine. Specifically, the \path\to\javafx-sdk-12.0.2 portion should be custom, such as
--module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml
Click Apply. You can now run this application with this run configuration with the Run button. The result should be a window popping up in the middle of the screen containing a filled in black circle.
Monday, August 26, 2019
Sunday, August 11, 2019
Installing WMware Workstation and an Xubuntu virtual machine
VMware Workstation Player installation
Installation of VMware Workstation Player is pretty straight forward. Download the program from https://www.vmware.com/ . At that site, navigate to Products->Personal Desktop->Workstation Player which will land you at https://www.vmware.com/products/workstation-player.html . Click the Download Now button and get VMware Workstation 15.1.0 Player for Windows 64-bit Operating Systems. Run the installation executable.
Xubuntu download
Xubuntu is one of the official flavors of Ubuntu. It uses the Xfce desktop. (An official flavor of Ubuntu uses the full Ubuntu archive for packages and updates and is on the same development and release cycle as main Ubuntu. https://ubuntu.com/download/flavours ) Download the installation image from https://xubuntu.org/ . Get the latest LTS (Long Term Support) version, currently 18.04 Bionic Beaver. The LTS versions have maintenance updates for essentially five years. LTS versions are released every two years in April (14.04, 16.04, 18.04). An estimated 95% of Ubuntu installations are LTS releases. https://ubuntu.com/about/release-cycle On the download page, follow the link to the United States mirror. Get the latest 64 bit iso - xubuntu-18.04.3-desktop-amd64.iso - as of this writing. The file size is 1.4 GiB.
Run VMware Workstation
Run VMware Workstation Player and select Create a New Virtual Machine. Choose Installer disc image file (iso) and select the downloaded .iso file. Store the virtual disk as one file. The default 20GB should be big enough for a test system. Click the Customize Hardware... button when you get to the settings screen. Change the memory allocated to the virtual machine to at least 4GB. 6GB (6144 MB) is better on a system with 16GB of physical RAM installed. Increase the number of processors allocated to the virtual machine to at least 2. These hardware options can be changed each time the virtual machine is powered on. When the virtual machine powers on, choose Download VMware Tools for Linux. The VMware window can be resized once it is started up.
Friday, August 9, 2019
Installing Java, Eclipse and JavaFX
Note that in these instructions, something in angle
brackets, such as <javadirectory>, is a placeholder for a value that can
vary.
Installing Java
There are variations on implementation of a Java Development
Kit (JDK). Even more numerous are
variations on Java Virtual Machine (JVM) implementation. However, the main two to consider here are
Oracle JDK and OpenJDK. With respect to
functionality, they are currently pretty much the same:
"From Java 11 forward, therefore, Oracle JDK builds and
OpenJDK builds will be essentially identical." - https://blogs.oracle.com/java-platform-group/oracle-jdk-releases-for-java-11-and-later
Getting the Oracle JDK involves having or creating a free
account at Oracle and logging in before downloading. Getting the OpenJDK has less friction so that
is recommended. https://openjdk.java.net/ will point to https://jdk.java.net/12/ to get version
12. Previous versions will work, but
might as well get the most recent stable version as it seems that the support
cycle is now shorter than before. Oracle
does have their Version 11 as a Long Term Support (LTS) version, but that seems
to be only for a commercial license.
1—Download the OpenJDK.
Downloading from the above location is a .zip file rather than an
installer.
2—Unpack it and move it to the desired location, such as a
directory under “C:\Program Files”.
3—Add the location <javadirectory>/bin (this is
probably something like C:\Program Files\Java\jdk-12.0.1\bin , depending upon
where you chose to put it) to the system Path variable. Access the Path variable in Windows 10
through: Settings -> System -> About -> System Info -> Advanced
System Settings , Environment Variables button.
4--To test that it is installed and that it can be seen correctly,
open a Windows command line window. This
can be done either through a Start menu item (Windows System -> Command
Prompt) or the use of the Search Box in the Task Bar (type “cmd” or “command
prompt” or something similar). At the
Command Prompt, type “java –version” to establish that is a JVM visible from
everywhere. Type “javac –version” to
establish that there are JDK tools visible from everywhere. (You can use this test to determine the level
of Java support installed on an unfamiliar system. Various Microsoft Windows systems you
encounter may have none, only a JVM or both a JVM and JDK installed.)
Installing Eclipse
Download the Eclipse installer at https://www.eclipse.org/ . Normally you install applications in the “C:\Program
Files” (or “C:\Program Files (x86)” for 32-bit applications) directory. Depending upon which Windows 10 release you
have and how permissions are set up on your machine, the installer may complain
about trying to install in “C:\Program Files”.
It will likely try and default to a directory under “C:\Users\<currentuser>”
which should work fine.
Installing JavaFX
JavaFX is intended to replace Swing as the standard GUI
library for Java SE (Standard Edition). Since
the JDK 11 release in 2018, JavaFX is part of the open-source OpenJDK, under
the OpenJFX project. Back in version 8,
it was part of the Oracle JDK download.
Now it is downloaded and installed separately.
The main site for JavaFX is here: https://openjfx.io/ . The download link on this page directs to https://gluonhq.com/products/javafx/
. Gluon is a development tools,
libraries and infrastructure company that would appear to be hosting the JavaFX
SDK, among other things. JavaFX can be
downloaded in two forms from this location: as a platform-specific SDK and as a
set of JMODs. JMODs can be used at
compile and link time, but not at run time.
(https://stackoverflow.com/questions/51843208/running-javafx-sample-on-jdk-11-with-openjfx-11-jmods-on-module-path) So download the SDK form. As to which version, it would be a debate
between the most recent version and the LTS (Long Term Support) version. While it seems that the Long Term Support may
only be available via contract, download that version anyway. The support fixes may end up being publicly
available. As of this writing, the public
LTS version is 11.0.2 . (By contrast,
the most current version is 12.0.2 .)
Instructions on what to do upon downloading are here: https://openjfx.io/openjfx-docs/ (the
Getting Started link on the openjfx.io page).
Jump to the “Run HelloWorld using JavaFX 12” section (from the column of
links on the left side). Unzip the
JavaFX SDK downloaded .zip file and copy the JavaFX sdk directory to an appropriate
permanent location if it is not already there.
Next to the Java SDK directory would make sense, such as “C:\Program
Files\Java\javafx-sdk-11.0.2” . On the
instructions web page, click on the Windows tab to get the Windows version of
the commands. The instructions would
suggest using the ‘set’ command at the Command Prompt to create the environment
variable “PATH_TO_FX” . The problem with
this method is that the newly created environment variable will only remain for
the duration of that particular command line session. For Windows, a more permanent way would be to
create the new variable in the same place that the PATH variable was updated,
namely Settings -> System -> About -> System Info -> Advanced
System Settings -> Environment Variables .
Use New… to create the System Variable, with PATH_TO_FX being the
Variable name and the directory path being the Variable value. (To show all of the current environment
variables at the Windows command prompt, use the ‘set’ command with no
parameters.)
Testing the FX installation:
There is a link to the HelloFX.java sample program from the above openjfx-docs page. This goes to a GitHub repository. We will skip over pulling it down with Git
until later, for now it is easy enough to copy the program off the web page and
paste it into a text browser. Save the
program as HelloFX.java to a working directory.
There is a command on the documentation page to compile:
javac --module-path
%PATH_TO_FX% --add-modules javafx.controls HelloFX.java
If you have the PATH_TO_FX variable something like
C:\Program Files\Java\javafx-sdk-11.0.2\lib , this command will result in an three
line error message:
error: invalid flag: Files\Java\javafx-sdk-11.0.2\lib
Usage: javac <options> <source files>
use --help for a list of possible options
This is because there is a space in the pathname. This can be rectified by adding quotes around
the part of the command that decomposes the PATH_TO_FX variable:
javac --module-path "%PATH_TO_FX%" --add-modules
javafx.controls HelloFX.java
This should create a class file in the working
directory. Run it using the java
command, again adding the quotes in the command:
java --module-path "%PATH_TO_FX%" --add-modules
javafx.controls HelloFX
This should pop up a new window on the screen with the text
“Hello, JavaFX 11.0.2, running on Java 12.0.1” in the middle (if all of the
installed versions are the same).
Subscribe to:
Posts (Atom)