Important Note: Use the following instructions to change the proxy settings for Maven if you are part of the secured network and behind a firewall ONLY otherwise skip this activity and continue with the next activity, Creating a GIT Repository.
-
Open the C:\Program Files\NetBeans 8.1\java\maven\conf\settings.xml file with a text editor like Notepad++.
Note: On a Mac the settings.xml file can be found at /Applications/NetBeans/NetBeans 8.1.app/Contents/Resources/Netbeans/java/maven/conf/settings.xml
-
Add the following lines under the tag:
<proxy> <id>Oracle</id> <active>true</active> <protocol>http</protocol> <host>**ENTER YOUR PROXY ADDRESS**</host> <port>80</port> <nonProxyHosts>localhost|oracle.com</nonProxyHosts> </proxy>
-
Replace ENTER YOUR PROXY ADDRESS within the tag with your proxy and save the file.
Note: If you are facing problems in editing the settings.xml file, save a copy of the settings.xml file to some other location, modify it, and then put it back in to C:\Program Files\NetBeans 8.1\java\maven\conf\ (Windows) or /Applications/NetBeans/NetBeans 8.1.app/Contents/Resources/Netbeans/java/maven/conf/ (Mac) directory.
-
Open the C:\Maven\apache-maven-3.3.9\conf\settings.xml file with a text editor like Notepad++.
Note: On a Mac the settings.xml file can be found at /Applications/apache-maven-3.3.9/conf/settings.xml
-
Add the following lines under the tag:
<proxy> <id>Oracle</id> <active>true</active> <protocol>http</protocol> <host>**ENTER YOUR PROXY ADDRESS**</host> <port>80</port> <nonProxyHosts>localhost|oracle.com</nonProxyHosts> </proxy>
-
Replace ENTER YOUR PROXY ADDRESS within the tag with your proxy and save the file.
As part of this activity, you will learn to create and initialize a local GIT repository under user’s home directory.
-
Open Git Bash from the Windows Start menu or open a terminal window if using a Mac.
-
In your home directory, create a cloud directory.
mkdir cloud
-
Change the directory to cloud directory.
cd cloud
-
Create a Git repository type.
git init
-
The cloud directory is now a Git repository. Execute the
ls –a
command to confirm the same. The output of thels –a
command must match the output in the following screenshot:Note: Now you should see that a .git directory has been created inside the cloud directory and your repository is ready.
Before you commit changes to GIT repository, you must configure your name and email address to identify your commits in the repository.
-
Execute the following commands to configure your name:
git config --global user.name "Your Name"
Example:
git config –global user.name "John Doe"
-
Execute the following commands to configure your email address:
git config --global user.email your-email@address
Example:
git config –global user.email <[email protected]>
-
To confirm that the values have been set, execute the following command:
git config --global –l
The output of these commands must be similar to the output in the following screenshot:
Notes:
- This sets your name and email address for all GIT projects.
- Don’t use --global option to set the name and email address at the project level.
As part of this activity, you will learn to create a simple Maven application named, Helloworld-Example to print "Hello World!" message on the console. This application will be used in the subsequent activities to store it in a local GIT repository, creating a project on DevCS, clone it with GIT repository on DevCS and then creating a Build Job for deployment.
Use the following instructions to create a Maven project using Archetypes.
-
Open Git Bash from the Windows Start menu or open a terminal window if using a Mac.
-
Change to the cloud directory where your Git repository is stored.
cd cloud
-
Create a directory named helloworld.
mkdir helloworld
-
Change to the Helloworld directory.
cd helloworld
-
Create an empty Maven project using the maven-archetype-quickstart archetype. Enter the following command:
mvn archetype:generate -DgroupId=com.example -DartifactId=Helloworld-Example -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Note: The output of this command must be similar to the output in the following screenshot:
-
The command creates an empty Maven project named Helloworld-Example. Examine the directory structure and note that an executable class is located at com.example.App. Now the pom.xml file must be configured for
plug-ins. -
Launch Netbeans using the shortcut on the desktop.
-
Open the Helloworld-Example Maven project created under cloud/helloworld directory in Netbeans.
-
Examine the directory structure of the project, open com.example.App executable class, and review the code.
-
Right-click the Project Files > pom.xml file and click Open.
-
Add the following properties settings to the file before the dependencies section. This sets the Java version and encoding for the project.
<properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
-
After the dependencies element, add elements for build and plug-ins.
<build> <plugins> <!-- Your plugins go here --> </plugins> </build>
-
Add the configuration for the compiler plug-in to the plug-ins section.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>
-
Add the exec plug-in to the pom.xml file.
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.4.0</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <mainClass>com.example.App</mainClass> </configuration> </plugin>
-
Add the JAR plug-in to the pom.xml file.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <mainClass>com.example.App</mainClass> </manifest> </archive> </configuration> </plugin>
-
In the source window, right-click the pom.xml file and select Format to fix the indentation for the file.
-
Save the pom.xml file.
-
Right-click the Helloworld-Example project and click Clean and Build.
-
Right-click the Helloworld-Example project and click Run.
-
Select com.example.App from the Available Main Classes list and click the Select Main Class button.
-
You should see Hello World! Output with a BUILD SUCCESS message.
-
Switch to Git Bash(Windows) or terminal window(Mac) and change the directory to Helloworld-Example.
cd Helloworld-Example
-
Execute the
mvn clean compile
command to clean and compile the project. -
Execute the
mvn exec:java
command to execute the application. -
Execute the
mvn package command
to package the application.Note: Examine the Helloworld-Example-1.0-SNAPSHOT.jar file created inside cloud/helloworld/Helloworld-Example/target directory.
-
Execute the
java -jar target/Helloworld-Example-1.0-SNAPSHOT.jar
command to run the packaged application.
Use the following instructions to store the Helloworld-Example project in the local GIT repository.
-
Change into the cloud/helloworld directory.
-
Execute the
git add –n .
command to see the list of files that are ready to be added to the repository.Note: Please notice that there is . at the end of the command.
-
Execute the
git add .
command to add the files to the repository. -
Execute the
git status
command to check the files that are added. -
Execute the
git commit –m "Initial Commit for Helloworld-Example Project"
to commit the files to the repository and begin version tracking. -
Your files are now checked in for version tracking.
-
Check the status of the repository by executing the
git status command
.Note: You should get a response similar to the one in the screenshot.
As part of this activity, you will choose a replication policy (if it not already done by Identity Domain Administrator) to define your primary data center and also specifies whether your data should be replicated to a geographically distant (secondary) data center.
Activate Developer Cloud Service to create an empty project (HelloworldProject) with a repository (HelloworldProjectRepo) to push the Helloworld-Example application that you have created in the previous activity to Developer Cloud Service.
Note: The cloud login credentials and link are required to perform this part of the exercise. Gather this information from the email you have received from Oracle and keep it handy.
-
From any browser, go to the URL: https://cloud.oracle.com
-
Click Sign In in the upper right hand corner of the browser
-
IMPORTANT - Under my services, select from the drop down list the correct data center and click on My Services. If you are unsure of the data center you should select, and this is an in-person training event, ask your instructor which Region to select from the drop down list. If you received your account through an Oracle Trial, your Trial confirmation email should provide a URL that will pre-select the region for you.
-
Select your identity domain and click Go.
NOTE: The Identity Domain, User Name and Password values will be given to you by the instructor or within your Trial confirmation email.
-
Once your Identity Domain is set, enter your User Name and Password and click Sign In
-
You will be presented with a Dashboard displaying the various cloud services available to this account.
-
If all your Storage cloud service is not visible, click on the Customize Dashboard, you can add services to the dashboard by clicking Show. For this workshop, you will want to ensure that you are showing at least the Application Container, Developer and Storage cloud services. If you do not want to see a specific service, click Hide
Depending on the state of your Cloud Account, you may need to set the replication policy, if it has not been previously set. In this step you will got to the Storage Cloud Service to check on the status of the Replicaton Policy.
-
Click on the Open Service Console icon at the top of the screen.
-
If the follow dialog is displayed, care must be taking when setting your replication policy, because it cannot be changed. Take the default and click on the Set Policy button. If the message is not displayed, your replication policy has already been set, and your Cloud Account is ready for the Workshop.
-
Your replication policy is now set, and you can close your browser window.
To find out the replication policy that’s selected for your Oracle Storage Cloud Service instance, click the Storage link in the Dashboard page. On the resulting page, expand Service Details: Oracle Storage Cloud Service, the details of your Oracle Storage Cloud Service instance is displayed. Look for the Replication Policy field, as highlighted in the following screenshot.
In this activity, you are going to activate Developer Cloud Service, create a new project in DevCS, create a GIT repository in DevCS, clone locally built project with DevCS GIT repository and the create a build job for deployment.
Use the following instructions to activate DevCS and create a new project.
-
Services that are assigned to your account will be visible on the Dashboard. If the Developer service is not visible, click the Customize Dashboard button and the Show button for Application Container to make it visible on the Dashboard.
-
Click Developer Cloud Service on the Dashboard to go to the ServiceDetails:developer85599 (Oracle Developer Cloud Service) page.
-
Click the Open Service Console button.
-
Click New Project.
-
Enter the Project Name and Description as shown in the following screenshot and click Next.
-
Click the Empty Project template and Next.
-
Select MARKDOWN from the Wiki Markup drop-down list and click Finish.
-
Provisioning HelloworldProject may take several minutes. Wait until all the modules are provisioned and redirected to the HelloworldProject home screen.
Use the following instructions to create a GIT repository on Developer Cloud Service.
-
Click the New Repository button in the REPOSITORIES section.
-
In the New Repository window, enter the repository name and description as shown in the following screenshot and click Create.
-
It may take a few minutes to create a repository. Wait until the HelloworldProjectRepo repository is created and redirected to the HelloworldProjectRepo home page.
-
Click the HTTP tab in the HelloworldProjectRepo home page and copy the URL.
Use the following instructions to clone the Helloworld-Example project to a GIT repository on Developer Cloud Service.
-
To clone a GIT repository, first change to the cloud/helloworld directory that is the root directory for your repository.
-
Execute
git clone https://[email protected]/developer85599-ouopc084/s/developer85599-ouopc084_helloworldproject_3753/scm/HelloworldProjectRepo.git
Notes:
- Enter your cloud account username and password, if you are prompted.
- If you are not prompted for user name and password and if this
command fails with 403 error then mention the password explicitly
the GIT repository URL. For example:
git clone https://ora1:[email protected]/developer85599-ouopc084/s/developer85599-ouopc084\_helloworlsprojectrepo\_4070/scm/HelloworldProjectRepo.git
- The output of this command should be similar to the output in the above screenshot.
-
Notice that there is a new directory named HelloworldProjectRepo created inside cloud/helloworld directory.
-
Copy and paste Helloworld-Example project directory from cloud/helloworld directory to HelloworldProjectRepo directory
Note: Content of the HelloworldProjectRepo directory should match with the contents listed below screenshot.
-
Change to the HelloworldProjectRepo directory
cd HelloworldProjectRepo
-
Add the source files to GIT from project root directory
git add .
-
Commit the changes
git commit –m "commiting changes to HelloworldProjectRepo repository"
-
Push the files to the repository on Developer Cloud Service
git push origin master
-
Switch to Developer Cloud Service to verify the files pushed to the repository
-
In the HelloworldProject home page, click on HelloworldProjectRepo.git
-
Notice that Helloworld-Example project directory has been pushed to repository on Developer Cloud Service. Click on it and verify its contents.
Use the following instructions to build Helloworld-Example project Developer Cloud Service.
-
In the left navigation pane, click on Build and then New Job
-
In the New Job window, enter HelloworldProjectBJ the job name field and click on Save
-
In the Main tab, enter the following values:
- Edit the job name if it needs adjusting.
- Enter a description.
- Set the JDK to JDK 8.
-
Click the Source Control tab
- Select Git as your repository.
- For URL, select the URL to your Git repository.
-
Click the Build Steps tab.
- Click Add Build Step and select Invoke Maven 3.
- Set the Goals to: clean package.
- Set the POM File location to: Helloworld-Example/pom.xml
-
Click the Post Build tab.
- Select Archive the artifacts.
- Set Files To Archive to: Helloworld-Example/target/Helloworld-Example-1.0-SNAPSHOT.jar
- Set Compression Type to NONE.
-
Click Save and then click Build Now.
If the build was successful, you'll see a file: Helloworld-Example/target/Helloworld-Example-1.0-SNAPSHOT.jar in the Artifacts of Last Successful Build section. You can download it by clicking the file name.
If the build failed then go back to check the build job configuration or click Git Logs to see more information about the error.
With this you have successfully completed creating a local GIT repository, creating a Maven project, storing Maven project in local GIT repository, activating DevCS, creating a project and GIT repository in DevCS, cloning project to DevCS and then creating a build job for deployment.