Java Handler Error

266 views
Skip to first unread message

vikrant singh

unread,
Apr 17, 2015, 2:46:05 PM4/17/15
to nginx-...@googlegroups.com
Hello,
I am starting with setting up a java handler as explained here 

This is how jvm settings in my config file looks
.
   jvm_path "/home/y/libexec64/jdk64-1.8.0/jre/lib/amd64/server/libjvm.so";

    ### my app jars e.g. clojure-1.5.1.jar , groovy-2.3.4.jar ,etc.
    jvm_var jar_path '/home/y/lib/jars';
    jvm_var base_jar '#{jar_path}/nginx-clojure-0.3.0.jar';
    jvm_var hwService_jar '#{jar_path}/HelloService.jar';

    ###jvm_options can be repeated once per option.
    jvm_options "-Djava.class.path=#{base_jar}:#{hwService_jar}";

I have all the jars in place.

This is how location settings are..
      location /java {
          content_handler_type 'java';
          content_handler_name 'mytest.HelloService';
       }


when I hit /java on my server, I get following error in error.log

2015/04/17 18:29:11 [error] 18331#0: invalid java content_handler code : mytest.HelloService
Exception in thread "main" java.lang.RuntimeException: can not create nginx handler for name : mytest.HelloService
        at nginx.clojure.java.NginxJavaHandlerFactory.newInstance(NginxJavaHandlerFactory.java:33)
        at nginx.clojure.NginxHandlerFactory.fetchHandler(NginxHandlerFactory.java:46)
        at nginx.clojure.NginxClojureRT.registerCode(NginxClojureRT.java:696)
Caused by: java.lang.ClassNotFoundException: mytest.HelloService
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at nginx.clojure.java.NginxJavaHandlerFactory.newInstance(NginxJavaHandlerFactory.java:23)
        ... 2 more
2015/04/17 18:30:11 [error] 18331#0: invalid java content_handler code : mytest.HelloService


Not sure whats wrong here, 
Any help?
Best Regards,
Vikrant


Yuexiang Zhang

unread,
Apr 20, 2015, 3:04:56 AM4/20/15
to vikrant singh, nginx-...@googlegroups.com
Hi, It seems that nginx-clojure can not find mytest.HelloService  
in the classpath.

Regards.
Xfeep

--
You received this message because you are subscribed to the Google Groups "Nginx-Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginx-clojur...@googlegroups.com.
To post to this group, send email to nginx-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nginx-clojure/2b0fc079-65c8-43e1-be38-0d535de1bbc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yuexiang Zhang

unread,
Apr 20, 2015, 4:35:55 AM4/20/15
to vikrant singh, nginx-...@googlegroups.com
Hi, If your classpath is right, please make sure that the user of nginx workers has enough permissions to access all jars in the classpath.


Regards.
Xfeep

vikrant singh

unread,
Apr 20, 2015, 7:52:18 PM4/20/15
to nginx-...@googlegroups.com, vikrant...@gmail.com
Thanks for reply... You guessed it right. It was an issue with jar file. I was not packaging it correct. It is working correct now.

Another problem  where I was wondering if I can ask you for advise is,  using this framework in a reverse proxy setup. 

Is there a way I can use your framework.. along with "proxy_pass" config?

I need to use nginx as a reverse proxy. For each incoming request I need to look up in a service directory setup (which have a java interface) for service instance. I want to use your framework to do this lookup and then use the fetched information to populate proxy_pass.

Thanks,
Vikrant

Yuexiang Zhang

unread,
Apr 20, 2015, 10:02:10 PM4/20/15
to vikrant singh, nginx-...@googlegroups.com
Hi, 

Please try 

(1) use rewrite handler to set some nginx vars
(2) use proxy_pass  with nginx vars
(3) use proxy_set_header with nginx vars

Regards.
Xfeep

Roman Woronowicz

unread,
May 14, 2017, 11:46:26 AM5/14/17
to Nginx-Clojure, vikrant...@gmail.com
Hi Vikrant,

Many versions later and I'm running into the same problem. It's such an obvious problem with, I'm certain, a simple fix.

You mentioned that you had an issue with your jar file -- packaged incorrectly. What did you encounter and how did you fix it?

Thank you,
Roman

Roman Woronowicz

unread,
May 14, 2017, 11:49:42 AM5/14/17
to Nginx-Clojure, vikrant...@gmail.com
I'm also running nginx as "root" to rule out any access issues.

Give my recent spat of luck in uncovering/encountering odd issues -- lol -- this would probably turn out to be something related to running a 32-bit JVM.

Yuexiang Zhang

unread,
May 15, 2017, 11:50:54 AM5/15/17
to Roman Woronowicz, Nginx-Clojure, vikrant singh
Hi, Roman,

If you run nginx with root, by default nginx will use the user named "nobody" to create nginx worker process where nginx-clojure runs in.
So please make sure nginx worker process have enough permission to access these java jar files.

Regards.
Xfeep 

To unsubscribe from this group and stop receiving emails from it, send an email to nginx-clojure+unsubscribe@googlegroups.com.

To post to this group, send email to nginx-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages