Swathi
Swathi

Reputation: 33

java.lang.IllegalAccessError while ant build in SAP Hybris/Commerce version 2105

I am new to Hybris and trying to setup the Hybris latest version, I am trying to build it using ant clean all and getting the below error. I am using SAP Machine JDK 17 and also set it's path in Environment variables. Please help how to solve this!

** Java version **
C:\CXCOMM210500P_5-70005661\hybris\bin\platform>java -version
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."
openjdk version "17.0.1" 2021-10-19 LTS
OpenJDK Runtime Environment SapMachine (build 17.0.1+12-LTS)
OpenJDK 64-Bit Server VM SapMachine (build 17.0.1+12-LTS, mixed mode, sharing)

** Error logs **

C:\CXCOMM210500P_5-70005661\hybris\bin\platform\resources\ant\mavenTasks.xml:201: java.lang.IllegalAccessError: class com.oopsconsultancy.xmltask.jdk15.XPathAnalyser15 (in unnamed module @0x2f9f7dcf) cannot access class com.sun.org.apache.xpath.internal.XPathAPI (in module java.xml) because module java.xml does not export com.sun.org.apache.xpath.internal to unnamed module @0x2f9f7dcf
        at com.oopsconsultancy.xmltask.jdk15.XPathAnalyser15.analyse(XPathAnalyser15.java:28)
        at com.oopsconsultancy.xmltask.XmlReplace.apply(XmlReplace.java:72)
        at com.oopsconsultancy.xmltask.XmlReplacement.apply(XmlReplacement.java:61)
        at com.oopsconsultancy.xmltask.ant.XmlTask.processDoc(XmlTask.java:692)
        at com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:661)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
        at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     

Upvotes: 3

Views: 12301

Answers (10)

srihitha
srihitha

Reputation: 489

There would be two possible reasons.

  1. Uncompatible Java version
  2. not setting up ant environment before executing ant clean all command.

Executing setantenv.bat before executing ant clean all command solved error in my case.

Upvotes: 0

Sarita Jaiswal
Sarita Jaiswal

Reputation: 1

The error is related to xmltask library. If you are using jdk17, try to use latest version of xmltask from here.

Upvotes: 0

eminyagiz42
eminyagiz42

Reputation: 1

I faced the same issue while generating a new extension.

My Environment Details: SAP Commerce Version: 2205.9 , SapMachine: Java 17.0.9

I investigated my ANT_OPTS in the following path.

...\hybris\bin\platform\setantenv.sh

It already has this code below:

export ANT_OPTS="-Xmx2g -Dfile.encoding=UTF-8 \
--add-exports java.xml/com.sun.org.apache.xpath.internal=ALL-UNNAMED \
--add-exports java.xml/com.sun.org.apache.xpath.internal.objects=ALL-UNNAMED"

I solved it by running setantenv.bat at the beginning on Command Prompt. My build was failing since I was using Powershell and “ANT_HOME” was defined globally from Environment Variables in Windows.

Upvotes: 0

Pines Tran
Pines Tran

Reputation: 679

We can use any JDK (from Oracle or SAP). This seems that the ANT was not set properly. In the platform folder, just executed:

\hybris\bin\platform> setantenv.bat

Upvotes: 0

Stephen
Stephen

Reputation: 2187

I came across this error in my Azure pipeline build after upgrading from SAP Commerce 2105 to 2211:

java.lang.IllegalAccessError: class 
com.oopsconsultancy.xmltask.jdk15.XPathAnalyser15 (in unnamed module 
@0x4b5a078a) cannot access class com.sun.org.apache.xpath.internal.XPathAPI (in 
module java.xml) 
because module java.xml does not export com.sun.org.apache.xpath.internal to 
unnamed module @0x4b5a078a

The pipeline build was getting that error when trying to run the following scriptlet from my azure-pipelines.yml file:

- task: Ant@1
  inputs:
    buildFile: '$(workspace)/hybris/bin/platform'
    options: 'addoninstall -DaddonStorefront.yacceleratorstorefront=mystorefront -Daddonnames="b2bacceleratoraddon,commerceorgaddon,assistedservicestorefront,smarteditaddon,sapcoreaddon,b2bpunchoutaddon,myraddon,b2boccaddon"'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.17'
    publishJUnitResults: false
  displayName: ANT - install add-ons

