首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用自定义模块运行应用程序时的NoClassDefFoundError

使用自定义模块运行应用程序时的NoClassDefFoundError
EN

Stack Overflow用户
提问于 2021-04-09 22:47:39
回答 1查看 192关注 0票数 0

我已经使用内部使用com.googlecode.json-simple的Mule SDK构建了一个Mule4模块。为了创建这个项目,我使用了https://docs.mulesoft.com/mule-sdk/1.1/getting-started中解释的Maven原型org.mule.extensions:mule-extensions-archetype-maven-plugin:1.2.0

我能够构建项目并将其包含在Anypoint Studio7.8中,并利用我的Mule应用程序中的操作,我可以在UI中配置它们,更新其属性,但无论何时我运行该应用程序都会使用java.lang.NoClassDefFoundError失败,因为它找不到库。

我应该做什么额外的配置,以确保库在运行时可用?

错误:

代码语言:javascript
复制
ERROR 2021-04-09 06:33:48,410 [WrapperListener_start_runner] org.mule.runtime.module.deployment.internal.DefaultArchiveDeployer: Failed to deploy artifact [project1]
org.mule.runtime.deployment.model.api.DeploymentException: Failed to deploy artifact [project1]
Caused by: java.lang.NoClassDefFoundError: com/google/gson/JsonObject
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_232]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_232]
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_232]
    at org.mule.runtime.module.extension.internal.util.IntrospectionUtils.lambda$getMethodsStream$14(IntrospectionUtils.java:923) ~[mule-module-extensions-support-4.3.0-20210119.jar:4.3.0-20210119]
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:269) ~[?:1.8.0_232]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[?:1.8.0_232]
    at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1556) ~[?:1.8.0_232]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[?:1.8.0_232]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[?:1.8.0_232]

模块的pom.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.mule.extension</groupId>
    <artifactId>mule-basic-extension</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <packaging>mule-extension</packaging>
    <name>My Extension</name> 

    <parent>
        <groupId>org.mule.extensions</groupId>
        <artifactId>mule-modules-parent</artifactId>
        <version>1.1.3</version>
    </parent>

    <dependencies>
        <dependency>
           <groupId>com.googlecode.json-simple</groupId>
           <artifactId>json-simple</artifactId>
           <version>1.1.1</version>
        </dependency>
     </dependencies>

</project>

编辑:操作类

代码语言:javascript
复制
public class MyOperations {
  Logger logger = LoggerFactory.getLogger(MyOperations.class);


  /**
   * Example of an operation that uses the configuration and a connection instance to perform some action.
   */
  @MediaType(value = ANY, strict = false)
  public String retrieveInfo(@Config MyConfiguration configuration, @Connection MyConnection connection){
    return "Using Configuration [" + configuration.getConfigId() + "] with Connection id [" + connection.getId() + "]";
  }

  /**
   * Example of a simple operation that receives a string parameter and returns a new string message that will be set on the payload.
   */
  @MediaType(value = ANY, strict = false)
  public String sayHi(String person) {
    return buildHelloMessage(person);
  }

  /**
   * Returns a JSON representation of the input
   */
  @Throws(ExecuteErrorsProvider.class)
  @MediaType(value = MediaType.APPLICATION_JSON, strict = false)
  public String parseInput(String record) {
    JsonObject jsonObject = new JsonObject();

    jsonObject.addProperty("key", record);

    return jsonObject.toString();
  }


  /**
   * Private Methods are not exposed as operations
   */
  private String buildHelloMessage(String person) {
    return "Hello " + person + "!!!";
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-10 20:14:05

事实证明,我在项目中使用的JSON库有一个问题。

我替换了这个依赖项

代码语言:javascript
复制
<dependency>
  <groupId>com.googlecode.json-simple</groupId>
  <artifactId>json-simple</artifactId>
  <version>1.1.1</version>
</dependency>

有了这个,我就能够创建返回JSON的操作

代码语言:javascript
复制
<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.8.6</version>
</dependency>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67023295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档