Quantcast
Channel: DevOps tips & tricks
Viewing all 181 articles
Browse latest View live

Azure networking and storage accounts

$
0
0

 HOWTO

 

Github 

Create Storage account with  Network Rules

Terraform plan

resource "azurerm_storage_account""davestorageaccounttf" {
name = "davestorageaccounttf"
resource_group_name = azurerm_resource_group.daveterraformgroup.name

location = "westeurope"
account_tier = "Standard"
account_replication_type = "LRS"

network_rules {
default_action = "Deny"
ip_rules = ["100.0.0.1"]
virtual_network_subnet_ids = [azurerm_subnet.daveterraformsubnet.id]
bypass = ["Metrics", "AzureServices"]
}

tags = {
environment = "staging"
}
Add container
resource "azurerm_storage_container""example" {
name = "${var.prefix}storagecontainer"
storage_account_name = azurerm_storage_account.davestorageaccounttf.name
container_access_type = "blob"
}
# azurerm_storage_account.daveterraformsa will be created
+ resource "azurerm_storage_account""daveterraformsa" {
+ access_tier = (known after apply)
+ account_kind = "StorageV2"
+ account_replication_type = "LRS"
+ account_tier = "Standard"
+ allow_blob_public_access = false
+ enable_https_traffic_only = true
+ id = (known after apply)
+ is_hns_enabled = false
+ large_file_share_enabled = (known after apply)
+ location = "westeurope"
+ min_tls_version = "TLS1_0"
+ name = "davestorageaccount"
+ nfsv3_enabled = false
+ primary_access_key = (sensitive value)
+ primary_blob_connection_string = (sensitive value)
+ primary_blob_endpoint = (known after apply)
+ primary_blob_host = (known after apply)
+ primary_connection_string = (sensitive value)
+ primary_dfs_endpoint = (known after apply)
+ primary_dfs_host = (known after apply)
+ primary_file_endpoint = (known after apply)
+ primary_file_host = (known after apply)
+ primary_location = (known after apply)
+ primary_queue_endpoint = (known after apply)
+ primary_queue_host = (known after apply)
+ primary_table_endpoint = (known after apply)
+ primary_table_host = (known after apply)
+ primary_web_endpoint = (known after apply)
+ primary_web_host = (known after apply)
+ resource_group_name = "rg-dave-terraform-test"
+ secondary_access_key = (sensitive value)
+ secondary_blob_connection_string = (sensitive value)
+ secondary_blob_endpoint = (known after apply)
+ secondary_blob_host = (known after apply)
+ secondary_connection_string = (sensitive value)
+ secondary_dfs_endpoint = (known after apply)
+ secondary_dfs_host = (known after apply)
+ secondary_file_endpoint = (known after apply)
+ secondary_file_host = (known after apply)
+ secondary_location = (known after apply)
+ secondary_queue_endpoint = (known after apply)
+ secondary_queue_host = (known after apply)
+ secondary_table_endpoint = (known after apply)
+ secondary_table_host = (known after apply)
+ secondary_web_endpoint = (known after apply)
+ secondary_web_host = (known after apply)
+ tags = {
+ "environment" = "Development"
}

+ blob_properties {
+ change_feed_enabled = (known after apply)
+ default_service_version = (known after apply)
+ last_access_time_enabled = (known after apply)
+ versioning_enabled = (known after apply)

+ container_delete_retention_policy {
+ days = (known after apply)
}

+ cors_rule {
+ allowed_headers = (known after apply)
+ allowed_methods = (known after apply)
+ allowed_origins = (known after apply)
+ exposed_headers = (known after apply)
+ max_age_in_seconds = (known after apply)
}

+ delete_retention_policy {
+ days = (known after apply)
}
}

+ identity {
+ principal_id = (known after apply)
+ tenant_id = (known after apply)
+ type = (known after apply)
}

+ network_rules {
+ bypass = (known after apply)
+ default_action = "Deny"
+ ip_rules = [
+ "100.0.0.1",
]
+ virtual_network_subnet_ids = [
+ "/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet",
]
}

+ queue_properties {
+ cors_rule {
+ allowed_headers = (known after apply)
+ allowed_methods = (known after apply)
+ allowed_origins = (known after apply)
+ exposed_headers = (known after apply)
+ max_age_in_seconds = (known after apply)
}

+ hour_metrics {
+ enabled = (known after apply)
+ include_apis = (known after apply)
+ retention_policy_days = (known after apply)
+ version = (known after apply)
}

+ logging {
+ delete = (known after apply)
+ read = (known after apply)
+ retention_policy_days = (known after apply)
+ version = (known after apply)
+ write = (known after apply)
}

+ minute_metrics {
+ enabled = (known after apply)
+ include_apis = (known after apply)
+ retention_policy_days = (known after apply)
+ version = (known after apply)
}
}

+ routing {
+ choice = (known after apply)
+ publish_internet_endpoints = (known after apply)
+ publish_microsoft_endpoints = (known after apply)
}
}

Plan: 1 to add, 1 to change, 0 to destroy.

Terraform apply
[dave@dave azure]$ terraform apply
azurerm_resource_group.daveterraformgroup: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test]
azurerm_public_ip.daveterraformpublicip: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/publicIPAddresses/davePublicIP]
azurerm_virtual_network.daveterraformnetwork: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet]
azurerm_network_security_group.daveterraformnsg: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/networkSecurityGroups/daveNetworkSecurityGroup]
azurerm_subnet.daveterraformsubnet: Refreshing state... [id=/subscriptions/3434434-343-40/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet]
azurerm_network_interface.daveterraformnic: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/networkInterfaces/daveNIC]
azurerm_network_interface_security_group_association.dave: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/networkInterfaces/daveNIC|/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/networkSecurityGroups/daveNetworkSecurityGroup]
azurerm_linux_virtual_machine.daveterraformvm: Refreshing state... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Compute/virtualMachines/dave-terraform-test]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
~ update in-place

Terraform will perform the following actions:

# azurerm_storage_account.davestorageaccounttf will be created
+ resource "azurerm_storage_account""davestorageaccounttf" {
+ access_tier = (known after apply)
+ account_kind = "StorageV2"
+ account_replication_type = "LRS"
+ account_tier = "Standard"
+ allow_blob_public_access = false
+ enable_https_traffic_only = true
+ id = (known after apply)
+ is_hns_enabled = false
+ large_file_share_enabled = (known after apply)
+ location = "westeurope"
+ min_tls_version = "TLS1_0"
+ name = "davestorageaccounttf"
+ nfsv3_enabled = false
+ primary_access_key = (sensitive value)
+ primary_blob_connection_string = (sensitive value)
+ primary_blob_endpoint = (known after apply)
+ primary_blob_host = (known after apply)
+ primary_connection_string = (sensitive value)
+ primary_dfs_endpoint = (known after apply)
+ primary_dfs_host = (known after apply)
+ primary_file_endpoint = (known after apply)
+ primary_file_host = (known after apply)
+ primary_location = (known after apply)
+ primary_queue_endpoint = (known after apply)
+ primary_queue_host = (known after apply)
+ primary_table_endpoint = (known after apply)
+ primary_table_host = (known after apply)
+ primary_web_endpoint = (known after apply)
+ primary_web_host = (known after apply)
+ resource_group_name = "rg-dave-terraform-test"
+ secondary_access_key = (sensitive value)
+ secondary_blob_connection_string = (sensitive value)
+ secondary_blob_endpoint = (known after apply)
+ secondary_blob_host = (known after apply)
+ secondary_connection_string = (sensitive value)
+ secondary_dfs_endpoint = (known after apply)
+ secondary_dfs_host = (known after apply)
+ secondary_file_endpoint = (known after apply)
+ secondary_file_host = (known after apply)
+ secondary_location = (known after apply)
+ secondary_queue_endpoint = (known after apply)
+ secondary_queue_host = (known after apply)
+ secondary_table_endpoint = (known after apply)
+ secondary_table_host = (known after apply)
+ secondary_web_endpoint = (known after apply)
+ secondary_web_host = (known after apply)
+ tags = {
+ "environment" = "staging"
}

+ blob_properties {
+ change_feed_enabled = (known after apply)
+ default_service_version = (known after apply)
+ last_access_time_enabled = (known after apply)
+ versioning_enabled = (known after apply)

+ container_delete_retention_policy {
+ days = (known after apply)
}

+ cors_rule {
+ allowed_headers = (known after apply)
+ allowed_methods = (known after apply)
+ allowed_origins = (known after apply)
+ exposed_headers = (known after apply)
+ max_age_in_seconds = (known after apply)
}

+ delete_retention_policy {
+ days = (known after apply)
}
}

+ identity {
+ principal_id = (known after apply)
+ tenant_id = (known after apply)
+ type = (known after apply)
}

+ network_rules {
+ bypass = [
+ "AzureServices",
+ "Metrics",
]
+ default_action = "Deny"
+ ip_rules = [
+ "100.0.0.1",
]
+ virtual_network_subnet_ids = [
+ "/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet",
]
}

+ queue_properties {
+ cors_rule {
+ allowed_headers = (known after apply)
+ allowed_methods = (known after apply)
+ allowed_origins = (known after apply)
+ exposed_headers = (known after apply)
+ max_age_in_seconds = (known after apply)
}

+ hour_metrics {
+ enabled = (known after apply)
+ include_apis = (known after apply)
+ retention_policy_days = (known after apply)
+ version = (known after apply)
}

+ logging {
+ delete = (known after apply)
+ read = (known after apply)
+ retention_policy_days = (known after apply)
+ version = (known after apply)
+ write = (known after apply)
}

+ minute_metrics {
+ enabled = (known after apply)
+ include_apis = (known after apply)
+ retention_policy_days = (known after apply)
+ version = (known after apply)
}
}

+ routing {
+ choice = (known after apply)
+ publish_internet_endpoints = (known after apply)
+ publish_microsoft_endpoints = (known after apply)
}
}

# azurerm_storage_account_network_rules.davenetworkrules will be created
+ resource "azurerm_storage_account_network_rules""davenetworkrules" {
+ bypass = [
+ "AzureServices",
+ "Metrics",
]
+ default_action = "Allow"
+ id = (known after apply)
+ ip_rules = [
+ "127.0.0.1",
]
+ resource_group_name = "rg-dave-terraform-test"
+ storage_account_name = "davestorageaccounttf"
+ virtual_network_subnet_ids = [
+ "/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet",
]
}

# azurerm_subnet.daveterraformsubnet will be updated in-place
~ resource "azurerm_subnet""daveterraformsubnet" {
id = "/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet"
name = "daveSubnet"
~ service_endpoints = [
+ "Microsoft.Storage",
]
# (7 unchanged attributes hidden)
}

Plan: 2 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

azurerm_subnet.daveterraformsubnet: Modifying... [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet]
azurerm_subnet.daveterraformsubnet: Modifications complete after 4s [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Network/virtualNetworks/daveVnet/subnets/daveSubnet]
azurerm_storage_account.davestorageaccounttf: Creating...
azurerm_storage_account.davestorageaccounttf: Still creating... [10s elapsed]
azurerm_storage_account.davestorageaccounttf: Still creating... [20s elapsed]
azurerm_storage_account.davestorageaccounttf: Creation complete after 22s [id=/subscriptions/3434434-343-4/resourceGroups/rg-dave-terraform-test/providers/Microsoft.Storage/storageAccounts/davestorageaccounttf]


Azure Storage Account

Azure list of resources



Azure VM network topology





Azure CLI - upload file to Azure Storage Account

$
0
0

 HOWTO

 

 

Get Account Key and upload file

[dave@dave azure]$ export ACCOUNT_KEY=`az storage account keys list --account-name davestorageaccounttf  --query [0].value -o tsv`
[dave@dave azure]$ az storage azcopy blob upload -c davecontainer --account-name davestorageaccounttf -s /tmp/foo.txt --account-key $ACCOUNT_KEY

