1
votes

use code like the following to generate a class Greeting.

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/greeting/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 "!"))

these code are from http://www.coderanch.com/t/601586/clojure/Calling-Clojure-Java-code. can be called from a java class.

now compile to jar by

  lein uberjar

and import the standalone jar to WSO2 AS server, and got the following error

Error: java.lang.ExceptionInInitializerError at clojure.lang.Namespace. (Namespace.java:34) at clojure.lang.Namespace.findOrCreate(Namespace.java:176) at clojure.lang.Var.internPrivate(Var.java:151) at Greeting.(Unknown Source) 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 org.apache.axis2.deployment.util.Utils.fillAxisService(Utils.java:453) at org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:397) at org.apache.axis2.deployment.ServiceGroupBuilder.populateServiceGroup(ServiceGroupBuilder.java:101) at org.apache.axis2.deployment.repository.util.ArchiveReader.buildServiceGroup(ArchiveReader.java:109) at org.apache.axis2.deployment.repository.util.ArchiveReader.processServiceGroup(ArchiveReader.java:143) at org.apache.axis2.deployment.ServiceDeployer.deploy(ServiceDeployer.java:82) at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136) at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:807) at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144) at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:377) at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254) at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:371) at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:59) at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:67) at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.runAxisDeployment(CarbonDeploymentSchedulerTask.java:79) at org.wso2.carbon.core.deployment.CarbonDeploymentSchedulerTask.run(CarbonDeploymentSchedulerTask.java:124) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath. at clojure.lang.RT.load(RT.java:449) at clojure.lang.RT.load(RT.java:412) at clojure.lang.RT.doInit(RT.java:454) at clojure.lang.RT.(RT.java:330) ... 30 more

Is there something I missed? or how to get rid of it?

1
I found it said "Could not locate clojure/core__init.class or clojure/core.clj on classpath", but the two files are both in the standalone jar file.mxx
how did you import the jar to the wso2as?Thusitha Thilina Dayaratne
In WSO2AS management console, Main->Service->Add->Jar Service, and then follow the instructions, select the standalone jar file to upload, next, select the Greeting class, then next, only select greet method, and finish.mxx

1 Answers

0
votes

For Axis2 use separate Class Loader for each service, and Clojure Class Loader use context class loader by default, so when the jar file is loading, and the Clojue object in AOT-class will be loaded by Clojure class loader, and the Clojure class loader, the context class loader, do not have information about the jar's path, and so core__init.class could not be found.

to fix it, by using the axis2's costum deployer, overload the depoly method, and setting the context class loader the same as the service class loader.

this answer give much help to me. and some other reference could give a hint.thanks all!