In upgrading from 2105 to 2211, we upgraded java from 11 to 17. The first problem that I had to get past was using the correct the java version. I had to include the following scriptlet towards the beginning my azure-pipelines.yml file to make sure I was using java 17:

- task: JavaToolInstaller@0
  inputs:
    versionSpec: '17'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'
  displayName: 'Installing Java 17'

Before I did this, I found that azure pipelines was using the operating system installed version of java, which was version 11. After I added the above scriptlet, that took care of that problem, but I was still getting the IllegalAccessError.

I played around with the ANT_OPTS variable with the "--add-opens java.xml/com.sun.org.apache.xpath.internal=ALL-UNNAMED" option, but that didn't fix anything for me. While working with the environment variables, I discovered that the version of ant being used was the operating system installed version and not the version included with SAP Commerce. I had been running the setantenv.sh command in a separate scriptlet, thinking that this would properly set the ANT_HOME variable to point to the correct location, and I guess this was being lost once that scriptlet finished and the next one was being run.

What fixed the problem for me was not using the 'ANT - install add-ons' scriptlet mentioned above in lieu of replacing it with a 'script' type scriptlet where I run the baseline configuration, addoninstall, and clean all commands in the same scriptlet:

- script: |
    cd $(workspace)/hybris/bin/platform
    . ./setantenv.sh

    echo "JAVA_HOME = $JAVA_HOME"
    echo "ANT_HOME = $ANT_HOME"
    echo "ANT_OPTS = $ANT_OPTS"

    $(ANT_HOME)/bin/ant clean all -Dinput.template=develop

    /usr/bin/cp -r $(workspace)/hybris/bin/custom/core-customize/config/. $(workspace)/hybris/config
    rc=$?
    if [ x"$rc" != x"0" ]; then 
        exit -1
    fi

    $(ANT_HOME)/bin/ant addoninstall -DaddonStorefront.yacceleratorstorefront=graybarstorefront -Daddonnames="b2bacceleratoraddon,commerceorgaddon,assistedservicestorefront,smarteditaddon,sapcoreaddon,b2bpunchoutaddon,graybaraddon,b2boccaddon"
    rc=$?
    if [ x"$rc" != x"0" ]; then 
        exit -1
    fi

    $(ANT_HOME)/bin/ant clean all
    rc=$?
    if [ x"$rc" != x"0" ]; then 
        exit -1
    fi

  displayName: Running the ANT commands

Now the azure pipeline build is working correctly for me.

Upvotes: 1

Kashif Ibrahim
Kashif Ibrahim

Reputation: 183

You should be using the correct Java version, better use the SAPMachine instead of Java for no-nonsense compatibility issues: https://github.com/SAP/SapMachine

2105 requires Version 11, and 2205 needs 17

Also, add these exports to your setantenv:

export ANT_OPTS="-Xmx2g -Dfile.encoding=UTF-8 \
--add-exports java.xml/com.sun.org.apache.xpath.internal=ALL-UNNAMED \
--add-exports java.xml/com.sun.org.apache.xpath.internal.objects=ALL-UNNAMED"

Upvotes: 0

scrum
scrum

Reputation: 31

Unable to add a comment to original question. The solution proposed by @dmytrolysak worked for me. I had to add the option "--add-opens java.xml/com.sun.org.apache.xpath.internal=ALL-UNNAMED" in my setantenv.sh for ANT_OPTS.

This is for hybris version 2205 and Java version is sapMachine 17.x.

Upvotes: 3

quickshiftin
quickshiftin

Reputation: 69721

For Docker users make sure to use the appropriate sapmachine image based on your version of SAP Commerce, as mentioned by @mkysoft above.

Also note for newer versions (2205) you do need version 17.

Upvotes: 0

Timothy.Li
Timothy.Li

Reputation: 1051

SAP Machine JDK 17 is too high for SAP commerce cloud 2105.
Please use SAP Machine JDK 11 instead.
Here is SAP official guide for SAP commerce cloud installation.

enter image description here

Upvotes: 1

mkysoft
mkysoft

Reputation: 5758

You need to use SAP Machine 11.0 as JDK for version 2105. Full system requirements by versions are here.

Upvotes: 1

Related Questions