Running java utility via command in azure pipelines does not pass parameters - azure-devops

I have created an utility (java jar-file) to generate a file upon the building process. And placed it into /tools folder in my source code root folder.
In azure-pipelines I am using this approach to run this jar-file upon building the project (Xamarin project).
- task: CmdLine#2
inputs:
script: "java -jar $(build.SourcesDirectory)/tools/version2image.jar $(fullVersionText) $(androidVersionFileLocation)"
The task launched ok, but in the logs I get the following:
2020-08-17T14:48:45.4688112Z java -jar D:\a\1\s/tools/version2image.jar 1.0.0.123 'D:\a\1\s/XamarinProject/XamarinProject.Android/Resources/drawable/version.png'
2020-08-17T14:48:45.5231861Z ========================== Starting Command Output ===========================
2020-08-17T14:48:45.5731945Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\d5706f7c-43cd-4d50-8f17-98a6ae0a3391.cmd""
2020-08-17T14:48:46.8000947Z Version 2 Image Utility. version 1.0
2020-08-17T14:48:46.8001744Z
2020-08-17T14:48:46.8002367Z
2020-08-17T14:48:46.8003059Z Usage:
2020-08-17T14:48:46.8004115Z
2020-08-17T14:48:46.8004468Z java -jar version2image.jar version_string output_file_location
2020-08-17T14:48:46.8004769Z
2020-08-17T14:48:46.8005096Z Example:
2020-08-17T14:48:46.8005464Z
2020-08-17T14:48:46.8005739Z java -jar version2image.jar 1.0.0.121 c:/myproject/images/version.png
2020-08-17T14:48:46.8005961Z
2020-08-17T14:48:46.8507661Z ##[section]Finishing: CmdLine
In other words Azure does not pass parameters properly to the jar file. My application thinks that it launched without parameters.
But when I run this utility locally on my computer it works ok.
If it helps, in the java utility I get command line parameters like that:
final int correctParamsCount = 2;
if (args.length != correctParamsCount) {
System.out.println("Usage:\n\njava -jar version2image.jar <version_string> <output_file_location>\n");
System.out.println("Example:\n\njava -jar version2image.jar 1.0.0.121 c:/myproject/images/version.png\n");
System.exit(0);
}
final String versionNumber = args[0];
final String outputFilePath = args[1];
How can I fix this issue?

