在加载到AXIS2时,在Clojure中生成的类得到java.lang.ExceptionInInitializerError

时间:2015-11-10 09:49:30

标签: clojure wso2 axis2

使用以下代码生成类问候语。

project.clj

   (defproject greeting "0.1.0-SNAPSHOT"
     :description "FIXME: write description"
     :url "http://example.com/FIXME"
     :license {:name "Eclipse Public License"
     :url "http://www.eclipse.org/legal/epl-v10.html"}
     :dependencies [[org.clojure/clojure "1.7.0"]]
     :aot [greeting.core]
    )

的src /问候/ core.clj

(ns greeting.core
  (:gen-class
   :name Greeting
   :init create
   :constructors {[String] []}
   :methods [(greet [String] String)] 
   :state data))

(defn -create
  "Construct instance with a String."
 [s]
 [[] ;; super class args
  s])

(defn -greet
 "Return greeting based on the constructed data."
  [this n]
  (str (.data this) " " n "!"))

这些代码来自http://www.coderanch.com/t/601586/clojure/Calling-Clojure-Java-code。可以从java类中调用。

现在通过

编译到jar
  lein uberjar

并将独立jar导入WSO2 AS服务器,并出现以下错误

错误:clojure.lang.Namespace中的java.lang.ExceptionInInitializerError。 (Namespace.java:34)at clojure.lang.Name.findOrCreate(Namespace.java:176)at clojure.lang.Var.internPrivate(Var.java:151)at Greeting。(Unknown Source)at at  java.lang.Class.forName0(Native Method)at    java.lang.Class.forName(Class.java:278)at    org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator。(DefaultSchemaGenerator.java:140)at at    org.apache.axis2.deployment.util.Utils.fillAxisService(Utils.java:453)at    org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:397)at at  org.apache.axis2.deployment.ServiceGroupBuilder.populateServiceGroup(ServiceGroupBuilder.java:101)at   org.apache.axis2.deployment.repository.util.ArchiveReader.buildServiceGroup(ArchiveReader.java:109)at at   org.apache.axis2.deployment.repository.util.ArchiveReader.processServiceGroup(ArchiveReader.java:143)at    org.apache.axis2.deployment.ServiceDeployer.deploy(ServiceDeployer.java:82)at at  org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)at at  org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807)at at  org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144)at  org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377)at at  org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254)at at  org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371)at at  或者.apache.axis。  org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67)at  org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:79)at at  org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:124)at at  java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)at at  java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 301(ScheduledThreadPoolExecutor.java:178)at at  java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)at at  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)at at  java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)at java.lang.Thread.run(Thread.java:745)引起:  java.io.FileNotFoundException:找不到类路径上的clojure / core__init.class或clojure / core.clj。在clojure.lang.RT.load(RT.java:449)at  clojure.lang.RT.load(RT.java:412)在clojure.lang.RT.doInit(RT.java:454)at  clojure.lang.RT。(RT.java:330)... 30多个

我错过了什么吗?或者如何摆脱它?

1 个答案:

答案 0 :(得分:0)

对于Axis2,为每个服务使用单独的Class Loader,而Clojure Class Loader默认使用上下文类加载器,因此当加载jar文件时,Alo-class中的Clojue对象将由Clojure类加载器加载,并且Clojure类加载器,上下文类加载器,没有关于jar路径的信息,因此无法找到core__init.class。

通过使用axis2的costum部署程序修复它,重载depoly方法, 并将上下文类加载器设置为与服务类加载器相同。

this answer给了我很多帮助。 有些other reference可能会给出一个提示。谢谢所有人!