Show container
[dave@dave azure]$ az storage container show --account-key  $ACCOUNT_KEY --account-name davestorageaccounttf --name davecontainer
{
"metadata": {},
"name": "davecontainer",
"properties": {
"contentLength": 0,
"etag": "\"34343434\"",
"hasImmutabilityPolicy": false,
"hasLegalHold": false,
"lastModified": "2021-06-06T20:44:21+00:00",
"lease": {
"duration": null,
"state": "available",
"status": "unlocked"
},
"publicAccess": "blob"
}
}

Blob list
dave@dave azure]$ az storage blob list  --account-key  $ACCOUNT_KEY --account-name davestorageaccounttf --container-name davecontainer
This command has been deprecated and will be removed in future release. Use 'az storage fs file list' instead. For more information go to https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/storage/docs/ADLS%20Gen2.md
The behavior of this command has been altered by the following extension: storage-preview
[
{
"content": null,
"deleted": false,
"metadata": {},
"name": "foo.txt",
"properties": {
"Content-CRC64": null,
"appendBlobCommittedBlockCount": null,
"blobTier": "Hot",
"blobTierChangeTime": null,
"blobTierInferred": true,
"blobType": "BlockBlob",
"contentLength": 6,
"contentRange": null,
"contentSettings": {
"cacheControl": null,
"contentDisposition": null,
"contentEncoding": null,
"contentLanguage": null,
"contentMd5": "4343434==",
"contentType": "text/plain; charset=utf-8"
},
"copy": {
"completionTime": null,
"id": null,
"progress": null,
"source": null,
"status": null,
"statusDescription": null
},
"creationTime": "2021-06-06T20:53:16+00:00",
"deletedTime": null,
"encryptionKeySha256": null,
"etag": "0x8D9292D1B7AE62E",
"lastModified": "2021-06-06T20:53:16+00:00",
"lease": {
"duration": null,
"state": "available",
"status": "unlocked"
},
"pageBlobSequenceNumber": null,
"remainingRetentionDays": null,
"serverEncrypted": true
},
"snapshot": null
}
]


Deploy Azure function in Java

$
0
0

HOWTO

GitHub

 https://github.com/dveselka/devops-terraform/tree/master/azure/function/az-func

 

Create function using Maven

 

