Error:- Cannot index into a null array while installing java - java

I am trying to install java using powershell Invoke-WebRequest command on packer instance however, I am getting below error;
Cannot index into a null array.
At line:1 char:94
+ ... content | %{[regex]::matches($_, '(?:<a title="Download Java software ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Command;
[Net.ServicePointManager]::SecurityProtocol = "tls12"
$URL = (Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | %{[regex]::matches($_, '(?:<a title="Download Java software for Windows .64-bit." href=")(.*)(?:">)').Groups[1].Value}
Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL
Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
Few weeks ago I was able to run it successfully but since yesterday getting the above error.
Any advise?
Thanks.

This happens, as there is no such as string as Download Java software for Windows on the web page. Since the regex doesn't match anything, Groups member doesn't exist and you'll get an error about trying to index into a non-existing member.
Either use a web browser's View Source command, or save the content on a text file and view it with Notepad like so,
$cc = (Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content
Set-Content -Path c:\temp\javapage.txt -Value $cc
notepad c:\temp\javapage.txt
The page loads a bunch of Javascript that generates the actual page seen on a browser.

Related

Get specific java version with powershell

I have some issues with getting the java version out as a string.
In a batch script I have done it like this:
for /f tokens^=2-5^ delims^=.-_^" %%j in ('%EXTRACTPATH%\Java\jdk_extract\bin\java -fullversion 2^>^&1') do set "JAVAVER=%%j.%%k.%%l_%%m"
The output is: 1.8.0_121
Now I want to do this for PowerShell, but my output is: 1.8.0_12, I miss one "1" in the end Now I have tried it with trim and split but nothing gives me the right output can someone help me out?
This is what I've got so var with PowerShell
$javaVersion = (& $extractPath\Java\jdk_extract\bin\java.exe -fullversion 2>&1)
$javaVersion = "$javaVersion".Trim("java full version """).TrimEnd("-b13")
The full output is: java full version "1.8.0_121-b13"
TrimEnd() works a little different, than you might expect:
'1.8.0_191-b12'.TrimEnd('-b12')
results in: 1.8.0_19 and so does:
'1.8.0_191-b12'.TrimEnd('1-b2')
The reason is, that TrimEnd() removes a trailing set of characters, not a substring. So .TrimEnd('-b12') means: remove all occurrences of any character of the set '-b12' from the end of the string. And that includes the last '1' before the '-'.
A better solution in your case would be -replace:
'java full version "1.8.0_191-b12"' -replace 'java full version "(.+)-b\d+"','$1'
Use a regular expression for matching and extracting the version number:
$javaVersion = if (& java -fullversion 2>&1) -match '\d+\.\d+\.\d+_\d+') {
$matches[0]
}
or
$javaVersion = (& java -fullversion 2>&1 | Select-String '\d+\.\d+\.\d+_\d+').Matches[0].Groups[0].Value

JMeter scripts stop working, leaking memory, OutOfSpace Java

After last Thursday (can be linked to Windows OS (10 v 1803, OS Build 17134.165) updates) all my JMeter scripts stopped work. I first noticed when all scripts that run in Non GUI mode failed with
Uncaught Exception java.lang.OutOfMemoryError: Java heap space. See log file for details.
I started to test with GUI mode and the log shows these:
WARN c.h.c.r.e.LoggingCSSParseErrorHandler: Browser compliant mode skipped CSS from [1:24125] starting at token 'data' until [1:24143] to token ';' (based on com.helger.css.parser.ParseException: Encountered unexpected token: ":" ":"
at line 1, column 24129.
Was expecting one of:
")" "+" "-" "/" "=" "[" "and" "expression(" "from" "inherit" "not" "only" "or" "to" <ANGLE_DEG> <ANGLE_GRAD> <ANGLE_RAD> <ANGLE_TURN> <CH> <COMMA> <DPCM> <DPI> <DPPX> <EM> <EX> <FR> <FREQ_HZ> <FREQ_KHZ> <FUNCTION> <FUNCTION_CALC> <HASH> <IDENT> <LENGTH_CM> <LENGTH_IN>
<LENGTH_MM> <LENGTH_PC> <LENGTH_PT> <LENGTH_Q> <NUMBER>
<PERCENTAGE>
<PX> <REM> <S> <STRING1> <STRING2> <TIME_MS> <TIME_S> <URANGE> <URL> <VH> <VMAX> <VMIN> <VW>)
I see it on three machines: my local desktop, automation VM on perimeter, and at AWS.
I have:
set HEAP=-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m
I also set:
css.parser.ignore_all_css_errors=true
I also tested that it happens with JMter 4.0 and 3.3. Java 1.8.0_152
First check:
You're not running in GUI mode
You're following best-practices:
https://www.ubik-ingenierie.com/blog/jmeter_performance_tuning_tips/
http://jmeter.apache.org/usermanual/best-practices.html
But if issue persists, add to command line:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=
Then share using some sharing solution the generated hprof, and if possible your test plan.
I found the problem. It looks as there are several. In my jmx plan I was loading html pages. (We have a Single Web App architecture). Now after dev changed index.html I needed to disable html pages otherwise it blows.
My Test Plans (jmx) started to fail after dev changed index.html. It works correctly from UI perspective and from Selenium scripts. The change looks minor. They moved base tag from outside to inside script tag.
Before:
<base href="/ui/">
<script>
//var HOST = 'http://localhost/';
//var HOST = 'https://ooo.credifi.com/core/';
var HOST = 'https://oo2.credifi.com/core/';
var BASE = '/ui';
</script>
After:
<script>
var isLocalhost = document.location.hostname == 'localhost';
var BASE = isLocalhost ? '' : '/ui';
var HREF = isLocalhost ? '' : 'ui/';
document.write('<base href="/' + HREF + '" />');
</script>

NASHORN $EXEC issue with sed

I am trying to execute below command with NASHORN, to pull out a section of log -
$EXEC("sed '1,/Token to find:/d;/Another token to find:/,$d' /path/to/log/file.log")
But it ends with -
Exit Code:1, Error Msg::sed: -e expression #1, char 1: unknown
command: `''
Trying the same on Linux command prompt,
below (with single quote ') it is able to pull out the log section -
sed '1,/Token to find:/d;/Another token to find:/,$d' /path/to/log/file.log
On the other hand changing the quotes (""), I get the same error -
sed "1,/Token to find:/d;/Another token to find:/,$d" /path/to/log/file.log
sed: -e expression #1, char 1: unknown command: `
Any idea what is the right way?
After trying different combinations with sed " / ' etc. - it looks like due to multiple scripting expressions (JavaScript/Linux Shell Script & sed command itself!) i am getting into this trouble.
As a workaround i have moved expression into a text file and provided
sed its location -
sed --file=/sed/expression/file /path/to/log/file.log
or
$EXEC("sed --file=/sed/expression/file /path/to/log/file.log");
var output=$OUT
var exitErrorMsg="Exit Code:" + $EXIT + ", Error Msg::" + $ERR
It now works like charm!

Code Signing JavaFX Executable with VBScript, the SignTool errors with Access Denied

Alright so I've finally figured out how to go about code-signing the executable created by the JavaFX Bundler BEFORE (I hope) it is placed by the INNO script into a setup file : There's just one problem :
I've broken myself into pieces trying to resolve this stupid problem but the Access Denied error keeps popping up. This is the VBScript I'm using to try and make this work.
Initially I thought it was a permission error but as I was able to successfully call the script elevated, and still got this error, I can only assume I am mistaken. So...
Can someone please tell me what it is I am doing wrong here?
<?xml version = "1.0" ?>
<package>
<job id="CodeSign">
<script language = "VBScript">
<![CDATA[
WScript.Echo "Setting bElevate to False. . ."
bElevate = false
If WScript.Arguments.Count > 0 Then
WScript.Echo "Arguments.Count > 0"
If WScript.Arguments(WScript.Arguments.Count-1) <> "|" Then
WScript.Echo "Arg N - 1 != ""|"" . . ."
bElevate = true
End If
End If
If bElevate Or WScript.Arguments.Count = 0 Then
WScript.Echo "Elevating . . ."
ElevateUAC
End If
Dim Shell
Set Shell = WScript.CreateObject("WScript.Shell")
Shell.Run "C:\Sign.bat ""Registration Test\Registration Test.exe""", 1, True
Set Shell = Nothing
Sub ElevateUAC
sParams = "|"
If WScript.Arguments.Count > 0 Then
For I = WScript.Arguments.Count - 1 to 0 Step -1
SParams = " " & WScript.Arugments(I) & sParams
Next
End If
Dim objShell
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ """ & sParams & """", "", "runas", 1
WScript.Echo "Elevated . . ."
WScript.Quit
End Sub
]]>
</script>
</job>
</package>
Okay so I found it. This is pretty painful because there's (if I'm using this term in the correct context) "race conditions" here in that if the code signing doesn't finish before you start running the process again, it fails because it can't do anything with the .exe because it's being used by another process.
Turns out as long as your IDE is running in Admin (for Windows anyway) there's no need to elevate your script either.
Anyay, my problem was that the file was being set as Read-Only. VERY annoying but fortunately VBScript allows for you to change a files attributes so it was just a matter of doing that before trying to code-sign it :
<?xml version = "1.0" ?>
<package>
<job id="CodeSign">
<script language = "VBScript">
<![CDATA[
'Set File as Normal. . .
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("<Relative Path>\<File.exe>")
objFile.Attributes = 0
Dim Shell
Set Shell = WScript.CreateObject("WScript.Shell")
Shell.Run "<Code Sign> ""<Relative Path>\<File.exe>""", 1, True
Set Shell = Nothing
Set objFSO = Nothing
Set objFile = Nothing
]]>
</script>
</job>
</package>
So now, finally, at LONG LAST we have a complete and viable answer to this, evidently very esoteric question that no one but myself has dealt with (or is a very closely guarded secret, I'm not sure which) : How do you code-sign the executable created by a JavaFX bundle before it gets stored?
Create a WSF file with either JavaScript or VBScript (your
preference)
Add the directory in which the file is being stored to the Class Path (for NetBeans you go to Tools -> Options -> Java Tab, select Add Directory next to Class Path, browse to the directory, and add it).
In your WSF file, in the Script section, get the file object and set its attributes to normal (0).
Then Shell.Run your preferred method of code signing applications. 1 is for showing the Code Sign window, True is to make the VBScript wait until it's finished to hopefully avoid a race condition.
The .exe will ALWAYS be stored one directory up from the WSF script file so the relative path is always going to be <FILENAME>\<FILENAME.exe>.
I really, REALLY hope this saves someone a LOT of grief some day...

Autoconf test for JNI include dir

I'm working on a configuration script for a JNI wrapper. One of the configuration parameters is the path to jni.h. What's a good quick-and-dirty Autoconf test for whether this parameter is set correctly for C++ compilation? You can assume you're running on Linux and g++ is available.
Alternatively, is there a way to get javah (or a supporting tool) to give me this path directly?
Then there is the easy way: http://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html
Sometimes it is best to just use the standard recipies.
Checking for headers is easy; just use AC_CHECK_HEADER. If it's in a weird place (i.e., one the compiler doesn't know about), it's entirely reasonable to expect users to set CPPFLAGS.
The hard part is actually locating libjvm. You typically don't want to link with this; but you may want to default to a location to dlopen it from if JAVA_HOME is not set at run time.
But I don't have a better solution than requiring that JAVA_HOME be set at configure time. There's just too much variation in how this stuff is deployed across various OSes (even just Linux distributions). This is what I do:
AC_CHECK_HEADER([jni.h], [have_jni=yes])
AC_ARG_VAR([JAVA_HOME], [Java Runtime Environment (JRE) location])
AC_ARG_ENABLE([java-feature],
[AC_HELP_STRING([--disable-java-feature],
[disable Java feature])])
case $target_cpu in
x86_64) JVM_ARCH=amd64 ;;
i?86) JVM_ARCH=i386 ;;
*) JVM_ARCH=$target_cpu ;;
esac
AC_SUBST([JVM_ARCH])
AS_IF([test X$enable_java_feature != Xno],
[AS_IF([test X$have_jni != Xyes],
[AC_MSG_FAILURE([The Java Native Interface is required for Java feature.])])
AS_IF([test -z "$JAVA_HOME"],
[AC_MSG_WARN([JAVA_HOME has not been set. JAVA_HOME must be set at run time to locate libjvm.])],
[save_LDFLAGS=$LDFLAGS
LDFLAGS="-L$JAVA_HOME/lib/$JVM_ARCH/client -L$JAVA_HOME/lib/$JVM_ARCH/server $LDFLAGS"
AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [LIBS=$LIBS],
[AC_MSG_WARN([no libjvm found at JAVA_HOME])])
LDFLAGS=$save_LDFLAGS
])])
FYI - the patch below against the latest ax_jni_include_dir.m4 works for me on Macos 11.1.
--- a/m4/ax_jni_include_dir.m4
+++ b/m4/ax_jni_include_dir.m4
## -73,13 +73,19 ## fi
case "$host_os" in
darwin*) # Apple Java headers are inside the Xcode bundle.
- macos_version=$(sw_vers -productVersion | sed -n -e 's/^#<:#0-9#:>#
*.\(#<:#0-9#:>#*\).#<:#0-9#:>#*/\1/p')
- if #<:# "$macos_version" -gt "7" #:>#; then
- _JTOPDIR="$(xcrun --show-sdk-path)/System/Library/Frameworks/JavaVM.framework"
- _JINC="$_JTOPDIR/Headers"
+ major_macos_version=$(sw_vers -productVersion | sed -n -e 's/^\(#<:#0-9#:>#*\).#<:#0-9#:>#*.#<:#0-9#:>#*/\1/p')
+ if #<:# "$major_macos_version" -gt "10" #:>#; then
+ _JTOPDIR="$(/usr/libexec/java_home)"
+ _JINC="$_JTOPDIR/include"
else
- _JTOPDIR="/System/Library/Frameworks/JavaVM.framework"
- _JINC="$_JTOPDIR/Headers"
+ macos_version=$(sw_vers -productVersion | sed -n -e 's/^#<:#0-9#:>#*.\(#<:#0-9#:>#*\).#<:#0-9#:>#*/\1/p')
+ if #<:# "$macos_version" -gt "7" #:>#; then
+ _JTOPDIR="$(xcrun --show-sdk-path)/System/Library/Frameworks/JavaVM.framework"
+ _JINC="$_JTOPDIR/Headers"
+ else
+ _JTOPDIR="/System/Library/Frameworks/JavaVM.framework"
+ _JINC="$_JTOPDIR/Headers"
+ fi
fi
;;
*) _JINC="$_JTOPDIR/include";;

Categories

Resources