java.lang.RuntimeException: can not create nginx handler for name
chenhao13579 opened this issue · comments
Could you please check what the problem is
env
spring-boot 2.2.4
windows 11
nginx-clojure-0.5.3
my nginx.config
###you can uncomment next two lines for easy debug
###Warning: if master_process is off, there will be only one nginx worker running. Only use it for debug propose.
#daemon off;
#master_process off;
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
jvm_handler_type 'java';
jvm_path 'D:/tool/jdk1.8/jre/bin/server/jvm.dll';
#jvm_path auto;
jvm_var my_other_jars 'D:/tool/nginx/nginx-clojure-0.6.0/nginx-clojure-0.6.0';
### Set my app jars and resources, it must include nginx-clojure runtime jar,e.g. nginx-clojure-0.5.3.jar and
### for clojure user clojure runtime jar is also needed.
### See http://nginx-clojure.github.io/directives.html#jvm_classpath
#jvm_classpath "libs/*;jars/*;";
#jvm_classpath "libs/*;jars/*;#{my_other_jars}/jars/nginx-clojure-cache-0.0.1-SNAPSHOT.jar;";
jvm_classpath "libs/*;jars/*;D:/git-repository/nginx-clojure-cache/target/nginx-clojure-cache-0.0.1-SNAPSHOT.jar;";
jvm_init_handler_name 'com.ngcjc.handle.NginxJvmInitHandler';
###jvm heap memory
#jvm_options "-Xms1024m";
#jvm_options "-Xmx1024m";
#for enable java remote debug uncomment next two lines
#jvm_options "-Xdebug";
#jvm_options "-Xrunjdwp:server=y,transport=dt_socket,address=840#{pno},suspend=n";
###threads number for request handler thread pool on jvm, default is 0.
###check more details from
#jvm_workers 8;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
set $proxy_target "";
location /hello {
rewrite_handler_type spring;
rewrite_handler_name 'com.ngcjc.handle.NginxSpringHandlerWrapper';
rewrite_handler_property 'spring.realHandler' 'myRewriteHandler';
rewrite_handler_property 'spring.prefetched.vars' 'remote_addr,remote_port';
proxy_pass http://$proxy_target;
}
location /clojure {
handler_type 'clojure';
handler_code '
(fn[req]
{
:status 200,
:headers {"content-type" "text/plain"},
:body "Hello Clojure & Nginx!"
})
';
}
location /java {
content_handler_type 'java';
content_handler_name 'com.ngcjc.handle.TestHandle';
}
}
}
error.log
java.lang.RuntimeException: can not create nginx handler for name : com.ngcjc.handle.NginxJvmInitHandler
at nginx.clojure.java.NginxJavaHandlerFactory.newInstance(NginxJavaHandlerFactory.java:33)
at nginx.clojure.NginxHandlerFactory.fetchHandler(NginxHandlerFactory.java:47)
at nginx.clojure.NginxClojureRT.registerCode(NginxClojureRT.java:865)
Caused by: java.lang.ClassNotFoundException: com.ngcjc.handle.NginxJvmInitHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at nginx.clojure.java.NginxJavaHandlerFactory.newInstance(NginxJavaHandlerFactory.java:23)
... 2 more
2023/05/26 10:42:06 [error] 29524#27232: invalid java init-process code : com.ngcjc.handle.NginxJvmInitHandler
2023/05/26 10:42:07 [error] 27996#29496: jvm may be mad for wrong options! See hs_err_pid****.log for detail! restarted 2
2023/05/26 10:42:07 [error] 27996#29496: we try quit master now!
2023/05/26 10:42:07 [crit] 27996#29496: ngx_http_clojure_quit_master, file ("D:\tool\nginx\nginx-clojure-0.5.3\nginx-clojure-0.5.3\nginx.exe"), arg ("nginx.exe -s stop")
2023/05/26 10:42:07 [error] 23704#24552: jvm may be mad for wrong options! See hs_err_pid****.log for detail! restarted 3
2023/05/26 10:42:07 [error] 23704#24552: we try quit master now!
2023/05/26 10:42:07 [crit] 23704#24552: ngx_http_clojure_quit_master, file ("D:\tool\nginx\nginx-clojure-0.5.3\nginx-clojure-0.5.3\nginx.exe"), arg ("nginx.exe -s stop")
2023/05/26 10:42:07 [error] 25932#30712: CreateFile() "D:\tool\nginx\nginx-clojure-0.5.3\nginx-clojure-0.5.3/logs/nginx.pid" failed (2: The system cannot find the file specified)
Caused by: java.lang.ClassNotFoundException: com.ngcjc.handle.NginxJvmInitHandler 。
It seems jvm_classpath is configured incorrectly or your jar is not a plain jar file, e.g. spring boot maven plugin packaged standalone jar file.
BTW rewrite_handler_type spring;
can not work too. The feature about spring handler type has not been released.
I use the spring-boot-maven-plugin package, and jvm_path specifies this path
nginx.conf
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
jvm_handler_type 'java';
jvm_path 'D:/tool/jdk1.8/jre/bin/server/jvm.dll';
jvm_var my_other_jars 'D:/tool/nginx/nginx-clojure-0.6.0/nginx-clojure-0.6.0';
jvm_classpath "libs/*;jars/*;D:/git-repository/nginx-clojure-cache/target/nginx-clojure-cache-0.0.1-SNAPSHOT.jar;";
jvm_init_handler_name 'com.ngcjc.handle.NginxJvmInitHandler';
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /clojure {
handler_type 'clojure';
handler_code '
(fn[req]
{
:status 200,
:headers {"content-type" "text/plain"},
:body "Hello Clojure & Nginx!"
})
';
}
location /java {
content_handler_type 'java';
content_handler_name 'com.ngcjc.handle.TestHandle';
}
}
}
But the mistake is still this one
java.lang.RuntimeException: can not create nginx handler for name : com.ngcjc.handle.NginxJvmInitHandler
at nginx.clojure.java.NginxJavaHandlerFactory.newInstance(NginxJavaHandlerFactory.java:33)
at nginx.clojure.NginxHandlerFactory.fetchHandler(NginxHandlerFactory.java:47)
at nginx.clojure.NginxClojureRT.registerCode(NginxClojureRT.java:865)
Caused by: java.lang.ClassNotFoundException: com.ngcjc.handle.NginxJvmInitHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at nginx.clojure.java.NginxJavaHandlerFactory.newInstance(NginxJavaHandlerFactory.java:23)
... 2 more
2023/05/26 14:41:02 [error] 24104#31020: invalid java init-process code : com.ngcjc.handle.NginxJvmInitHandler
2023/05/26 14:41:03 [error] 20152#23704: jvm may be mad for wrong options! See hs_err_pid****.log for detail! restarted 2
2023/05/26 14:41:03 [error] 20152#23704: we try quit master now!
2023/05/26 14:41:03 [crit] 20152#23704: ngx_http_clojure_quit_master, file ("D:\tool\nginx\nginx-clojure-0.5.3\nginx-clojure-0.5.3\nginx.exe"), arg ("nginx.exe -s stop")
2023/05/26 14:41:03 [error] 14728#27232: jvm may be mad for wrong options! See hs_err_pid****.log for detail! restarted 3
2023/05/26 14:41:03 [error] 14728#27232: we try quit master now!
2023/05/26 14:41:03 [crit] 14728#27232: ngx_http_clojure_quit_master, file ("D:\tool\nginx\nginx-clojure-0.5.3\nginx-clojure-0.5.3\nginx.exe"), arg ("nginx.exe -s stop")
2023/05/26 14:41:03 [error] 30320#22320: CreateFile() "D:\tool\nginx\nginx-clojure-0.5.3\nginx-clojure-0.5.3/logs/nginx.pid" failed (2: The system cannot find the file specified)
Please try to use maven-assembly-plugin to package your jar file.
Here's an example https://github.com/nginx-clojure/nginx-clojure/tree/master/example-projects/spring-core-example
thank you for your help