Apache Commons SCXML - cannot find JexlContext

我与影子孤独终老i 提交于 2019-12-01 22:56:14

问题


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>

回答1:


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



回答2:


All SCXML dependency jars can be found here:

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



来源:https://stackoverflow.com/questions/8286760/apache-commons-scxml-cannot-find-jexlcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!