问题描述
我正在尝试将Java类添加到我的适配器,如教程中所述。但是,我试图从CLI中做到这一点。
I am trying to add Java classes to my adapter as described in the tutorial Using Java in Adapters. However, I am trying to do that from the CLI.
当我这样做时:
- wl create WLProject
- cd WLProject
- wl add adapter
- 复制Java类(Calculator1 .java)到服务器/ java / com / worklight / customcode
- wl start
- wl create WLProject
- cd WLProject
- wl add adapter
- copy the Java class (Calculator1.java) to server/java/com/worklight/customcode
- wl start
构建过程失败并且没有创建war文件;
The build process fails and no war file is created;
当我这样做时:
- wl创建WLProject
- cd WLProject
- wl add adapter
- wl start
- 将Java类(Calculator1.java)复制到server / java / com / worklight / customcode
- wl build
- wl deploy
- wl invoke
- wl create WLProject
- cd WLProject
- wl add adapter
- wl start
- copy the Java class (Calculator1.java) to server/java/com/worklight/customcode
- wl build
- wl deploy
- wl invoke
调用失败。当我检查war文件时,还没有部署Calculator1.class。
The invocation fails. When I inspect the war file, the Calculator1.class has not been deployed.
所以问题是:在使用CLI时如何将Java类添加到适配器?
So the question is: how can I add Java classes to an adapter when using the CLI?
推荐答案
生成WAR的构建文件中存在无效的classpathref。
There's an invalid classpathref in the build file that's producing the WAR.
您可以编辑 [CLI安装位置] /worklight-cli/node_modules/generator-worklight-server/lib/build.xml
以使用classpathref修复此问题。
You can edit [CLI Install Location]/worklight-cli/node_modules/generator-worklight-server/lib/build.xml
to fix this issue with the classpathref.
如果您不打算使用任何服务器运行时库:
在第132行,您可以删除attribute classpathref =server-classpath。
If you're not planning on using any server runtime libraries:
On line 132, you can remove the attribute classpathref="server-classpath".
如果您打算使用服务器运行时库:
你会需要添加编译代码时要使用的server-classpath。在build.xml文件中的 build-WAR
目标之前,您可以添加以下内容:
< path id =服务器类路径>
< fileset dir =$ {worklight.jars.dir}includes =worklight-jee-library.jar/>
< fileset dir =[您的主目录] / .worklight / 6.2.0 / server / wlp / devincludes =** / * .jar/>
< / path>
If you plan on using server runtime libraries:
You'll need to add the "server-classpath" to be used when compiling your code. Before the build-WAR
target in the build.xml file, you can add the following<path id="server-classpath"> <fileset dir="${worklight.jars.dir}" includes="worklight-jee-library.jar" /> <fileset dir="[your home directory]/.worklight/6.2.0/server/wlp/dev" includes="**/*.jar" /> </path>
请注意第二个文件集,您必须更改 [您的主目录]
到适当的路径。在编译类时,添加这两个文件集包括worklight运行时和服务器运行时。
Please note that the second fileset, you'll have to change [your home directory]
to the appropriate path. Adding both of these filesets includes the worklight runtime and the server runtime when compiling your classes.
进行更改后
重新启动服务器。此时,应将Calculator1类添加到WAR中。
When you've made your changes:
Restart the server. At this point, the Calculator1 class should be added to your WAR.
这篇关于使用CLI时如何将Java类添加到Worklight适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!