[dave@dave function]$ mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=11
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype [com.microsoft.azure:azure-functions-archetype:1.39] found in catalog remote
Downloading from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.pom (1.8 kB at 38 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.jar
Downloaded from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.jar (18 kB at 457 kB/s)
Define value for property 'groupId' (should match expression '[A-Za-z0-9_\-\.]+'): com.dave
[INFO] Using property: groupId = com.dave
Define value for property 'artifactId' (should match expression '[A-Za-z0-9_\-\.]+'): az-func
[INFO] Using property: artifactId = az-func
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' com.dave: :
[INFO] Using property: appName = $(artifactId)-$(timestamp)
[INFO] Using property: appRegion = westus
[INFO] Using property: appServicePlanName = java-functions-app-service-plan
[INFO] Using property: docker = false
[INFO] Using property: javaVersion = 11
[INFO] Using property: resourceGroup = java-functions-group
[INFO] Using property: trigger = HttpTrigger
Confirm properties configuration:
groupId: com.dave
groupId: com.dave
artifactId: az-func
artifactId: az-func
version: 1.0-SNAPSHOT
package: com.dave
appName: $(artifactId)-$(timestamp)
appRegion: westus
appServicePlanName: java-functions-app-service-plan
docker: false
javaVersion: 11
resourceGroup: java-functions-group
trigger: HttpTrigger
Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: azure-functions-archetype:1.39
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.dave
[INFO] Parameter: artifactId, Value: az-func
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.dave
[INFO] Parameter: packageInPathFormat, Value: com/dave
[INFO] Parameter: resourceGroup, Value: java-functions-group
[INFO] Parameter: package, Value: com.dave
[INFO] Parameter: appName, Value: $(artifactId)-$(timestamp)
[INFO] Parameter: javaVersion, Value: 11
[INFO] Parameter: groupId, Value: com.dave
[INFO] Parameter: artifactId, Value: az-func
[INFO] Parameter: appServicePlanName, Value: java-functions-app-service-plan
[INFO] Parameter: trigger, Value: HttpTrigger
[INFO] Parameter: appRegion, Value: westus
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: docker, Value: false
[INFO] Executing META-INF/archetype-post-generate.groovy post-generation script
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/home/dave/.m2/repository/org/codehaus/groovy/groovy/2.4.16/groovy-2.4.16.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Project created from Archetype in dir: /git/devops-terraform/azure/function/az-func
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.355 s
[INFO] Finished at: 2021-06-07T22:04:15+02:00
[INFO] ------------------------------------------------------------------------
[dave@dave function]$ find
.
./az-func
./az-func/host.json
./az-func/pom.xml
./az-func/local.settings.json
./az-func/src
./az-func/src/main
./az-func/src/main/java
./az-func/src/main/java/com
./az-func/src/main/java/com/dave
./az-func/src/main/java/com/dave/Function.java
./az-func/src/test
./az-func/src/test/java
./az-func/src/test/java/com
./az-func/src/test/java/com/dave
./az-func/src/test/java/com/dave/FunctionTest.java
./az-func/src/test/java/com/dave/HttpResponseMessageMock.java
./az-func/.gitignore

Deploy function to Azure

[dave@dave az-func]$ mvn azure-functions:deploy
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.dave:az-func >--------------------------
[INFO] Building Azure Java Functions 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- azure-functions-maven-plugin:1.12.0:deploy (default-cli) @ az-func ---
[WARNING] The POM for com.microsoft.azure.applicationinsights.v2015_05_01:azure-mgmt-insights:jar:1.0.0-beta is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Set function worker runtime to java.
[INFO] Auth type: OAUTH2
Default subscription: Free Trial(3434343434343434343)
Username: some.name@gmail.com
[INFO] Subscription: Free Trial(3434343434343434343)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/home/dave/.m2/repository/org/codehaus/groovy/groovy/2.5.11/groovy-2.5.11.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Creating resource group java-functions-group in region westus...
[INFO] Successfully created resource group java-functions-group.
[INFO] Creating app service plan...
[INFO] Successfully created app service plan java-functions-app-service-plan.
[INFO] Creating function app az-func-20210607220415178...
[INFO] Creating application insights...
[INFO] Successfully created the application insights az-func-20210607220415178 for this Function App. You can visit https://ms.portal.azure.com/#@/resource/subscriptions/3434343434343434343/resourceGroups/java-functions-group/providers/microsoft.insights/components/az-func-20210607220415178/overview to view your Application Insights component.
[INFO] Ignoring decoding of null or empty value to:com.azure.resourcemanager.storage.fluent.models.StorageAccountInner
[INFO] Successfully created function app az-func-20210607220415178.
[INFO] Starting deployment...
[INFO] Trying to deploy artifact to az-func-20210607220415178...
[INFO] Successfully deployed the artifact to https://az-func-20210607220415178.azurewebsites.net
[INFO] Deployment done, you may access your resource through https://ms.portal.azure.com/#@/resource/subscriptions/343434343434/resourceGroups/java-functions-group/providers/Microsoft.Web/sites/az-func-20210607220415178
[INFO] Syncing triggers and fetching function information (Attempt 1/3)...
[INFO] Syncing triggers and fetching function information (Attempt 2/3)...
[INFO] HTTP Trigger Urls:
[INFO] az-func-20210607220415178/HttpExample : https://az-func-20210607220415178.azurewebsites.net/api/httpexample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:17 min
[INFO] Finished at: 2021-06-07T22:15:06+02:00
[INFO] ------------------------------------------------------------------------
Run function
https://az-func-20210607343434.azurewebsites.net/api/httpexample?name=dave
Azure function in Portal

GCP - create VM using Terraform

$
0
0

HOWTO


Install Terraform 

[dave@dave tmp]$ sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
Adding repo from: https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
[dave@dave tmp]$ sudo dnf -y install terraform
Hashicorp Stable - x86_64 2.0 MB/s | 602 kB 00:00
Dependencies resolved.
==================================================================================================================================================================================
Package Architecture Version Repository Size
==================================================================================================================================================================================
Installing:
terraform x86_64 1.0.7-1 hashicorp 25 M
Installing dependencies:
openssl x86_64 1:1.1.1l-2.fc34 updates 658 k

Transaction Summary
==================================================================================================================================================================================
Install 2 Packages

Total download size: 26 M
Installed size: 77 M
Downloading Packages:
(1/2): openssl-1.1.1l-2.fc34.x86_64.rpm 1.9 MB/s | 658 kB 00:00
(2/2): terraform-1.0.7-1.x86_64.rpm 4.3 MB/s | 25 MB 00:05
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 4.2 MB/s | 26 MB 00:06
Hashicorp Stable - x86_64 10 kB/s | 3.1 kB 00:00
Importing GPG key 0xA3219F7B:
Userid : "HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>"
Fingerprint: E8A0 32E0 94D8 EB4E A189 D270 DA41 8C88 A321 9F7B
From : https://rpm.releases.hashicorp.com/gpg
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : openssl-1:1.1.1l-2.fc34.x86_64 1/2
Installing : terraform-1.0.7-1.x86_64 2/2
Running scriptlet: terraform-1.0.7-1.x86_64 2/2
Verifying : openssl-1:1.1.1l-2.fc34.x86_64 1/2
Verifying : terraform-1.0.7-1.x86_64 2/2

Installed:
openssl-1:1.1.1l-2.fc34.x86_64 terraform-1.0.7-1.x86_64

Complete!

Create GCP project and Account Key

 https://cloud.google.com/iam/docs/creating-managing-service-account-keys

 

Install gcloud

[dave@dave ~]$ sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el8-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

[dave@dave ~]$ sudo dnf install google-cloud-sdk
Fedora 34 - x86_64 - Updates 72 kB/s | 9.7 kB 00:00
Fedora Modular 34 - x86_64 - Updates 46 kB/s | 8.0 kB 00:00
Google Cloud SDK 11 MB/s | 38 MB 00:03
Dependencies resolved.
=======================================================================================================================================================
Package Architecture Version Repository Size
=======================================================================================================================================================
Installing:
google-cloud-sdk x86_64 358.0.0-1 google-cloud-sdk 82 M

Transaction Summary
=======================================================================================================================================================
Install 1 Package

gcloud init
You are logged in as: [ab123@gmail.com].

Pick cloud project to use:
[1] dave-terraform
[2] genial-acronym-295114
[3] Create a new project
Please enter numeric choice or text value (must exactly match list
item): 1

Your current project has been set to: [dave-terraform].

Not setting default zone/region (this feature makes it easier to use
[gcloud compute] by setting an appropriate default value for the
--zone and --region flag).
See https://cloud.google.com/compute/docs/gcloud-compute section on how to set
default compute region and zone manually. If you would like [gcloud init] to be
able to do this for you the next time you run it, make sure the
Compute Engine API is enabled for your project on the
https://console.developers.google.com/apis page.

Created a default .boto configuration file at [/home/dave/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use ab123@gmail.com by default
* Commands will reference project `dave-terraform` by default
Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
[dave@dave ~]$ gcloud version
Google Cloud SDK 358.0.0
alpha 2021.09.17
beta 2021.09.17
bq 2.0.71
core 2021.09.17
gsutil 4.68

show service account keys
gcloud iam service-accounts keys list \
--iam-account=sa-name@project-id.iam.gserviceaccount.com

Refactor log4j project to slf4j

$
0
0

HOWTO 

 

Create simple Java project using Maven archetype

$     mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4

Define value for property 'groupId': : dave
Define value for property 'artifactId': : simple
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': dave: :
Confirm properties configuration:
groupId: dave
artifactId: simple
version: 1.0-SNAPSHOT
package: dave
Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: simple
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: dave
[INFO] Parameter: packageInPathFormat, Value: dave
[INFO] Parameter: package, Value: dave
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: simple
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Archetype in dir: /git/simple/simple
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.314 s
[INFO] Finished at: 2021-12-22T22:03:21+01:00
[INFO] ------------------------------------------------------------------------
[dave@dave simple]$ find
.
./simple
./simple/pom.xml
./simple/src
./simple/src/main
./simple/src/main/java
./simple/src/main/java/dave
./simple/src/main/java/dave/App.java
./simple/src/test
./simple/src/test/java
./simple/src/test/java/dave
./simple/src/test/java/dave/AppTest.java
[dave@dave simple]$

Add log4j Maven dependency
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

Add log4j 1.2 call
package dave;

// Import log4j classes.
import org.apache.log4j.*;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{

// get a logger instance named "com.foo"
Logger logger = Logger.getLogger("com.foo");

Logger barlogger = Logger.getLogger("com.foo.Bar");

// This request is enabled, because WARN >= INFO.
logger.warn("Low fuel level.");

// This request is disabled, because DEBUG < INFO.
logger.debug("Starting search for nearest gas station.");

// The logger instance barlogger, named "com.foo.Bar",
// will inherit its level from the logger named
// "com.foo" Thus, the following request is enabled
// because INFO >= INFO.
barlogger.info("Located nearest gas station.");

// This request is disabled, because DEBUG < INFO.
barlogger.debug("Exiting gas station search");
}

}

Add rewrite plugin
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.14.1</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.logging.slf4j.Log4jToSlf4j</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-logging-frameworks</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>
</plugin>

Discover
[INFO] Available Recipes:
[INFO] org.openrewrite.DeleteSourceFiles
[INFO] org.openrewrite.FindSourceFiles
[INFO] org.openrewrite.RenameFile
[INFO] org.openrewrite.hcl.format.AutoFormat
[INFO] org.openrewrite.hcl.format.NormalizeFormat
[INFO] org.openrewrite.hcl.format.RemoveTrailingWhitespace
[INFO] org.openrewrite.hcl.format.Spaces
[INFO] org.openrewrite.hcl.format.TabsAndIndents
[INFO] org.openrewrite.java.AddLicenseHeader
[INFO] org.openrewrite.java.ChangeMethodAccessLevel
[INFO] org.openrewrite.java.ChangeMethodName
[INFO] org.openrewrite.java.ChangeMethodTargetToStatic
[INFO] org.openrewrite.java.ChangeMethodTargetToVariable
[INFO] org.openrewrite.java.ChangePackage
[INFO] org.openrewrite.java.ChangeType
[INFO] org.openrewrite.java.DeleteMethodArgument
[INFO] org.openrewrite.java.GenerateGetter
[INFO] org.openrewrite.java.NoStaticImport
[INFO] org.openrewrite.java.OrderImports
[INFO] org.openrewrite.java.RemoveAnnotation
[INFO] org.openrewrite.java.RemoveUnusedImports
[INFO] org.openrewrite.java.ReorderMethodArguments
[INFO] org.openrewrite.java.SimplifyMethodChain
[INFO] org.openrewrite.java.UseStaticImport
[INFO] org.openrewrite.java.cleanup.AtomicPrimitiveEqualsUsesGet
[INFO] org.openrewrite.java.cleanup.BigDecimalRoundingConstantsToEnums
[INFO] org.openrewrite.java.cleanup.BooleanChecksNotInverted
[INFO] org.openrewrite.java.cleanup.CaseInsensitiveComparisonsDoNotChangeCase
[INFO] org.openrewrite.java.cleanup.CatchClauseOnlyRethrows
[INFO] org.openrewrite.java.cleanup.ControlFlowIndentation
[INFO] org.openrewrite.java.cleanup.CovariantEquals
[INFO] org.openrewrite.java.cleanup.DefaultComesLast
[INFO] org.openrewrite.java.cleanup.EmptyBlock
[INFO] org.openrewrite.java.cleanup.EqualsAvoidsNull
[INFO] org.openrewrite.java.cleanup.ExplicitInitialization
[INFO] org.openrewrite.java.cleanup.ExplicitLambdaArgumentTypes
[INFO] org.openrewrite.java.cleanup.ExternalizableHasNoArgsConstructor
[INFO] org.openrewrite.java.cleanup.FallThrough
[INFO] org.openrewrite.java.cleanup.FinalClass
[INFO] org.openrewrite.java.cleanup.FinalizeLocalVariables
[INFO] org.openrewrite.java.cleanup.FixSerializableFields
[INFO] org.openrewrite.java.cleanup.ForLoopControlVariablePostfixOperators
[INFO] org.openrewrite.java.cleanup.ForLoopIncrementInUpdate
[INFO] org.openrewrite.java.cleanup.HiddenField
[INFO] org.openrewrite.java.cleanup.HideUtilityClassConstructor
[INFO] org.openrewrite.java.cleanup.IndexOfChecksShouldUseAStartPosition
[INFO] org.openrewrite.java.cleanup.IndexOfReplaceableByContains
[INFO] org.openrewrite.java.cleanup.IndexOfShouldNotCompareGreaterThanZero
[INFO] org.openrewrite.java.cleanup.IsEmptyCallOnCollections
[INFO] org.openrewrite.java.cleanup.LambdaBlockToExpression
[INFO] org.openrewrite.java.cleanup.MethodNameCasing
[INFO] org.openrewrite.java.cleanup.MethodParamPad
[INFO] org.openrewrite.java.cleanup.MinimumSwitchCases
[INFO] org.openrewrite.java.cleanup.MissingOverrideAnnotation
[INFO] org.openrewrite.java.cleanup.ModifierOrder
[INFO] org.openrewrite.java.cleanup.MultipleVariableDeclarations
[INFO] org.openrewrite.java.cleanup.NeedBraces
[INFO] org.openrewrite.java.cleanup.NestedEnumsAreNotStatic
[INFO] org.openrewrite.java.cleanup.NewStringBuilderBufferWithCharArgument
[INFO] org.openrewrite.java.cleanup.NoDoubleBraceInitialization
[INFO] org.openrewrite.java.cleanup.NoEmptyCollectionWithRawType
[INFO] org.openrewrite.java.cleanup.NoEqualityInForCondition
[INFO] org.openrewrite.java.cleanup.NoFinalizer
[INFO] org.openrewrite.java.cleanup.NoRedundantJumpStatements
[INFO] org.openrewrite.java.cleanup.NoToStringOnStringType
[INFO] org.openrewrite.java.cleanup.NoValueOfOnStringType
[INFO] org.openrewrite.java.cleanup.NoWhitespaceAfter
[INFO] org.openrewrite.java.cleanup.NoWhitespaceBefore
[INFO] org.openrewrite.java.cleanup.OperatorWrap
[INFO] org.openrewrite.java.cleanup.PadEmptyForLoopComponents
[INFO] org.openrewrite.java.cleanup.PrimitiveWrapperClassConstructorToValueOf
[INFO] org.openrewrite.java.cleanup.RedundantFileCreation
[INFO] org.openrewrite.java.cleanup.RemoveExtraSemicolons
[INFO] org.openrewrite.java.cleanup.RemoveUnusedLocalVariables
[INFO] org.openrewrite.java.cleanup.RemoveUnusedPrivateMethods
[INFO] org.openrewrite.java.cleanup.RenameLocalVariablesToCamelCase
[INFO] org.openrewrite.java.cleanup.RenameMethodsNamedHashcodeEqualOrTostring
[INFO] org.openrewrite.java.cleanup.SimplifyBooleanExpression
[INFO] org.openrewrite.java.cleanup.SimplifyBooleanReturn
[INFO] org.openrewrite.java.cleanup.StaticMethodNotFinal
[INFO] org.openrewrite.java.cleanup.StringLiteralEquality
[INFO] org.openrewrite.java.cleanup.TypecastParenPad
[INFO] org.openrewrite.java.cleanup.UnnecessaryCloseInTryWithResources
[INFO] org.openrewrite.java.cleanup.UnnecessaryExplicitTypeArguments
[INFO] org.openrewrite.java.cleanup.UnnecessaryParentheses
[INFO] org.openrewrite.java.cleanup.UnnecessaryPrimitiveAnnotations
[INFO] org.openrewrite.java.cleanup.UnnecessaryThrows
[INFO] org.openrewrite.java.cleanup.UseCollectionInterfaces
[INFO] org.openrewrite.java.cleanup.UseDiamondOperator
[INFO] org.openrewrite.java.cleanup.UseFilesCreateTempDirectory
[INFO] org.openrewrite.java.cleanup.UseJavaStyleArrayDeclarations
[INFO] org.openrewrite.java.cleanup.UseLambdaForFunctionalInterface
[INFO] org.openrewrite.java.cleanup.WhileInsteadOfFor
[INFO] org.openrewrite.java.cleanup.WriteOctalValuesAsDecimal
[INFO] org.openrewrite.java.format.AutoFormat
[INFO] org.openrewrite.java.format.BlankLines
[INFO] org.openrewrite.java.format.EmptyNewlineAtEndOfFile
[INFO] org.openrewrite.java.format.NormalizeFormat
[INFO] org.openrewrite.java.format.NormalizeLineBreaks
[INFO] org.openrewrite.java.format.NormalizeTabsOrSpaces
[INFO] org.openrewrite.java.format.RemoveTrailingWhitespace
[INFO] org.openrewrite.java.format.SingleLineComments
[INFO] org.openrewrite.java.format.Spaces
[INFO] org.openrewrite.java.format.TabsAndIndents
[INFO] org.openrewrite.java.format.WrappingAndBraces
[INFO] org.openrewrite.java.logging.PrintStackTraceToLogError
[INFO] org.openrewrite.java.logging.log4j.PrependRandomName
[INFO] org.openrewrite.java.logging.logback.Log4jAppenderToLogback
[INFO] org.openrewrite.java.logging.logback.Log4jLayoutToLogback
[INFO] org.openrewrite.java.logging.slf4j.Log4jToSlf4j
[INFO] org.openrewrite.java.logging.slf4j.ParameterizedLogging
[INFO] org.openrewrite.java.search.FindAnnotations
[INFO] org.openrewrite.java.search.FindDeprecatedClasses
[INFO] org.openrewrite.java.search.FindDeprecatedFields
[INFO] org.openrewrite.java.search.FindDeprecatedMethods
[INFO] org.openrewrite.java.search.FindDeprecatedUses
[INFO] org.openrewrite.java.search.FindEmptyClasses
[INFO] org.openrewrite.java.search.FindFields
[INFO] org.openrewrite.java.search.FindFieldsOfType
[INFO] org.openrewrite.java.search.FindMethods
[INFO] org.openrewrite.java.search.FindMissingTypes
[INFO] org.openrewrite.java.search.FindText
[INFO] org.openrewrite.java.search.FindTypes
[INFO] org.openrewrite.java.search.ResultOfMethodCallIgnored
[INFO] org.openrewrite.json.ChangeKey
[INFO] org.openrewrite.json.ChangeValue
[INFO] org.openrewrite.json.DeleteKey
[INFO] org.openrewrite.json.search.FindKey
[INFO] org.openrewrite.maven.AddDependency
[INFO] org.openrewrite.maven.AddPlugin
[INFO] org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId
[INFO] org.openrewrite.maven.ChangeDependencyScope
[INFO] org.openrewrite.maven.ChangePropertyValue
[INFO] org.openrewrite.maven.ExcludeDependency
[INFO] org.openrewrite.maven.ManageDependencies
[INFO] org.openrewrite.maven.OrderPomElements
[INFO] org.openrewrite.maven.RemoveDependency
[INFO] org.openrewrite.maven.RemoveExclusion
[INFO] org.openrewrite.maven.RemovePlugin
[INFO] org.openrewrite.maven.RemoveProperty
[INFO] org.openrewrite.maven.RemoveRedundantDependencyVersions
[INFO] org.openrewrite.maven.UpgradeDependencyVersion
[INFO] org.openrewrite.maven.UpgradeParentVersion
[INFO] org.openrewrite.maven.UpgradePluginVersion
[INFO] org.openrewrite.maven.search.DependencyInsight
[INFO] org.openrewrite.maven.search.FindDependency
[INFO] org.openrewrite.maven.search.FindPlugin
[INFO] org.openrewrite.maven.search.FindProperties
[INFO] org.openrewrite.properties.ChangePropertyKey
[INFO] org.openrewrite.properties.ChangePropertyValue
[INFO] org.openrewrite.properties.DeleteProperty
[INFO] org.openrewrite.properties.search.FindProperties
[INFO] org.openrewrite.text.ChangeText
[INFO] org.openrewrite.text.CreateTextFile
[INFO] org.openrewrite.xml.AutoFormat
[INFO] org.openrewrite.xml.search.FindTags
[INFO] org.openrewrite.yaml.ChangeKey
[INFO] org.openrewrite.yaml.ChangePropertyKey
[INFO] org.openrewrite.yaml.ChangeValue
[INFO] org.openrewrite.yaml.CoalesceProperties
[INFO] org.openrewrite.yaml.CopyValue
[INFO] org.openrewrite.yaml.DeleteKey
[INFO] org.openrewrite.yaml.DeleteProperty
[INFO] org.openrewrite.yaml.MergeYaml
[INFO] org.openrewrite.yaml.cleanup.RemoveUnused
[INFO] org.openrewrite.yaml.format.Indents
[INFO] org.openrewrite.yaml.search.FindKey
[INFO] org.openrewrite.yaml.search.FindProperty
[INFO] org.openrewrite.java.logging.logback.Log4jToLogback
[INFO] org.openrewrite.java.cleanup.Cleanup
[INFO] org.openrewrite.java.cleanup.CommonStaticAnalysis
[INFO] org.openrewrite.java.AddApache2LicenseHeader
[INFO] org.openrewrite.java.search.FindSecrets
[INFO]
[INFO] Available Styles:
[INFO] com.netflix.genie.Style
[INFO] org.openrewrite.java.SpringFormat
[INFO] org.openrewrite.java.GoogleJavaFormat
[INFO] com.netflix.eureka.Style
[INFO]
[INFO] Active Styles:
[INFO]
[INFO] Active Recipes:
[INFO] org.openrewrite.java.logging.slf4j.Log4jToSlf4j
[INFO]
[INFO] Found 173 available recipes and 4 available styles.
[INFO] Configured with 1 active recipes and 1 active styles.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Run rewrite
[dave@dave simple]$ mvn rewrite:run
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------------< dave:simple >-----------------------------
[INFO] Building simple 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> rewrite-maven-plugin:4.14.1:run (default-cli) > process-test-classes @ simple >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /git/simple/simple/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ simple ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /git/simple/simple/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /git/simple/simple/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ simple ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< rewrite-maven-plugin:4.14.1:run (default-cli) < process-test-classes @ simple <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:4.14.1:run (default-cli) @ simple ---
[INFO] Using active recipe(s) [org.openrewrite.java.logging.slf4j.Log4jToSlf4j]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Parsing Java main files...
[INFO] Parsing Java test files...
[INFO] Running recipe(s)...
[WARNING] Changes have been made to src/main/java/dave/App.java by:
[WARNING] org.openrewrite.java.logging.slf4j.Log4jToSlf4j
[WARNING] Please review and commit the results.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Refactored code - log4j replaced with slf4j
 git diff src/main/java/dave/App.java
diff --git a/src/main/java/dave/App.java b/src/main/java/dave/App.java
index 179d8ff..39a78c9 100644
--- a/src/main/java/dave/App.java
+++ b/src/main/java/dave/App.java
@@ -1,7 +1,9 @@
package dave;

// Import log4j classes.
-import org.apache.log4j.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;

/**
* Hello world!
@@ -13,14 +15,14 @@ public class App
{

// get a logger instance named "com.foo"
- Logger logger = Logger.getLogger("com.foo");
+ Logger logger = LoggerFactory.getLogger("com.foo");


- Logger barlogger = Logger.getLogger("com.foo.Bar");
+ Logger barlogger = LoggerFactory.getLogger("com.foo.Bar");

// This request is enabled, because WARN >= INFO.
logger.warn("Low fuel level.");

package dave;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{

// get a logger instance named "com.foo"
Logger logger = LoggerFactory.getLogger("com.foo");

Logger barlogger = LoggerFactory.getLogger("com.foo.Bar");

// This request is enabled, because WARN >= INFO.
logger.warn("Low fuel level.");

// This request is disabled, because DEBUG < INFO.
logger.debug("Starting search for nearest gas station.");

// The logger instance barlogger, named "com.foo.Bar",
// will inherit its level from the logger named
// "com.foo" Thus, the following request is enabled
// because INFO >= INFO.
barlogger.info("Located nearest gas station.");

// This request is disabled, because DEBUG < INFO.
barlogger.debug("Exiting gas station search");
}

}

HP Fortify scan - exclude files

$
0
0

 HOWTO

 

 

 


-exclude

 

Removes files from the list of files to translate. Separate multiple file

<file_specifiers>

 

paths with semicolons (Windows) or colons (non-Windows systems).

 

 

See "Specifying Files and Directories" on page 125 for more

 

 

information on how to use file specifiers.

 

 

For example:

 

 

 

 

 

 

sourceanalyzer –cp"**/*.jar""**/*"

 

 

 

-exclude"**/Test/*.java"

 

 

 

 

 

 

 

This example excludes all Java files in any Test subdirectory.

 

 

 

 

 

Note: When you integrate the translation with a compiler or a

 

 

 

build tool, Fortify Static Code Analyzer translates all source files

 

 

 

that the compiler or build tool processes even if they are specified

 

 

 

with this option.

 

 

 

 

 

 

 

Equivalent Property Name:

 

 

com.fortify.sca.exclude

 

 

 

Specifying Files and Directories

File specifiers are expressions that allow you to pass a long list of files or a directory to Fortify Static Code Analyzer using wildcard characters. Fortify Static Code Analyzer recognizes two types of wildcard characters: a single asterisk character (*) matches part of a file name, and double asterisk characters (**) recursively matches directories. You can specify one or more files, one or more file specifiers, or a combination of files and file specifiers.

<files> | <file_dir_specifiers>

Note: File specifiers do not apply to C, C++, or Objective-C++.

The following table describes examples of file and directory specifiers.

File / Directory Specifier

Description

 

 

<dir>

Matches all files in the named directory and any subdirectories

<dir>/**/*

or the named directory when used for a directory parameter.

 

 

 

<dir>/**/Example.java

Matches any file named Example.java found in the named

 

directory or any subdirectories.

 

 

<dir>/*.java

Matches any file with the specified extension found in the

<dir>/*.jar

named directory.

 

 

 

<dir>/**/*.kt

Matches any file with the specified extension found in the

<dir>/**/*.jar

named directory or any subdirectories.

 

 

 

<dir>/**/beta/**

Matches all directories and files found in the named directory

 

that have beta in the path, including beta as a file name.

 

 

<dir>/**/classes/

Matches all directories and files with the name classes found

 

in the named directory and any subdirectories.

 

 

**/test/**

Matches all files in the current directory tree that have a test

 

element in the path, including test as a file name.

 

 

**/webgoat/*

Matches all files in any webgoat directory in the current

 

directory tree.

 

Matches:

 

/src/main/java/org/owasp/webgoat

 

 

 

Set active sound port to headphones on Linux Fedora Gnome

$
0
0

 HOWTO

 

Get current sound settings
[dave@dave ~]$ pactl list short sinks
44 alsa_output.pci-0000_00_1f.3.analog-stereo PipeWire s32le 2ch 48000Hz RUNNING

[dave@dave ~]$ more ~/.local/state/wireplumber/default-routes 
[default-routes]
alsa_card.pci-0000_00_1f.3:input:analog-input-headset-mic:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:input:analog-input-headset-mic:channelVolumes=0.39999160170555;0.39999160170555;
alsa_card.pci-0000_00_1f.3:input:analog-input-headset-mic:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:channelVolumes=1.0;1.0;
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:channelVolumes=0.39999160170555;0.39999160170555;
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:profile:output:analog-stereo+input:analog-stereo=analog-output-headphones;

Set active port - change to headphones

[dave@dave ~]$ man pactl
[dave@dave ~]$ pactl list sinks |& grep -E "Sink|Ports|analog-ou"
Sink #44
media.class = "Audio/Sink"
Ports:
analog-output-speaker: Speakers (type: Speaker, priority: 10000, availability group: Legacy 3, availability unknown)
analog-output-headphones: Headphones (type: Headphones, priority: 9900, availability group: Legacy 2, availability unknown)
Active Port: analog-output-speaker
[dave@dave ~]$ pactl set-sink-port 44 analog-output-headphones
[dave@dave ~]$ pactl list sinks |& grep -E "Sink|Ports|analog-ou"
Sink #44
media.class = "Audio/Sink"
Ports:
analog-output-speaker: Speakers (type: Speaker, priority: 10000, availability group: Legacy 3, availability unknown)
analog-output-headphones: Headphones (type: Headphones, priority: 9900, availability group: Legacy 2, availability unknown)
Active Port: analog-output-headphones
[dave@dave ~]$ pactl set-sink-port 44 analog-output-headphones

Using Maven with Weblogic 14.1.1

$
0
0

 HOWTO

 

GitHub

 

Set env 

dave@dave dave-basic-webapp-ejb-project]$ . /app/weblogic/wlserver/server/bin/setWLSEnv.sh
CLASSPATH=/usr/java/jdk-11.0.13/lib/tools.jar:/home/app/weblogic/wlserver/modules/features/wlst.wls.classpath.jar:

PATH=/home/app/weblogic/wlserver/server/bin:/home/app/weblogic/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.10.5.0.0/apache-ant-1.10.5/bin:/usr/java/jdk-11.0.13/bin:/usr/java/jdk-11.0.13/bin:/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1//bin:/app/weblogic-14.1.1/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1//bin:/home/dave/.local/bin:/home/dave/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1//bin

Your environment has been set.

 

Compile and deploy the project - requires Maven configuration - see below 

Use Weblogic path /app/weblogic - Maven plugin had issues with Oracle JARs synced to local repository 

Error "java.lang.NoClassDefFoundError Required class missing : weblogic/Deployer" After deleting com/oracle/weblogic in Maven local repo and resync deploy works

dave@dave dave-basic-webapp-ejb-project]$ mvn  clean  compile package  pre-integration-test 
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< dave:dave-basic-webapp-ejb-project >-----------------
[INFO] Building basicWebappEjb 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dave-basic-webapp-ejb-project ---
[INFO] Deleting /git/weblogic/dave-basic-webapp-ejb-project/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /git/weblogic/dave-basic-webapp-ejb-project/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /git/weblogic/dave-basic-webapp-ejb-project/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dave-basic-webapp-ejb-project ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dave-basic-webapp-ejb-project ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ dave-basic-webapp-ejb-project ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/home/dave/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-ejb-project] in [/git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb]
[INFO] Processing war project
[INFO] Copying webapp resources [/git/weblogic/dave-basic-webapp-ejb-project/src/main/webapp]
[INFO] Webapp assembled in [105 msecs]
[INFO] Building war: /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /git/weblogic/dave-basic-webapp-ejb-project/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dave-basic-webapp-ejb-project ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dave-basic-webapp-ejb-project ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ dave-basic-webapp-ejb-project ---
[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-ejb-project] in [/git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb]
[INFO] Processing war project
[INFO] Copying webapp resources [/git/weblogic/dave-basic-webapp-ejb-project/src/main/webapp]
[INFO] Webapp assembled in [66 msecs]
[INFO] Building war: /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- weblogic-maven-plugin:14.1.1-0-0:deploy (default) @ dave-basic-webapp-ejb-project ---
[INFO] Command flags are: -noexit -deploy -username weblogic -password ******* -name basicWebappEjb -source /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war -verbose -adminurl t3://127.0.0.1:7001
weblogic.Deployer invoked with options: -noexit -deploy -username weblogic -name basicWebappEjb -source /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war -verbose -adminurl t3://127.0.0.1:7001
<Jan 30, 2022, 9:00:58 AM Central European Standard Time> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, basicWebappEjb [archive: /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war], to configured targets.>
Task 6 initiated: [Deployer:149026]deploy application basicWebappEjb on AdminServer.
Task 6 completed: [Deployer:149026]deploy application basicWebappEjb on AdminServer.
Target state: deploy completed on Server AdminServer

Target Assignments:
+ basicWebappEjb AdminServer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.671 s
[INFO] Finished at: 2022-01-30T09:01:01+01:00
[INFO] ------------------------------------------------------------------------


 


Install Oracle plugin to local repository

Follow instructions from Oracle Weblogic 14.1.1 HOWTO https://docs.oracle.com/en/middleware/standalone/weblogic-server/14.1.1.0/wlprg/maven.html#GUID-C6FC7582-2D1C-4EA5-B000-71AE9A2F2B05 

 


cd /app/weblogic-14.1.1/
find . -name oracle*maven-*.jar
cd ./oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/14.1.1/

ls ~/.m2/repository/
mvn install:install-file -DpomFile=oracle-maven-sync-14.1.1.pom -Dfile=oracle-maven-sync-14.1.1.jar
mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/app/weblogic-14.1.1/
mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml

  List plugins goals

[dave@dave dave-basic-webapp-ejb-project]$ mvn help:describe -DgroupId=com.oracle.weblogic -DartifactId=weblogic-maven-plugin -Dversion=14.1.1-0-0
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< dave:dave-basic-webapp-ejb-project >-----------------
[INFO] Building basicWebappEjb 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ dave-basic-webapp-ejb-project ---
[INFO] com.oracle.weblogic:weblogic-maven-plugin:14.1.1-0-0

Name: weblogic-maven-plugin
Description: The Oracle WebLogic Server 12.3.1 Maven plugin
Group Id: com.oracle.weblogic
Artifact Id: weblogic-maven-plugin
Version: 14.1.1-0-0
Goal Prefix: weblogic

This plugin has 23 goals:

weblogic:appc
Description: This goal is a wrapper for the weblogic.appc compiler.

weblogic:create-domain
Description: Create a domain for WebLogic Server using the default domain
template. For more complex domain creation use the WLST goal. Note:
Starting in WLS 12.2.1, there is a single unified version of WLST that
automatically includes the WLST environment from all products in the
ORACLE_HOME.

weblogic:deploy
Description: Deploys an application to WebLogic Server (supports all
formats WAR, JAR, RAR, EAR, etc.)

weblogic:distribute-app
Description: Prepares deployment files for deployment by copying deployment
files to target servers and validating them.

weblogic:install
Description: Installs WebLogic Server

weblogic:list-apps
Description: Lists the deployment names for applications and stand-alone
modules deployed distributed, or installed to the domain

weblogic:purge-tasks
Description: Flushes out retired deployment tasks

weblogic:redeploy
Description: Redeploys a running application or part of a running
application

weblogic:remove-domain
Description: This class provides basic capabilities to remove a domain
directory.

weblogic:start-app
Description: Starts an application

weblogic:start-server
Description: Starts WebLogic Server.

weblogic:stop-app
Description: Stops an application

weblogic:stop-server
Description: This goals run a stop script to stop WebLogic Server.

weblogic:undeploy
Description: Stops the deployment unit and removes staged files from target
servers

weblogic:uninstall
Description: Uninstalls WebLogic Server

weblogic:update-app
Description: Updates an application's deployment plan by redistributing the
plan files and reconfiguring the application based on the new plan
contents.

weblogic:wlst
Description: This goal is a wrapper for the WLST scripting tool.
Note: Starting in WLS 12.2.1, there is a single unified version of WLST
that automatically includes the WLST environment from all products in the
ORACLE_HOME.

weblogic:wlst-client
Description: WLST wrapper for Maven that does not require a server install
for WLST online commands.

weblogic:ws-clientgen
Description: A Maven goal to generate client web service artifacts from a
WSDL Note the differences between clientgen Ant task and Maven goal:
clientgen goal only generates JAXWS web service artifacts, while Ant task
has JAXRPC as the default. At the moment there is no way to direct
clientgen goal to also compile and package generated artifacts.
Deprecated. No reason given

weblogic:ws-jwsc
Description: This goal builds a JAX-WS web service, generates source code,
data binding artifacts, deployment descriptors, and so on into an output
directory.
Deprecated. No reason given

weblogic:ws-wsdlc
Description: This goal generates, from an existing WSDL file, a set of
artifacts that together provide a partial Java implementation of the Web
Service described by the WSDL file.
Deprecated. No reason given

weblogic:wsgen
Description: Reads a JAX-WS service endpoint implementation class and
generates all of the portable artifacts for a JAX-WS web service.

weblogic:wsimport
Description: Parses wsdl and binding files and generates Java code needed
to access it.

For more information, run 'mvn help:describe [...] -Ddetail'

Create project using Eclipse and Maven archetype 


 

 


JDK 11 - garbage collector logging

$
0
0

 HOWTO

 

 

GitHub 

* test class  https://github.com/dveselka/java-tutorial/blob/master/src/main/java/gc/LogGC.java

 

GC logs with  timestamp -Xlog:gc*::time

[2022-03-16T22:30:42.734+0100] GC(30) Pause Full (G1 Compaction Pause)
[2022-03-16T22:30:42.734+0100] GC(30) Phase 1: Mark live objects
[2022-03-16T22:30:43.663+0100] GC(30) Phase 1: Mark live objects 929.512ms
[2022-03-16T22:30:43.663+0100] GC(30) Phase 2: Prepare for compaction
[2022-03-16T22:30:43.941+0100] GC(30) Phase 2: Prepare for compaction 277.577ms
[2022-03-16T22:30:43.941+0100] GC(30) Phase 3: Adjust pointers
[2022-03-16T22:30:44.372+0100] GC(30) Phase 3: Adjust pointers 430.642ms
[2022-03-16T22:30:44.372+0100] GC(30) Phase 4: Compact heap
[2022-03-16T22:30:44.748+0100] GC(30) Phase 4: Compact heap 375.878ms
[2022-03-16T22:30:44.751+0100] GC(30) Eden regions: 0->0(99)
[2022-03-16T22:30:44.751+0100] GC(30) Survivor regions: 0->0(13)
[2022-03-16T22:30:44.751+0100] GC(30) Old regions: 1541->1539
[2022-03-16T22:30:44.751+0100] GC(30) Archive regions: 0->0
[2022-03-16T22:30:44.751+0100] GC(30) Humongous regions: 129->129
[2022-03-16T22:30:44.751+0100] GC(30) Metaspace: 3704K(3904K)->3704K(3904K) NonClass: 3407K(3520K)->3407K(3520K) Class: 297K(384K)->297K(384K)
[2022-03-16T22:30:44.751+0100] GC(30) Pause Full (G1 Compaction Pause) 3331M->3330M(3964M) 2017.026ms
[2022-03-16T22:30:44.751+0100] GC(30) User=15.35s Sys=0.02s Real=2.02s
[2022-03-16T22:30:44.751+0100] GC(17) Concurrent Rebuild Remembered Sets 3586.878ms
[2022-03-16T22:30:44.751+0100] GC(17) Concurrent Mark Abort
[2022-03-16T22:30:44.751+0100] GC(17) Concurrent Mark Cycle 5637.293ms
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.HashMap.resize(HashMap.java:702)
at java.base/java.util.HashMap.putVal(HashMap.java:661)
at java.base/java.util.HashMap.put(HashMap.java:610)
at gc.LogGC.main(LogGC.java:15)
[2022-03-16T22:30:44.755+0100] Heap
[2022-03-16T22:30:44.755+0100] garbage-first heap total 4059136K, used 3412405K [0x0000000708400000, 0x0000000800000000)
[2022-03-16T22:30:44.755+0100] region size 2048K, 1 young (2048K), 0 survivors (0K)
[2022-03-16T22:30:44.755+0100] Metaspace used 3801K, committed 3968K, reserved 1056768K
[2022-03-16T22:30:44.755+0100] class space used 307K, committed 384K, reserved 1048576K

GC logs with -Xlog:gc*

[0.002s][warning][logging] Output options for existing outputs are ignored.
[0.016s][info ][gc ] Using G1
[0.019s][info ][gc,init] Version: 17.0.1+12 (release)
[0.019s][info ][gc,init] CPUs: 8 total, 8 available
[0.019s][info ][gc,init] Memory: 15849M
[0.019s][info ][gc,init] Large Page Support: Disabled
[0.019s][info ][gc,init] NUMA Support: Disabled
[0.019s][info ][gc,init] Compressed Oops: Enabled (Zero based)
[0.019s][info ][gc,init] Heap Region Size: 2M
[0.019s][info ][gc,init] Heap Min Capacity: 8M
[0.019s][info ][gc,init] Heap Initial Capacity: 248M
[0.019s][info ][gc,init] Heap Max Capacity: 3964M
[0.019s][info ][gc,init] Pre-touch: Disabled
[0.019s][info ][gc,init] Parallel Workers: 8
[0.019s][info ][gc,init] Concurrent Workers: 2
[0.019s][info ][gc,init] Concurrent Refinement Workers: 8
[0.019s][info ][gc,init] Periodic GC: Disabled


[4.399s][info][gc,heap ] GC(31) Survivor regions: 12->12(12)
[4.399s][info][gc,heap ] GC(31) Old regions: 1535->1563
[4.399s][info][gc,heap ] GC(31) Archive regions: 0->0
[4.399s][info][gc,heap ] GC(31) Humongous regions: 244->244
[4.399s][info][gc,metaspace] GC(31) Metaspace: 3706K(3904K)->3706K(3904K) NonClass: 3409K(3520K)->3409K(3520K) Class: 297K(384K)->297K(384K)
[4.399s][info][gc ] GC(31) Pause Young (Normal) (G1 Preventive Collection) 3632M->3637M(3716M) 34.114ms
[4.399s][info][gc,cpu ] GC(31) User=0.23s Sys=0.01s Real=0.04s
[4.407s][info][gc,start ] GC(32) Pause Young (Normal) (G1 Preventive Collection)
[4.407s][info][gc,task ] GC(32) Using 8 workers of 8 for evacuation
[4.429s][info][gc,phases ] GC(32) Pre Evacuate Collection Set: 0.2ms
[4.429s][info][gc,phases ] GC(32) Merge Heap Roots: 0.1ms
[4.429s][info][gc,phases ] GC(32) Evacuate Collection Set: 21.4ms
[4.429s][info][gc,phases ] GC(32) Post Evacuate Collection Set: 0.1ms
[4.429s][info][gc,phases ] GC(32) Other: 0.1ms
[4.429s][info][gc,heap ] GC(32) Eden regions: 12->0(80)
[4.429s][info][gc,heap ] GC(32) Survivor regions: 12->12(12)
[4.429s][info][gc,heap ] GC(32) Old regions: 1563->1577
[4.429s][info][gc,heap ] GC(32) Archive regions: 0->0
[4.429s][info][gc,heap ] GC(32) Humongous regions: 244->244
[4.429s][info][gc,metaspace] GC(32) Metaspace: 3706K(3904K)->3706K(3904K) NonClass: 3409K(3520K)->3409K(3520K) Class: 297K(384K)->297K(384K)
[4.429s][info][gc ] GC(32) Pause Young (Normal) (G1 Preventive Collection) 3661M->3666M(3716M) 21.847ms
[4.429s][info][gc,cpu ] GC(32) User=0.14s Sys=0.00s Real=0.02s
[4.430s][info][gc,start ] GC(33) Pause Young (Normal) (G1 Humongous Allocation)
[4.430s][info][gc,task ] GC(33) Using 8 workers of 8 for evacuation
[4.443s][info][gc,phases ] GC(33) Pre Evacuate Collection Set: 0.1ms
[4.443s][info][gc,phases ] GC(33) Merge Heap Roots: 0.0ms
[4.443s][info][gc,phases ] GC(33) Evacuate Collection Set: 11.5ms
[4.443s][info][gc,phases ] GC(33) Post Evacuate Collection Set: 0.5ms
[4.443s][info][gc,phases ] GC(33) Other: 0.1ms
[4.443s][info][gc,heap ] GC(33) Eden regions: 2->0(93)
[4.443s][info][gc,heap ] GC(33) Survivor regions: 12->2(12)
[4.443s][info][gc,heap ] GC(33) Old regions: 1577->1591
[4.443s][info][gc,heap ] GC(33) Archive regions: 0->0
[4.443s][info][gc,heap ] GC(33) Humongous regions: 244->244
[4.443s][info][gc,metaspace] GC(33) Metaspace: 3706K(3904K)->3706K(3904K) NonClass: 3409K(3520K)->3409K(3520K) Class: 297K(384K)->297K(384K)
[4.443s][info][gc ] GC(33) Pause Young (Normal) (G1 Humongous Allocation) 3670M->3672M(3816M) 12.175ms
[4.443s][info][gc,cpu ] GC(33) User=0.07s Sys=0.00s Real=0.01s
[4.443s][info][gc,ergo ] Attempting full compaction
[4.443s][info][gc,task ] GC(34) Using 8 workers of 8 for full compaction
[4.443s][info][gc,start ] GC(34) Pause Full (G1 Compaction Pause)
[4.449s][info][gc,phases,start] GC(34) Phase 1: Mark live objects
[5.430s][info][gc,phases ] GC(34) Phase 1: Mark live objects 980.544ms
[5.430s][info][gc,phases,start] GC(34) Phase 2: Prepare for compaction
[5.443s][info][gc,phases ] GC(34) Phase 2: Prepare for compaction 13.229ms
[5.443s][info][gc,phases,start] GC(34) Phase 3: Adjust pointers
[5.738s][info][gc,phases ] GC(34) Phase 3: Adjust pointers 295.030ms
[5.738s][info][gc,phases,start] GC(34) Phase 4: Compact heap
[5.756s][info][gc,phases ] GC(34) Phase 4: Compact heap 17.952ms
[5.785s][info][gc,heap ] GC(34) Eden regions: 0->0(99)
[5.785s][info][gc,heap ] GC(34) Survivor regions: 2->0(12)
[5.785s][info][gc,heap ] GC(34) Old regions: 1591->1541
[5.785s][info][gc,heap ] GC(34) Archive regions: 0->0
[5.785s][info][gc,heap ] GC(34) Humongous regions: 244->129
[5.785s][info][gc,metaspace ] GC(34) Metaspace: 3706K(3904K)->3706K(3904K) NonClass: 3409K(3520K)->3409K(3520K) Class: 297K(384K)->297K(384K)
[5.785s][info][gc ] GC(34) Pause Full (G1 Compaction Pause) 3672M->3331M(3964M) 1341.941ms
[5.785s][info][gc,cpu ] GC(34) User=9.83s Sys=0.22s Real=1.35s
[5.785s][info][gc,ergo ] Attempting maximum full compaction clearing soft references
[5.785s][info][gc,task ] GC(35) Using 8 workers of 8 for full compaction
[5.786s][info][gc,start ] GC(35) Pause Full (G1 Compaction Pause)
[5.786s][info][gc,phases,start] GC(35) Phase 1: Mark live objects
[6.797s][info][gc,phases ] GC(35) Phase 1: Mark live objects 1011.022ms
[6.797s][info][gc,phases,start] GC(35) Phase 2: Prepare for compaction
[7.091s][info][gc,phases ] GC(35) Phase 2: Prepare for compaction 293.850ms
[7.091s][info][gc,phases,start] GC(35) Phase 3: Adjust pointers
[7.551s][info][gc,phases ] GC(35) Phase 3: Adjust pointers 460.264ms
[7.551s][info][gc,phases,start] GC(35) Phase 4: Compact heap
[7.967s][info][gc,phases ] GC(35) Phase 4: Compact heap 416.610ms
[7.971s][info][gc,heap ] GC(35) Eden regions: 0->0(99)
[7.971s][info][gc,heap ] GC(35) Survivor regions: 0->0(12)
[7.971s][info][gc,heap ] GC(35) Old regions: 1541->1540
[7.971s][info][gc,heap ] GC(35) Archive regions: 0->0
[7.971s][info][gc,heap ] GC(35) Humongous regions: 129->129
[7.971s][info][gc,metaspace ] GC(35) Metaspace: 3706K(3904K)->3706K(3904K) NonClass: 3409K(3520K)->3409K(3520K) Class: 297K(384K)->297K(384K)
[7.971s][info][gc ] GC(35) Pause Full (G1 Compaction Pause) 3331M->3330M(3964M) 2185.032ms
[7.971s][info][gc,cpu ] GC(35) User=15.44s Sys=0.03s Real=2.18s
[7.971s][info][gc,marking ] GC(19) Concurrent Mark From Roots 5527.878ms
[7.971s][info][gc,marking ] GC(19) Concurrent Mark Abort
[7.971s][info][gc ] GC(19) Concurrent Mark Cycle 5539.567ms
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.HashMap.resize(HashMap.java:702)
at java.base/java.util.HashMap.putVal(HashMap.java:661)
at java.base/java.util.HashMap.put(HashMap.java:610)
at gc.LogGC.main(LogGC.java:15)
[7.973s][info][gc,heap,exit ] Heap
[7.973s][info][gc,heap,exit ] garbage-first heap total 4059136K, used 3412405K [0x0000000708400000, 0x0000000800000000)
[7.973s][info][gc,heap,exit ] region size 2048K, 1 young (2048K), 0 survivors (0K)
[7.973s][info][gc,heap,exit ] Metaspace used 3802K, committed 3968K, reserved 1056768K
[7.973s][info][gc,heap,exit ] class space used 307K, committed 384K, reserved 1048576K

 

Create GihHub Action with Maven build

$
0
0

HOWTO

 

GitHub

  •  https://github.com/dveselka/java-tutorial/tree/master/.github/workflows

 

Workflow file

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

 

Run list


 Job detail


 


Java EE: XML Schemas for Java EE Deployment Descriptors

$
0
0

Running JSF 1.1 application on Weblogic 12.2.1.4 with latest patches

$
0
0

 HOWTO

 

javax.faces.FacesException: Expression Error: Named Object: not found 

 

Web app configuration files - placed into WEB-INF

  • faces-config.xml - JSF specific
  • web.xml - web app
  • weblogic.xml - app server specific

Debug compiled JSP pages - use keepgenerated in weblogic.xml to see produced Java code

jsp-descriptor https://docs.oracle.com/cd/E11035_01/wls100/webapp/weblogic_xml.html#wp1038491 

 


working-dir
internally generated directory
The name of a directory where WebLogic Server saves the generated Java and compiled class files for a JSP.

keepgenerated
false
Saves the Java files that are generated as an intermediary step in the JSP compilation process. Unless this parameter is set to true, the intermediate Java files are deleted after they are compiled.

TLD files - add custom files into WEB-INF

<%@ taglib uri="/WEB-INF/tags/customTags.tld"  prefix="tt"%>

 

Faces config - add custom files in faces-config.xml

<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/custom-config.xml,/WEB-INF/other-custom-config.xml
</param-value>
</init-param>

Disable Spring DEBUG in log4j2 logs on Weblogic

$
0
0

HOWTO 

 

There is dump of all environment variables in Weblogic log due to Spring initialization

2022-05-12 14:13:43,673;DEBUG;com.bea.core.repackaged.springframework.core.env.AbstractEnvironment;<init>();125;Initialized StandardEnvironment with PropertySources

 

To remove it add logger for com.bea.core.repackaged.springframework into log4j.xml file

<logger name="com.bea.core.repackaged.springframework" additivity="false">
<level value="error" />
<appender-ref ref="some-appender"/>
</logger>

 

Check in Weblogic logs

weblogic.log:<May 18, 2022 10:24:09,804 AM CEST> <Notice> <Stdout> <BEA-000000> <2022-05-18 10:24:09,804 [ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' DEBUG Level value for com.bea.core.repackaged.springframework is [error].>
weblogic.log:<May 18, 2022 10:24:09,804 AM CEST> <Notice> <Stdout> <BEA-000000> <2022-05-18 10:24:09,804 [ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)' DEBUG com.bea.core.repackaged.springframework level set to ERROR>

Remove deprecated Oracle JDBC classes oracle.sql.ArrayDescriptor, oracle.sql.STRUCT, oracle.sql.StructDescriptor

$
0
0

 HOWTO

 
 
package dave.service;

import java.sql.Array;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Struct;

import javax.annotation.sql.DataSourceDefinition;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import dave.entity.Account;
import oracle.jdbc.OracleConnection;
import oracle.sql.ArrayDescriptor;
import oracle.sql.SQLName;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;

@Stateless
//Data Source defined for JPA. It assume the derby database is started up and listen to localhost:1527
@DataSourceDefinition(name = "java:module/env/mavenArchetypeDataSource", className = "org.apache.derby.jdbc.ClientXADataSource", portNumber = 1527, serverName = "localhost", databaseName = "examples", user = "examples", password = "examples", properties = {
"create=true", "weblogic.TestTableName=SQL SELECT 1 FROM SYS.SYSTABLES" })
public class AccountManagerImpl implements AccountManager {

@PersistenceContext
private EntityManager em;

public void depositOnAccount(String name, float amount) {
Account account = em.find(Account.class, name);
if (account == null) {
account = new Account();
account.setName(name);
}
account.setAmount(account.getAmount() + amount);
em.persist(account);
}

public Account findAccount(String name) {

em.getTransaction().begin();
Connection connection = em.unwrap(java.sql.Connection.class);

try {
useDeprecatedOracleConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}

try {
useOracleConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}

return em.find(Account.class, name);
}

private void useDeprecatedOracleConnection(java.sql.Connection connection) throws SQLException {

OracleConnection oracleConnection = null;

if (connection.isWrapperFor(OracleConnection.class)) {
oracleConnection = connection.unwrap(OracleConnection.class);
} else {
// recover, not an oracle connection
}

Object[] reportArray = new Object[3];
STRUCT[] struct = new STRUCT[1];

ArrayDescriptor arrayDescriptor = new ArrayDescriptor(
new SQLName("T_REPORT_TABLE", (OracleConnection) connection), connection);
StructDescriptor structDescriptor = StructDescriptor.createDescriptor("R_REPORT_OBJECT", connection);

oracle.sql.ARRAY reportsArray = new oracle.sql.ARRAY(arrayDescriptor, connection, struct);

}

private void useOracleConnection(java.sql.Connection connection) throws SQLException {

OracleConnection oracleConnection = null;

if (connection.isWrapperFor(OracleConnection.class)) {
oracleConnection = connection.unwrap(OracleConnection.class);
} else {
// recover, not an oracle connection
}

Object[] reportArray = new Object[3];
Struct[] struct = new Struct[1];

int arrayIndex = 0;

struct[arrayIndex++] = connection.createStruct("R_REPORT_OBJECT", reportArray);

Array reportsArray = ((OracleConnection) connection).createOracleArray("T_REPORT_TABLE", struct);

}
}

Docker UBI RedHat image

$
0
0

HOWTO 

 

Search for image

Pastdave@dave ~]$ docker search registry.access.redhat.com/ubi
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubi8/go-toolset Platform for building and running Go 1.11.5 … 0
ubi9/go-toolset rhcc_registry.access.redhat.com_ubi9/go-tool… 0
ubi7 The Universal Base Image is designed and eng… 0
ubi9-beta/ubi Provides the latest release of Red Hat Unive… 0
ubi8/openjdk-8-runtime OpenJDK 1.8 runtime-only image on Red Hat Un… 0
ubi8/openjdk-11-runtime OpenJDK 11 runtime-only image on Red Hat Uni… 0
ubi8/openjdk-17-runtime OpenJDK 17 runtime-only image on Red Hat Uni… 0
ubi7/ubi-minimal The Universal Base Image Init is designed to… 0
ubi7/ubi-init The Universal Base Image Init is designed to… 0
ubi8-minimal The Universal Base Image Minimal is a stripp… 0
ubi7-minimal The Universal Base Image Minimal is a stripp… 0
ubi8/ubi-micro Provides the latest release of Micro Univers… 0
ubi9-beta/ubi-minimal Provides the latest release of the Minimal R… 0
ubi9/ubi-init rhcc_registry.access.redhat.com_ubi9/ubi-init 0
ubi9-init rhcc_registry.access.redhat.com_ubi9-init 0
ubi9-micro rhcc_registry.access.redhat.com_ubi9-micro 0
ubi7/ubi The Universal Base Image is designed and eng… 0
ubi8/ubi Provides the latest release of the Red Hat U… 0
ubi8 The Universal Base Image is designed and eng… 0
ubi9/ubi rhcc_registry.access.redhat.com_ubi9/ubi 0
ubi9 rhcc_registry.access.redhat.com_ubi9 0
ubi8/ubi-minimal Provides the latest release of the Minimal R… 0
ubi8/ubi-init Provides the latest release of the Red Hat U… 0
ubi8-init The Universal Base Image Init is designed to… 0
ubi7-init The Universal Base Image Init is designed to… 0
ubi8-micro Provides the latest release of Micro Univers… 0
ubi9-beta/ubi-init Provides the latest release of the Red Hat U… 0
ubi9-beta/ubi-micro Provides the latest release of Micro Univers… 0
ubi9/ubi-minimal rhcc_registry.access.redhat.com_ubi9/ubi-min… 0
ubi9/ubi-micro rhcc_registry.access.redhat.com_ubi9/ubi-mic… 0
ubi9-minimal rhcc_registry.access.redhat.com_ubi9-minimal 0
ubi7/php-72 Apache 2.4 with PHP 7.2 0
ubi8/php-72 Platform for building and running PHP 7.2 ap… 0
ubi8/s2i-core Base image which allows using of source-to-i… 0
ubi8/s2i-base Base image with essential libraries and tool… 0
ubi8/python-27 Platform for building and running Python 2.7… 0
ubi8/python-36 Platform for building and running Python 3.6… 0
ubi7/nodejs-8 Platform for building and running Node.js 8 … 0
ubi7/ruby-25 Platform for building and running Ruby 2.5 a… 0
ubi7/python-27 Python 2.7 platform for building and running… 0
ubi8/dotnet-21 .NET Core 2.1 SDK and Runtime on RHEL 8 0
ubi7/go-toolset Platform for building and running Go Applica… 0
ubi8/ruby-26 Platform for building and running Ruby 2.6 a… 0
ubi8/nodejs-12 Platform for building and running Node.js 12… 0
ubi8/php-73 Platform for building and running PHP 7.3 ap… 0
ubi7/nodejs-10 Platform for building and running Node.js 10… 0
ubi8/dotnet-30 .NET Core 3.0 SDK and Runtime on RHEL 8 0
ubi7/php-73 Platform for building and running PHP 7.3 ap… 0
ubi7/nodejs-12 Platform for building and running Node.js 12… 0
ubi8/openjdk-8 Source To Image (S2I) image for Red Hat Open… 0
ubi8/python-38 Platform for building and running Python 3.8… 0
ubi8/dotnet-31-runtime .NET Core 3.1 runtime only on RHEL 8 0
ubi8/nginx-118 Platform for running nginx 1.18 or building … 0
ubi8/ruby-27 Platform for building and running Ruby 2.7 a… 0
ubi8/dotnet-50 .NET 5.0 SDK and Runtime on RHEL 8 0
ubi7/nginx-118 Platform for running nginx 1.18 or building … 0
ubi8/pause Podman pod infrastructure container 0
ubi8/skopeo Containerized version of Skopeo 0
ubi8/python-39 Platform for building and running Python 3.9… 0
ubi8/httpd-24 Platform for running Apache httpd 2.4 or bui… 0
ubi7/ruby-30 Ruby 3.0 0
ubi8/podman Containerized version of Podman 0
ubi7/nginx-120 Platform for running nginx 1.20 or building … 0
ubi8/openjdk-17 Source To Image (S2I) image for Red Hat Open… 0
ubi8/php-80 rhcc_registry.access.redhat.com_ubi8/php-80 0
ubi8/perl-532 rhcc_registry.access.redhat.com_ubi8/perl-532 0
ubi8/dotnet-21-runtime Provides the latest release of Red Hat Enter… 0
ubi8/perl-526 Platform for building and running Perl 5.26 … 0
ubi8/nodejs-10 Platform for building and running Node.js 10… 0
ubi8/ruby-25 Platform for building and running Ruby 2.5 a… 0
ubi7/python-36 Platform for building and running Python 3.6… 0
ubi7/s2i-core Base image which allows using of source-to-i… 0
ubi7/s2i-base Base image with essential libraries and tool… 0
ubi8/dotnet-30-runtime .NET Core 3.0 runtime only on RHEL 8 0
ubi7/ruby-26 Platform for building and running Ruby 2.5 a… 0
ubi8/openjdk-11 Source To Image (S2I) image for Red Hat Open… 0
ubi8/dotnet-31 .NET Core 3.1 SDK and Runtime on RHEL 8 0
ubi7/ruby-27 Platform for building and running Ruby 2.7 a… 0
ubi7/python-38 Python 3.8 platform for building and running… 0
ubi8/nodejs-14 Platform for building and running Node.js 14… 0
ubi8/perl-530 Platform for building and running Perl 5.26 … 0
ubi8/php-74 Platform for building and running PHP 7.4 ap… 0
ubi8/dotnet-50-runtime .NET 5.0 runtime only on RHEL 8 0
ubi7/nodejs-14 Platform for building and running Node.js 14… 0
ubi8/buildah Containerized version of Buildah 0
ubi8/nodejs-14-minimal Minimal image for running Node.js 14 applica… 0
ubi8/toolbox Toolbox containerized shell image based in U… 0
ubi8/ruby-30 Platform for building and running Ruby 3.0 a… 0
ubi8/nginx-120 Platform for running nginx 1.20 or building … 0
ubi8/nodejs-16 Platform for building and running Node.js 16… 0
ubi8/nodejs-16-minimal Minimal image for running Node.js 16 applica… 0
ubi8/dotnet-60-runtime .NET 6.0 runtime only on RHEL 8 0
ubi8/dotnet-60 .NET 6.0 SDK and Runtime on RHEL 8 0
ubi8/openssl rhcc_registry.access.redhat.com_ubi8/openssl 0
ubi9-beta/toolbox Toolbox containerized shell image based in U… 0
rhel8/toolbox Toolbox containerized shell image based in U… 0
rhel9-beta/toolbox Toolbox containerized shell image based in U… 0
ubi9/toolbox rhcc_registry.access.redhat.com_ubi9/toolbox 0
ubi9/openjdk-11-runtime rhcc_registry.access.redhat.com_ubi9/openjdk… 0
ubi9/openjdk-17-runtime rhcc_registry.access.redhat.com_ubi9/openjdk… 0
e your text here.

 

Create container 

dave@dave ~]$ docker run -it --name  ubi-test registry.access.redhat.com/ubi8/ubi bash
Unable to find image 'registry.access.redhat.com/ubi8/ubi:latest' locally
latest: Pulling from ubi8/ubi
7985264c26f7: Pull complete
0689084f485b: Pull complete
Digest: sha256:38e7c463209e3c5b7f1fcb79bb250e4653a66f3be9f23f5d175eeeadf8c3da79
Status: Downloaded newer image for registry.access.redhat.com/ubi8/ubi:latest
[root@634052a6ad62 /]# more /etc/redhat-release
Red Hat Enterprise Linux release 8.6 (Ootpa)
[root@634052a6ad62 /]# ls /
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var


Install SSL proxy intercept certificate for Azure CLI on Ubuntu

$
0
0

HOWTO

 

Add SSL intercept certificate to local OS storage

sudo cp SSL-intercept.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

Add into .bashrc

export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

Add SSL intercept certificate to Python

cp SSL-intercept.crt  /usr/lib/python3/dist-packages/certifi/

Maven JAR plugin - include/exclude classes, create additional JARs from module

$
0
0

 HOWTO

Plugin configuration

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<includes>
<include>**/generics/*</include>
</includes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>test-ldap</classifier>
<includes>
<include>**/ldap/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

JARs created

[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ tutorial ---
[INFO] Building jar: /git/java-tutorial/target/tutorial.jar
[INFO]
[INFO] --- maven-jar-plugin:3.3.0:jar (default) @ tutorial ---
[INFO] Building jar: /git/java-tutorial/target/tutorial-test-ldap.jar

Calling Ant from Maven using maven-antrun-plugin

$
0
0

 HOWTO

Sample code

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>
package
</phase>
<configuration>
<target>
<echoproperties />
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="test_classpath" refid="maven.test.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
 
<echo message="compile classpath: ${compile_classpath}" />
<echo message="runtime classpath: ${runtime_classpath}" />
<echo message="test classpath: ${test_classpath}" />
<echo message="plugin classpath: ${plugin_classpath}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Ant packaged JAR installed into Maven repository

Code

<jar destfile="${project.build.directory}/ant-generated.jar"
basedir="${project.build.directory}/classes"
includes="$(project.build.directory}//classes**/*.class"
excludes="**/Test.class"
/>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<groupId>dave</groupId>
<artifactId>ant-jar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>target/ant-generated.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>

Output

INFO]       [jar] Building MANIFEST-only jar: /git/java-tutorial/common/target/ant-generated.jar
[INFO] Executed tasks
[INFO]
[INFO] --- maven-install-plugin:2.5.1:install-file (install-jar-lib) @ tutorial ---
[INFO] pom.xml not found in ant-generated.jar
[INFO] Installing /git/java-tutorial/common/target/ant-generated.jar to /home/dave/.m2/repository/dave/ant-jar/1.0/ant-jar-1.0.jar
[INFO] Installing /tmp/mvninstall5653662900106884773.pom to /home/dave/.m2/repository/dave/ant-jar/1.0/ant-jar-1.0.pom

Special Maven properties exported to Ant


maven.multiModuleProjectDirectory=/git/java-tutorial
project.build.directory=/git/java-tutorial/common/target

Maven classpath exported into Ant

[WARNING]      [echo] compile classpath: /git/java-tutorial/common/target/classes
[WARNING] [echo] runtime classpath: /git/java-tutorial/common/target/classes
[WARNING] [echo] test classpath: /git/java-tutorial/common/target/test-classes:/git/java-tutorial/common/target/classes:/home/dave/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/dave/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[WARNING] [echo] plugin classpath: /home/dave/.m2/repository/org/apache/maven/plugins/maven-antrun-plugin/3.1.0/maven-antrun-plugin-3.1.0.jar:/home/dave/.m2/repository/org/codehaus/plexus/plexus-utils/3.4.1/plexus-utils-3.4.1.jar:/home/dave/.m2/repository/org/apache/ant/ant/1.10.12/ant-1.10.12.jar:/home/dave/.m2/repository/org/apache/ant/ant-launcher/1.10.12/ant-launcher-1.10.12.jar


Exporting properties from Maven to ant 

 See https://maven.apache.org/plugins/maven-antrun-plugin/usage.html 

If the Maven property you want to use is not available in an external file, you will have to redefine the property before calling ant.

<property name="maven.project.url" value="${project.url}"/>
<ant antfile="build.xml"/>

 Ant  properties defined in  maven-antrun-plugin call

FO] --- maven-antrun-plugin:3.1.0:run (default) @ tutorial ---
[INFO] Executing tasks
[INFO] [echoproperties] #Ant properties
[INFO] [echoproperties] #Sat Dec 03 19:41:56 CET 2022
[INFO] [echoproperties] ant.file.maven-antrun-=/git/java-tutorial/common/target/antrun/build-main.xml
[INFO] [echoproperties] sun.desktop=gnome
[INFO] [echoproperties] awt.toolkit=sun.awt.X11.XToolkit
[INFO] [echoproperties] project.build.directory=/git/java-tutorial/common/target
[INFO] [echoproperties] java.specification.version=11
[INFO] [echoproperties] failOnMissingWebXml=false
[INFO] [echoproperties] ant.project.name=maven-antrun-
[INFO] [echoproperties] sun.cpu.isalist=
[INFO] [echoproperties] sun.jnu.encoding=UTF-8
[INFO] [echoproperties] git.build.version=0.0.1-SNAPSHOT
[INFO] [echoproperties] java.class.path=/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1/boot/plexus-classworlds-2.6.0.jar
[INFO] [echoproperties] project.name=tutorial
[INFO] [echoproperties] project.build.testOutputDirectory=/git/java-tutorial/common/target/test-classes
[INFO] [echoproperties] java.vm.vendor=Oracle Corporation
[INFO] [echoproperties] sun.arch.data.model=64
[INFO] [echoproperties] settings.localRepository=/home/dave/.m2/repository
[INFO] [echoproperties] project.groupId=dave
[INFO] [echoproperties] java.vendor.url=https\://openjdk.java.net/
[INFO] [echoproperties] user.timezone=Europe/Prague
[INFO] [echoproperties] project.build.outputDirectory=/git/java-tutorial/common/target/classes
[INFO] [echoproperties] maven.conf=/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1/conf
[INFO] [echoproperties] java.vm.specification.version=11
[INFO] [echoproperties] os.name=Linux
[INFO] [echoproperties] ant.file.type.maven-antrun-=file
[INFO] [echoproperties] user.country=US
[INFO] [echoproperties] sun.java.launcher=SUN_STANDARD
[INFO] [echoproperties] sun.boot.library.path=/usr/java/jdk-11.0.16.1/lib
[INFO] [echoproperties] sun.java.command=org.codehaus.plexus.classworlds.launcher.Launcher clean package
[INFO] [echoproperties] jdk.debug=release
[INFO] [echoproperties] maven.home=/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1
[INFO] [echoproperties] sun.cpu.endian=little
[INFO] [echoproperties] maven.compiler.source=11
[INFO] [echoproperties] user.home=/home/dave
[INFO] [echoproperties] project.build.testSourceDirectory=/git/java-tutorial/common/src/test/java
[INFO] [echoproperties] user.language=en
[INFO] [echoproperties] org.hamcrest\:hamcrest-core\:jar=/home/dave/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[INFO] [echoproperties] java.specification.vendor=Oracle Corporation
[INFO] [echoproperties] project.artifactId=tutorial
[INFO] [echoproperties] project.version=0.0.1-SNAPSHOT
[INFO] [echoproperties] java.version.date=2022-08-18
[INFO] [echoproperties] java.home=/usr/java/jdk-11.0.16.1
[INFO] [echoproperties] basedir=/git/java-tutorial/common
[INFO] [echoproperties] file.separator=/
[INFO] [echoproperties] project.packaging=jar
[INFO] [echoproperties] java.vm.compressedOopsMode=Zero based
[INFO] [echoproperties] line.separator=\n
[INFO] [echoproperties] ant.java.version=11
[INFO] [echoproperties] java.specification.name=Java Platform API Specification
[INFO] [echoproperties] java.vm.specification.vendor=Oracle Corporation
[INFO] [echoproperties] java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
[INFO] [echoproperties] git.commit.id.full=ff3ab46b0d66dfa9c433058be438f2cb0c2ea3b1
[INFO] [echoproperties] git.build.time=2022-12-03T19\:41\:55+0100
[INFO] [echoproperties] sun.management.compiler=HotSpot 64-Bit Tiered Compilers
[INFO] [echoproperties] java.runtime.version=11.0.16.1+1-LTS-1
[INFO] [echoproperties] user.name=dave
[INFO] [echoproperties] ant.file=/git/java-tutorial/common/pom.xml
[INFO] [echoproperties] path.separator=\:
[INFO] [echoproperties] securerandom.source=file\:/dev/./urandom
[INFO] [echoproperties] os.version=6.0.10-200.fc36.x86_64
[INFO] [echoproperties] java.runtime.name=Java(TM) SE Runtime Environment
[INFO] [echoproperties] file.encoding=UTF-8
[INFO] [echoproperties] guice.disable.misplaced.annotation.check=true
[INFO] [echoproperties] java.vm.name=Java HotSpot(TM) 64-Bit Server VM
[INFO] [echoproperties] java.vendor.version=18.9
[INFO] [echoproperties] localRepository=\ id\: local\n url\: file\:///home/dave/.m2/repository/\n layout\: default\nsnapshots\: [enabled \=> true, update \=> always]\n releases\: [enabled \=> true, update \=> always]\n
[INFO] [echoproperties] ant.core.lib=/home/dave/.m2/repository/org/apache/ant/ant/1.10.12/ant-1.10.12.jar
[INFO] [echoproperties] java.vendor.url.bug=https\://bugreport.java.com/bugreport/
[INFO] [echoproperties] java.io.tmpdir=/tmp
[INFO] [echoproperties] java.version=11.0.16.1
[INFO] [echoproperties] user.dir=/git/java-tutorial
[INFO] [echoproperties] os.arch=amd64
[INFO] [echoproperties] maven.multiModuleProjectDirectory=/git/java-tutorial
[INFO] [echoproperties] git.commit.id.abbrev=ff3ab46
[INFO] [echoproperties] java.vm.specification.name=Java Virtual Machine Specification
[INFO] [echoproperties] java.awt.printerjob=sun.print.PSPrinterJob
[INFO] [echoproperties] sun.os.patch.level=unknown
[INFO] [echoproperties] ant.version=Apache Ant(TM) version 1.10.12 compiled on October 13 2021
[INFO] [echoproperties] maven.compiler.target=11
[INFO] [echoproperties] java.library.path=/usr/java/packages/lib\:/usr/lib64\:/lib64\:/lib\:/usr/lib
[INFO] [echoproperties] project.build.sourceDirectory=/git/java-tutorial/common/src/main/java
[INFO] [echoproperties] java.vm.info=mixed mode
[INFO] [echoproperties] java.vendor=Oracle Corporation
[INFO] [echoproperties] java.vm.version=11.0.16.1+1-LTS-1
[INFO] [echoproperties] classworlds.conf=/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1/bin/m2.conf
[INFO] [echoproperties] sun.io.unicode.encoding=UnicodeLittle
[INFO] [echoproperties] library.jansi.path=/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1/lib/jansi-native
[INFO] [echoproperties] maven.project.dependencies.versions=4.11\:1.3\:
[INFO] [echoproperties] java.class.version=55.0
[INFO] [echoproperties] junit\:junit\:jar=/home/dave/.m2/repository/junit/junit/4.11/junit-4.11.jar
[INFO] [echoproperties] ant.project.default-target=main
[WARNING] [echo] compile classpath: /git/java-tutorial/common/target/classes
[WARNING] [echo] runtime classpath: /git/java-tutorial/common/target/classes
[WARNING] [echo] test classpath: /git/java-tutorial/common/target/test-classes:/git/java-tutorial/common/target/classes:/home/dave/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/dave/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[WARNING] [echo] plugin classpath: /home/dave/.m2/repository/org/apache/maven/plugins/maven-antrun-plugin/3.1.0/maven-antrun-plugin-3.1.0.jar:/home/dave/.m2/repository/org/codehaus/plexus/plexus-utils/3.4.1/plexus-utils-3.4.1.jar:/home/dave/.m2/repository/org/apache/ant/ant/1.10.12/ant-1.10.12.jar:/home/dave/.m2/repository/org/apache/ant/ant-launcher/1.10.12/ant-launcher-1.10.12.jar

