我在此thread中描述的同一主题上有一个上一个问题。我找到了使用maven-assembly-plugin的解决方案但是我遇到了以下问题。
示例代码。
1)以下课程
i) import clojure.java.api.Clojure; , ii) import clojure.lang.IFn;
2)将你的clojure编译成一个uberjar然后将它导入java 代码。
我选择了第二个选项,因为它更直接。
这是clojure代码
(ns com.test.app.service
(:gen-class
:name com.test.app.service
:main false
:methods [^{:static true} [returned [int] int]]))
(defn returned
[number]
(* 2 number))
(defn -returned
[number]
(returned number))
这是Java代码。
package com.s.profile;
import java.util.*;
import com.microsoft.azure.serverless.functions.annotation.*;
import com.microsoft.azure.serverless.functions.*;
import com.test.app.service;
/**
* Azure Functions with HTTP Trigger.
*/
public class Function {
/**
* This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/hello
* 2. curl {your host}/api/hello?name=HTTP%20Query
*/
@FunctionName("hello")
public HttpResponseMessage<String> hello(
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");
// Parse query parameter
String query = request.getQueryParameters().get("name");
String name = request.getBody().orElse(query);
if (name == null) {
return request.createResponse(400, "Please pass a name on the query string or in the request body");
} else {
service.returned(4);
context.getLogger().info("process data" );
return request.createResponse(200, "Hellos, " + name );
}
}
}
这是完整的堆栈跟踪
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
java.lang.ExceptionInInitializerError
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.Namespace.<init>(Namespace.java:34)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.Var.internPrivate(Var.java:151)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.test.app.service.<clinit>(Unknown Source)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.s.profile.Function.hello(Function.java:42)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.lang.reflect.Method.invoke(Method.java:483)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.broker.JavaMethodExecutor.execute(JavaMethodExecutor.java:59)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:40)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.handler.MessageHandler.handle(MessageHandler.java:43)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:84)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at com.microsoft.azure.webjobs.script.JavaWorkerClient$StreamingMessagePeer$$Lambda$10/293453555.run(Unknown Source)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:902)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1689)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1644)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath:
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.RT.load(RT.java:443)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.RT.load(RT.java:411)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.RT.doInit(RT.java:447)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
at clojure.lang.RT.<clinit>(RT.java:329)
info: Worker.Java.917bfefd-b67a-49b2-b77b-6848c52c3a98[0]
根据文档,我对该问题的信息如下。
表示静态初始化程序中发生意外异常。抛出ExceptionInInitializerError以指示在评估静态初始化程序或静态变量的初始化程序期间发生异常。
哪种静态方法在我的clojure代码中有问题?似乎不太可能,因为当我从一个更简单的&#34; hello world&#34;来自main函数的Java示例它返回正常,这让我相信我编译的clojure jar文件不是问题。那它源于哪里?是否有规则背后的天蓝色功能如何在内部工作,限制可以调用的内容?