To resolve this issue (thanks to #riQQ) I should update AndroidVersionFileLocation variable, and remove single quote symbols from the path.
And add double quotes to the utility command call:
It should look like this:
script: 'java -jar $(build.SourcesDirectory)/tools/version2image.jar "$(fullVersionText)" "$(androidVersionFileLocation)"'
instead of this:
script: "java -jar $(build.SourcesDirectory)/tools/version2image.jar $(fullVersionText) $(androidVersionFileLocation)"

Related

Java utility unable to find and read its properties file

I have to execute a java utility (UTL.jar) through a shell script (mainUTL.sh). It utilizes a properties file (SetupUTL.properties).
The location of the files is as following -
/a/b/mainUTL.sh
/a/b/UTL.jar
/a/b/SetupUTL.properties
I have setup my CLASSPATH as following in the mainUTL.sh -
export CLASSPATH=$CLASSPATH:/a/b/SetupUTL.properties:/a/b/UTL.jar
I am executing the script from command prompt (Login shell is csh) as following -
sh mainUTL.sh <$ARG1> &
and the script mainUTL.sh has the following java execution command -
nohup $JAVA_HOME/bin/java -d64 UTL.jar <$ARG1>
Now when I am executing the shell script from location /a/b/ as following
/a/b$: sh mainUTL.sh <$ARG1> &
The utility is executing fine.
But when I am executing the shell script from any other location say /a/ as following
/a$: sh mainUTL.sh <$ARG1> &
The utility is unable to find its properties file. The utility has following piece of code -
private boolean initPropertiesAndLog()
{
String str1 = null;
String str2 = null;
InputStream localInputStream = ClassLoader.getSystemResourceAsStream("SetupUTL.properties");
if (localInputStream == null) {
System.out.println("Unable to read SetupUTL.properties.properties file.");
return false;
}
I am not at all aware of Java codes, so please tell me what wrong I am doing as to not able to execute the utility fine.
You should not use ClassLoader.getSystemResourceAsStream
Try this
this.getClass().getClassLoader().getResourceAsStream("your_prop_file")
if fails, try to add a "/":
this.getClass().getClassLoader().getResourceAsStream("/your_prop_file")

executing jarsigner command generates error: "Jarsigner is not recognized internal or external command"

I am trying to verify signature of apk uploaded on my site.
I am trying to execute
String command= "cmd /c jarsigner -verify -verbose -certs " +Filelocation;
Process proc = Runtime.getRuntime().exec(command);
BufferedReader reader=new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader reader1=new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String line=reader.readLine();
String line1=reader1.readLine();
line output is null and line1 output is"Jarsigner is not recognized internal external command".
I have checked java_home,java.home,java.class.path.
java_home is holding jdk path
java.home is holding jre path
java.class.path holds jboss server>deploy folder.
I am running this part of code on JBOSS Server.
Make sure Java JDK is set on the PATH. In my case put "D:\Java\jdk1.6.0_34\bin" into System Variable PATH.
Make sure the release key and the apk are in the same directory.
1 Make sure below Environment Variables are set:
Variable name: JAVA_HOME
Varaible value: C:\Program Files\Java\jre7 (example only; update path based on your Java library location)
Variable name: Path
Varaible value: %JAVA_HOME%\bin;
2 Make sure that jarsigner.exe file exists in your JAVA library ie.
C:\Program Files\Java\jre7\bin\jarsigner.exe

"Path must include project and resource name" in Eclim when executing some commands

I'm using Eclim to develop Java Application, whenever I run command :Validate in MacVim to validate Java Source, it raise exception message:
`java.lang.IllegalArgumentException: Path must include project and resource name: <Project>
while executing command (port: 9091): -editor vim -command java_src_update -p "<Project>" -f "src/mobile/railsvideos/LoginActivity.java" -v`
Any help is appreciated?

How do i run PMD on a command line in linux

I tried
$java -jar ../lib/pmd-5.0.0.jar /var/lib/jenkins/jobs/MYPROJECT/workspace/ xml
error:
Failed to load Main-Class manifest attribute from
../lib/pmd-5.0.0.jar
as per docs from PMD
i also tried:
$java -jar ../lib/pmd-5.0.0.jar /var/lib/jenkins/jobs/MYPROJECT/workspace/ xml java-basic,java-design -encoding UTF-8
Failed to load Main-Class manifest attribute from
../lib/pmd-5.0.0.jar
resolved it by using the following Syntax:
cd ../pmd/bin
./run.sh pmd /var/lib/jenkins/workspace/MYPROJECT/ xml java-basic,java-design -encoding UTF-8 | tee ../../MYPROJECT/pmd.xml
Where do you see that in the doc you linked to?
All of the examples I see on that page say to run java using the PMD class name rather than with the -jar flag. (Which is what I use when running PMD)
Which gives you something like:
java net.sourceforge.pmd.PMD /var/lib/jenkins/jobs/MYPROJECT/workspace/ xml rulesets/java/imports.xml

Hudson CLI, anyone got it to work?

I simply could not get it to work not matter what. The only thing it does is that it lists the help. that's all. Any help, example is appreciated. Thanks much.
I installed the Debian package (then the prerequisite package daemon to get it to finish installing), then got the jarfile from the warfile according to instructions, and it works for me:
jcomeau#intrepid:~$ java -jar /usr/local/bin/hudson-cli.jar -s http://localhost:8080/ version
2.0.1
jcomeau#intrepid:~$ java -jar /usr/local/bin/hudson-cli.jar -s http://localhost:8080/ list-changes
Argument "JOB" is required
java -jar hudson-cli.jar list-changes args...
Dumps the changelog for the specified build(s)
JOB : Name of the job to build
RANGE : Range of the build records to delete. 'N-M',
'N,M', or 'N'
-format [XML | CSV | PLAIN] : Controls how the output from this command is
printed.