Maven assembly plugin

$
0
0

 HOWTO

Project input 

  • Java sources
  • resources files
  • 3rd party libraries for compilation only

Project output 

  • packaged JARs
  • packaged EARs
  • packaged WARs
  • config files
  • 3rd party libraries required for runtime
  • complete TAR file delivering the application

Sample code

 ear

<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<!-- configuration elements goes here -->
</configuration>
</plugin>

 war

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>

assembly

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.1 https://maven.apache.org/xsd/assembly-2.1.1.xsd">
<id/>
<formats/>
<includeBaseDirectory/>
<baseDirectory/>
<includeSiteDirectory/>
<containerDescriptorHandlers>
<containerDescriptorHandler>
<handlerName/>
<configuration/>
</containerDescriptorHandler>
</containerDescriptorHandlers>
<moduleSets>
<moduleSet>
<useAllReactorProjects/>
<includeSubModules/>
<includes/>
<excludes/>
<sources>
<useDefaultExcludes/>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<fileSets>
<fileSet>
<useDefaultExcludes/>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<directory/>
<lineEnding/>
<filtered/>
<nonFilteredFileExtensions/>
</fileSet>
</fileSets>
<includeModuleDirectory/>
<excludeSubModuleDirectories/>
<outputDirectoryMapping/>
</sources>
<binaries>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<attachmentClassifier/>
<includeDependencies/>
<dependencySets>
<dependencySet>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<useStrictFiltering/>
<outputFileNameMapping/>
<unpack/>
<unpackOptions>
<includes/>
<excludes/>
<filtered/>
<nonFilteredFileExtensions/>
<lineEnding/>
<useDefaultExcludes/>
<encoding/>
</unpackOptions>
<scope/>
<useProjectArtifact/>
<useProjectAttachments/>
<useTransitiveDependencies/>
<useTransitiveFiltering/>
</dependencySet>
</dependencySets>
<unpack/>
<unpackOptions>
<includes/>
<excludes/>
<filtered/>
<nonFilteredFileExtensions/>
<lineEnding/>
<useDefaultExcludes/>
<encoding/>
</unpackOptions>
<outputFileNameMapping/>
</binaries>
</moduleSet>
</moduleSets>
<fileSets>
<fileSet>
<useDefaultExcludes/>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<directory/>
<lineEnding/>
<filtered/>
<nonFilteredFileExtensions/>
</fileSet>
</fileSets>
<files>
<file>
<source/>
<sources/>
<outputDirectory/>
<destName/>
<fileMode/>
<lineEnding/>
<filtered/>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<useStrictFiltering/>
<outputFileNameMapping/>
<unpack/>
<unpackOptions>
<includes/>
<excludes/>
<filtered/>
<nonFilteredFileExtensions/>
<lineEnding/>
<useDefaultExcludes/>
<encoding/>
</unpackOptions>
<scope/>
<useProjectArtifact/>
<useProjectAttachments/>
<useTransitiveDependencies/>
<useTransitiveFiltering/>
</dependencySet>
</dependencySets>
<repositories>
<repository>
<outputDirectory/>
<includes/>
<excludes/>
<fileMode/>
<directoryMode/>
<includeMetadata/>
<groupVersionAlignments>
<groupVersionAlignment>
<id/>
<version/>
<excludes/>
</groupVersionAlignment>
</groupVersionAlignments>
<scope/>
</repository>
</repositories>
<componentDescriptors/>
</assembly>

