How to add Java classes to a Worklight adapter when using CLI - ibm-mobilefirst

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.
When I do:
wl create WLProject
cd WLProject
wl add adapter
copy the Java class (Calculator1.java) to server/java/com/worklight/customcode
wl start
The build process fails and no war file is created;
When I do:
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
The invocation fails. When I inspect the war file, the Calculator1.class has not been deployed.
So the question is: how can I add Java classes to an adapter when using the CLI?

Sounds like a bug to me. It looks like the build process fails when introducing server-side artifacts.
This might be not currently supported in the CLI, but I can't imagine such a limitation...
I've opened a defect to have this looked at.
You can open a PMR (support ticket) to receive a fix if/when available.
If I do the following,
the .war file is being generated.
wl create myTestProject
cd myTestProject/
wl build
But if I do this,
the .war file is not generated which is why everything else then fails:
wl create myTestProject
mkdir -p myTestProject/server/java/com/worklight/customcode
cp Calculator.java myTestProject/server/java/com/worklight/customcode
cd myTestProject/
wl build

There's an invalid classpathref in the build file that's producing the WAR.
You can edit [CLI Install Location]/worklight-cli/node_modules/generator-worklight-server/lib/build.xml to fix this issue with the classpathref.
If you're not planning on using any server runtime libraries:
On line 132, you can remove the attribute classpathref="server-classpath".
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>
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.
When you've made your changes:
Restart the server. At this point, the Calculator1 class should be added to your WAR.

Related

JavaFX application fail to launch with native exe bundle created with intellij ide

I have build a JavaFX application which can be executed by its jar file. However if i try to run it using the native exe bundle i am receiving two popups:
Error Invoking method
Failed to launch JVM
and the application fails to start.
The Javafx application is build with intellij ide.
The project structure looks as follows;
when launching the application following popup shows..
The config file looks as follows:-
The packaged jar file is executing properly...
the problem occurs when starting application with launching exe file.
kindly tell me what could went wrong?
UPDATE:
It seems that the build output runtime/bin directory does not contain java.exe file therefore i think the application does not launches.
the output when try to run the application is as follows:
i have build the application with intellij idea, i think there is a problem with that. Kindly look into this matter.
UPDATED:-
Run it from the command line using the runtime that was bundled for you:
If you made an executable Jar (with a proper manifest specifying the classpath and main class)
cd firecap
runtime\bin\java -jar app\libs\your-main.jar
If you don't have an executable jar use something like
cd firecap
runtime\bin\java -cp app\libs\*.* your.main.class.name
Since java.exe is a console program you should be able to see the full error output to get a better idea of what is going wrong.
You very likely have missed including a needed module in the runtime.
It is also possible you ran into a bug that I discovered recently: https://bugs.openjdk.java.net/browse/JDK-8254920
I created my runtime image with this command:
"C:\Program Files\BellSoft\LibericaJDK-15-Full\bin\jlink.exe" --no-header-files --no-man-page, --compress=1 --add-modules java.management,java.logging,javafx.controls,java.xml,java.desktop --output C:\MyProject\build\image\runtime
But yours may be different depending on what modules you need. Note also that I used a JDK from BellSoft that included the JavaFX modules to make it easier.

IBM MobileFirst war file unable to deploy to MFP server

I had tried deploy both war file without java and jar files and with java and jar files. The war file without java and jar files managed to deploy successfully without any error in the log. The runtime appear in the admin console and everything works.
If I deploy server/java and jar war files, my runtime will disappear from the admin console. Here is my java lib,
I am using the IBM Server Configuration Tool to deploy war.
axis.jar
bcprov-jdk14-143.jar
commons-discovery-0.2.jar
commons=logging.jar
CryptoPasswordTool_14.jar
e2eejslib2048_b1.4_v1.3jar
jaxrpc.jar
jcprov.jar
saaj.jar
wsdl4j.jar
xerces-2.9.1.jar
Here is my Java call
javax.xml.rpc.Service aacmService = javax.xml.rpc.ServiceFactory.newInstance().createService(new java.net.URL(connectionUrl),new javax.xml.namespace.QName(ssoLink, "SSOService"));
These library had been used in my server/java to make some customized server call.Is there any of these jar files that will crash with MFP?
In this environment, I unable to get to copy anything out from the server due to the client policy. But I managed to take a shot on the screen.
Without proper information to review, such as the complete log file to see all errors printed, the recommendation is to open a PMR instead of a question on stack overflow, which anyway is more suitable for programming questions rather than infrastructure questions.
Open a support ticket to IBM: http://www-01.ibm.com/support/docview.wss?uid=swg21507643

IBM MobileFirst: using external jar files during command line build

