You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用D96AInterchangeFactory转换EDI遇Smooks报错求助(Java 8)

Fixing the NoSuchMethodError When Using D96AInterchangeFactory with Java 8

Hey, let's work through this issue you're hitting with EDIFACT/D96A parsing. That NoSuchMethodError tied to sun.misc.Unsafe.defineClass is a common compatibility hiccup between the libraries you're using and Java 8. Here's what's going on and how to fix it:

What's Causing the Error?

Even though you added MVEL2 2.2.0.Final, that version has a mismatch with Java 8's implementation of sun.misc.Unsafe. The method signature for defineClass changed in Java 8, and the older MVEL version is still calling the outdated variant. On top of that, you might be using a version of Smooks (the underlying library for D96AInterchangeFactory) that isn't fully tuned for Java 8.

Step-by-Step Fixes

1. Upgrade MVEL2 to a Java 8-Compatible Version

MVEL2 version 2.4.0.Final and above fixes the sun.misc.Unsafe compatibility issue. Dump the 2.2.0.Final version and use a newer stable release.

For Maven, update your dependency:

<dependency>
    <groupId>org.mvel</groupId>
    <artifactId>mvel2</artifactId>
    <version>2.4.12.Final</version> <!-- Latest stable as of now, any 2.4.x+ works -->
</dependency>

For Gradle:

implementation 'org.mvel:mvel2:2.4.12.Final'

2. Ensure Smooks EDI Libraries Are Java 8-Friendly

Make sure your Smooks UN/EDIFACT dependencies are at version 1.7.5 or higher—this version added proper Java 8 support. Here's how to set that up in Maven:

<dependency>
    <groupId>org.milyn</groupId>
    <artifactId>milyn-smooks-edi</artifactId>
    <version>1.7.5</version>
</dependency>
<dependency>
    <groupId>org.milyn</groupId>
    <artifactId>milyn-smooks-edifact</artifactId>
    <version>1.7.5</version>
</dependency>

3. Clean Up Dependency Conflicts

It's possible another dependency in your project is pulling in an older MVEL or Smooks version behind the scenes. Use Maven's dependency tree to check for conflicts:

mvn dependency:tree | grep mvel

If you spot an unwanted old version, exclude it from the parent dependency. For example:

<dependency>
    <!-- Replace with the conflicting dependency in your project -->
    <groupId>com.example</groupId>
    <artifactId>some-dependency</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.mvel</groupId>
            <artifactId>mvel2</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Test the Fix

Once you've updated your dependencies and cleared conflicts, re-run your code:

D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(ediContent.getBytes());
UNEdifactInterchange interchange = factory.fromUNEdifact(byteArrayInputStream);

This should resolve the error and let you parse your EDIFACT content successfully.

内容的提问来源于stack exchange,提问作者Sohaib Jamal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:33:43