XSD schema for list of objects using ComplexType

$
0
0

 HOWTO

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:foo="foo.schema.myproject"
targetNamespace="foo.schema.myproject" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element name="DaveObjectList" type="foo:DaveObjectListType">
<xs:annotation>
<xs:documentation>ROOT: DaveObjectList</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="DaveObject" type="foo:DaveObjectType">
<xs:annotation>
<xs:documentation>Dave Object Type</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="DaveObjectType">
<xs:attribute name="newDaveObject" type="xs:string" use="required"/>
<xs:attribute name="timestamp" type="xs:dateTime" use="required"/>
</xs:complexType>
<xs:complexType name="DaveObjectListType">
<xs:annotation>
<xs:documentation>List of type DaveObjectType</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element ref="foo:DaveObject" minOccurs="0" maxOccurs="9999"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Generated XML document

 Using https://www.liquid-technologies.com/online-xsd-to-xml-converter

<!--Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com)-->
<daveobjectlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="foo.schema.myproject" xsi:schemalocation="foo.schema.myproject schema.xsd">
<daveobject newdaveobject="string" timestamp="2005-09-03T21:00:34.28">
</daveobject>
<daveobject newdaveobject="string" timestamp="2016-10-14T06:28:07.37">
</daveobject></daveobjectlist>
Viewing all 181 articles
Browse latest View live