We are trying to use a org.JSON.JSONObject library for some intense json processing in the adapter side. We have Java classes which processes the data received from http adapters.
mobilefirst 6.3.0 and using cli 20150701 build
(the recent one).
This JSON referencing has no issues when building from eclipse mobilefirst studio environment.
We are building this environment in ubuntu linux 14.04. There is an error in referencing org.JSON.JSONObject..x.jar file when we execute
mfp start or mfp build or mfp deploy
Is there a way to reference this jar file during mfp start or mfp build or mfp deploy as a classpath.
We need to have something like
mfp -classpath "path/to/json.jar" build
please help.
As it turns out, the CLI does not yet recognize jars placed into the server/lib folder of your project. In oder to make this work, you can make a simple edit to the following file:
[cli install folder]/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml
At or about line 123, add the third fileset element shown below:
<!-- Classpath for server runtime libraries used when building the WAR -->
<path id="server-classpath">
<fileset dir="${worklight.jars.dir}" includes="worklight-jee-library.jar" />
<fileset dir="${worklight.server.install.dir}/wlp/dev" includes="**/*.jar" />
<!-- add server/lib folder to classpath -->
<fileset dir="${worklight.app.dir}/../server/lib" includes="**/*.jar" />
</path>
After that, running 'mfp start' (or 'mfp restart' if your server is already running) will compile your custom Java code with any jars that you add to the server/lib folder included in the classpath.
JARs for use by your adapters should be added to you Project's server directory in the folder lib. They will be included in your Projects WAR file when the project is built (in Studio or by the ant tasks) and when you deploy that WAR it will be visible to your adapters.
I agree with #bjustin_ibm. Thanks for that. While the above approach works, there's also another way of doing this.
Alternative hack
Just add your required .jars to the following location, it gets added to the classpath during mfp start
/home/instanceubuntu/.ibm/mobilefirst/6.3.0/server/wlp/dev/spi/third-party
This solution is more simple and doesn't really have to maintain the build.xml file.
Hope this helps.

Deploying file to WebLogic - Error: Unresolved Webapp Library references

I received this error on deploying the file to WebLogic.
Should I make any alteration to the Weblogic.xml file?
Error: Unresolved Webapp Library references for "ServletContext#8793091[app:casman-jsf-3 module:casman-jsf-3.5-SNAPSHOT.war path: spec-version:2.5]", defined in weblogic.xml [Extension-Name: jstl, Specification-Version: 1.1, exact-match: true], [Extension-Name: jsf-myfaces, Specification-Version: 1.1, exact-match: true]
To fix this, I had to take the following steps (I am developing using Eclipse and deploying to Weblogic 10.3.5):
REMOVE weblogic.xml from the /WebContent/WEB-INF/ directory
Add needed jars to your lib directory (/WEB-INF/lib/) including JSTL.jar
Add project libraries to your Deployment Descriptor
Install EAR or WAR to Weblogic
This resolved the issue.
the error is because some library referenced in the Weblogic.xml is not being accessed during deployment.
try to call all the referencing libraries through run (Windows OS). Like if you have some reference to a library called \systemlib\alllibs\lib1.jar, then go to run and try calling in the library file or see manually if you can access the file in the server.
If the file is present then for unix/linux server, check if there are no access rights issue on the system. like if the library was placed by the root user and the weblogic user(Application server) does not have rights to read or write on the library folder. Remove any such issues.
Lastly, since the error specifically says JSTL, therefore check if the JRE version and JSTL version are in sync.
If still the error is not resolved, then please share the weblogic.xml also
Do a deep search of "jsf" in your wlServer\common\deployable-libraries folder .
Find the library corresponding to that extension and install it into your server.
Re-deploye the application
It worked for me

HSQLDB - works with external Jar - not with JRE

Using a test app to figure out problems with production application and hsqldb.
If I compile the test app with the hsqldb.jar file as an external jar in eclipse the program works. However, if I only have the jar file in my JRE system library I get a pre-9.0 client attempted to connect error from the database.
The two files are the exact same files. Only difference is one was added as external jar and the other was just in the class path. When production app builds it is using classpath to same file and generating the same pre-9.0 error.
The jar you want to use is an HSQLDB version 2.0 jar. There is a second HSQLDB jar which is version 1.8 and is in your classpath before your intended jar.
This is a classpath issue. You should be able to find where the second jar (1.8) is and how it gets into the classpath by using java -verbose or other debugging options.
[added] An additional step you could take to debug this in your application is to print out the value of the field org.hsqldb.persist.HsqlDatabaseProperties.THIS_FULL_VERSION before connecting to the database. This will print the version of the jar used as the client. A successful connection means the client and server jars are the same version.
The server instance prints out its version to the console when it starts.
I would also recommend using the latest snapshot jar for HSQLDB from the http://hsqldb.org/support/ page.
Sorted out problem by moving hsqldb.jar to first declared in classpath.