Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java action that depends on packages jar file fails #31

Open
brunogirin opened this issue Apr 5, 2018 · 4 comments
Open

Java action that depends on packages jar file fails #31

brunogirin opened this issue Apr 5, 2018 · 4 comments

Comments

@brunogirin
Copy link

I have a set of Java actions packaged in a jar file that I deploy on Bluemix. All Java code is packaged in a jar file with a lib directory that contains dependant jar files, in particular the Cloudant client. Simple actions that do not use any dependant libraries work fine. Actions that use the Cloudant library fail with a NoClassDefFoundError.

Environment details:

  • Bluemix
  • Build on Ubuntu 16.04

Steps to reproduce the issue:

  1. Build the code with gradle
  2. Deploy on bluemix (I use wskdeploy)
  3. Invoke the example/greeting action
  4. Invoke the example/cloudant-test action

Provide the expected results and outputs:

Result invoking example/greeting:

$ bx wsk action invoke example/greeting  -b
ok: invoked /_/example/greeting with id 48d37cc2dfff42c2937cc2dfff42c2cb
{
    "activationId": "48d37cc2dfff42c2937cc2dfff42c2cb",
    "annotations": [
        {
            "key": "path",
            "value": "consideratehoteliers.com_dev/example/greeting"
        },
        {
            "key": "waitTime",
            "value": 493
        },
        {
            "key": "kind",
            "value": "java"
        },
        {
            "key": "limits",
            "value": {
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        },
        {
            "key": "initTime",
            "value": 434
        }
    ],
    "duration": 460,
    "end": 1522921174650,
    "logs": [],
    "name": "greeting",
    "namespace": "consideratehoteliers.com_dev",
    "publish": false,
    "response": {
        "result": {
            "greeting": "Hello !"
        },
        "status": "success",
        "success": true
    },
    "start": 1522921174190,
    "subject": "[email protected]",
    "version": "0.0.1"
}

Provide the actual results and outputs:

$ bx wsk action invoke example/cloudant_test -b
ok: invoked /_/example/cloudant_test with id b7b7df5cbc754685b7df5cbc752685c5
{
    "activationId": "b7b7df5cbc754685b7df5cbc752685c5",
    "annotations": [
        {
            "key": "path",
            "value": "consideratehoteliers.com_dev/example/cloudant_test"
        },
        {
            "key": "waitTime",
            "value": 520
        },
        {
            "key": "kind",
            "value": "java"
        },
        {
            "key": "limits",
            "value": {
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        },
        {
            "key": "initTime",
            "value": 420
        }
    ],
    "duration": 447,
    "end": 1522851950713,
    "logs": [],
    "name": "cloudant_test",
    "namespace": "consideratehoteliers.com_dev",
    "publish": false,
    "response": {
        "result": {
            "error": "An error has occured while invoking the action (see logs for details): java.lang.NoClassDefFoundError: com/cloudant/client/api/ClientBuilder"
        },
        "status": "action developer error",
        "success": false
    },
    "start": 1522851950266,
    "subject": "[email protected]",
    "version": "0.0.1"
}

Additional information you deem important:

See attached files that include:

  • the wskdeploy manifest
  • the gradle build file
  • two Java classes that implement the actions mentioned above, Hello.java that works and CloudantTest.java that doesn't

code.zip

@rabbah
Copy link
Member

rabbah commented Apr 6, 2018

Did you try locating the libraries at the root path instead of under /lib? Will have a look at your zip file.

@brunogirin
Copy link
Author

When I check the jar file, here's what's inside, the additional jar are in the lib folder in the main jar:

$ jar tvf ./build/libs/platform-0.0.1.jar 
     0 Thu Apr 05 15:39:40 BST 2018 META-INF/
   105 Mon Mar 19 12:52:44 GMT 2018 META-INF/MANIFEST.MF
     0 Mon Mar 19 12:52:44 GMT 2018 com/
     0 Thu Apr 05 15:39:40 BST 2018 com/consideratehoteliers/
  2563 Thu Apr 05 15:39:40 BST 2018 com/consideratehoteliers/CloudantTest.class
  1127 Thu Apr 05 15:39:40 BST 2018 com/consideratehoteliers/Hello.class
     0 Thu Apr 05 15:39:42 BST 2018 lib/
213477 Wed Apr 04 14:53:24 BST 2018 lib/cloudant-client-2.12.0.jar
232932 Mon Mar 19 12:40:00 GMT 2018 lib/gson-2.8.2.jar
232771 Wed Apr 04 14:53:24 BST 2018 lib/commons-codec-1.6.jar
 41629 Wed Apr 04 14:53:24 BST 2018 lib/cloudant-http-2.12.0.jar
185140 Wed Apr 04 14:53:24 BST 2018 lib/commons-io-2.4.jar

@gorkem
Copy link
Contributor

gorkem commented Apr 20, 2018

@rabbah Are dependencies packaged into /lib folder even supposed to work. This is not really a Java standard and I do not see anything to enable this on the runtime.

@brunogirin Do your functions work OK when you package them as one jar?

@brunogirin
Copy link
Author

@gorkem I didn't try that but will do when I have the time. That said, it raises a question of how to package dependencies that a particular Java action relies on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants