Apache Commons SCXML - 找不到 JexlContext

发布于 2024-12-18 09:23:25 字数 4029 浏览 0 评论 0原文

我是 SCXML 新手,甚至无法启动最简单的应用程序。当我尝试启动它时,出现以下异常。但我在类路径上有该类的库 commons-scxml-0.9.jar 。有什么想法吗?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/jexl/JexlContext
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.apache.commons.scxml.env.AbstractStateMachine.<init>(AbstractStateMachine.java:103)
at main.StateMachineImpl.<init>(StateMachineImpl.java:8)
at main.Main.main(Main.java:6)

Caused by: java.lang.ClassNotFoundException: org.apache.commons.jexl.JexlContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 15 more

这是代码:

Main class

public class Main {
    public static void main(String[] args) {
        StateMachineImpl stateMachineImpl = new StateMachineImpl();
        stateMachineImpl.fireEvent(Event.START.getEvent());
        stateMachineImpl.fireEvent(Event.STOP.getEvent());
    }
}

Event

public enum Event {

    START("event.start"), STOP("event.stop");

    private String event;

    private Event(String event) {
        this.event = event;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

}

StateMachineImpl

public class StateMachineImpl extends AbstractStateMachine {

    public StateMachineImpl() {
        super(StateMachineImpl.class.getClassLoader().getResource("state-machine-cfg.xml"));
    }

    public void off() {
        System.out.println("StateMachine is OFF");
    }

    public void running() {
        System.out.println("StateMachine is RUNNING");
    }

}

state-machine-cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
    initialstate="off">

    <state id="off">
        <transition event="event.start" target="running" />
    </state>

    <state id="running">
        <transition event="event.stop" target="off" />
    </state>

</scxml>

编辑 - 解决方案: 我必须添加额外的依赖项(我认为它们会由 Maven 自动加载)。

pom.xml 依赖项

<dependency>
    <groupId>commons-scxml</groupId>
    <artifactId>commons-scxml</artifactId>
    <version>0.9</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>commons-jexl</groupId>
    <artifactId>commons-jexl</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>xalan</groupId>
    <artifactId>xalan</artifactId>
    <version>2.7.1</version>
</dependency>

I'm new to SCXML and I cannot start even the simplest application. When I try to start it I get the following exception. But I have the library commons-scxml-0.9.jar with that class on classpath. Any ideas?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/jexl/JexlContext
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.apache.commons.scxml.env.AbstractStateMachine.<init>(AbstractStateMachine.java:103)
at main.StateMachineImpl.<init>(StateMachineImpl.java:8)
at main.Main.main(Main.java:6)

Caused by: java.lang.ClassNotFoundException: org.apache.commons.jexl.JexlContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 15 more

Here is the code:

Main class

public class Main {
    public static void main(String[] args) {
        StateMachineImpl stateMachineImpl = new StateMachineImpl();
        stateMachineImpl.fireEvent(Event.START.getEvent());
        stateMachineImpl.fireEvent(Event.STOP.getEvent());
    }
}

Event

public enum Event {

    START("event.start"), STOP("event.stop");

    private String event;

    private Event(String event) {
        this.event = event;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

}

StateMachineImpl

public class StateMachineImpl extends AbstractStateMachine {

    public StateMachineImpl() {
        super(StateMachineImpl.class.getClassLoader().getResource("state-machine-cfg.xml"));
    }

    public void off() {
        System.out.println("StateMachine is OFF");
    }

    public void running() {
        System.out.println("StateMachine is RUNNING");
    }

}

state-machine-cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
    initialstate="off">

    <state id="off">
        <transition event="event.start" target="running" />
    </state>

    <state id="running">
        <transition event="event.stop" target="off" />
    </state>

</scxml>

EDIT - solution:
I have to add additional dependencies (I thought they would be loaded by Maven automatically).

pom.xml dependencies

<dependency>
    <groupId>commons-scxml</groupId>
    <artifactId>commons-scxml</artifactId>
    <version>0.9</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>commons-jexl</groupId>
    <artifactId>commons-jexl</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>xalan</groupId>
    <artifactId>xalan</artifactId>
    <version>2.7.1</version>
</dependency>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夢归不見 2024-12-25 09:23:25

添加 commons-jexl.jar 也到 CLASSPATH 中。根据项目 pom. xml 在 0.9 版本中,您还需要(不包括传递依赖项):

  • commons-logging
  • commons-digester
  • commons-beanutils
  • commons-el

Add commons-jexl.jar to the CLASSPATH as well. According to the project pom.xml in version 0.9 you will also need (excluding transitive depndencies):

  • commons-logging
  • commons-digester
  • commons-beanutils
  • commons-el
请叫√我孤独 2024-12-25 09:23:25

所有 SCXML 依赖项 jar 都可以在这里找到:

http://commons.apache.org/scxml/dependency。 html

All SCXML dependency jars can be found here:

http://commons.apache.org/scxml/dependencies.html

一页 2024-12-25 09:23:25

在问题提出近 12 年后我又遇到了同样的问题。答案不适用于当前版本的 common-scxml2。我找到了添加当前需要的 jexl3 版本的灵魂。

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-jexl3</artifactId>
    <version>3.3</version>
</dependency>

I got the same problem almost 12 years after the question. The answser are not working for the current version of common-scxml2. I found a soultion with adding the currently needed version of jexl3.

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-jexl3</artifactId>
    <version>3.3</version>
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文