Java sample code fails to get batchUrl
Closed this issue · 4 comments
I am new to Azure Batch Service, I have followed the README of Java Samples and included the batch and storage details. everything is doubled checked and correct. But when I run, it fails with below error:
I baseUrl is returning as null when I did a syso, is it something todo with batchUri vs baseUrl? need help:
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalArgumentException: **Parameter baseUrl is required and cannot be null.**
at com.microsoft.azure.batch.auth.BatchSharedKeyCredentials.<init> (BatchSharedKeyCredentials.java:50)
at PoolAndResourceFile.main (PoolAndResourceFile.java:318)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
at java.lang.Thread.run (Thread.java:748)
Are you setting AZURE_BATCH_ENDPOINT? The error states that https://docs.microsoft.com/en-us/java/api/com.microsoft.azure.batch.auth.batchsharedkeycredentials?view=azure-java-stable is failing to be created due to
being nullI did set all the batch and storage account information. below are the "sample" keys how I did:
String batchAccount = System.getenv("batchaccountname");
String batchKey = System.getenv("PrimaryAccessKey");
String batchUri = System.getenv("https://xxxx.yyyy.batch.azure.com");
String storageAccountName = System.getenv("storageaccountname");
String storageAccountKey = System.getenv("Key1");
Note: All the above info I have taken from the batch account--> Keys section
This section of code gets environment variables for the keys provided in System.getenv(). Unless you are setting the environment variables in your system to be value=value it appears this is a misunderstanding of what environment variables are?
I figured it out (the env variables were already set). I restarted the machine and tried, it worked. Probably I should have opened a new command prompt and try it. Thank you so much for investing your time to debug this issue.