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
3.1.0 AerospikeClient.register in war does not work #26
Comments
Can you provide the code snippet where register was called? |
This will work if you place the file in "src/main/resources/udf/list_functions.lua" and you use maven to build "myjar.jar" and this jar is placed in the war file "WEB-INF/lib/myjar.jar". ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
Here is my exact code, it is a list of file names, all of these files are under the udf directory. It is nearly identical to your code. for (String udfResource : UDF_RESOURCES) {
client.register(client.readPolicyDefault, Thread.currentThread().getContextClassLoader(), "udf" + File.separator + udfResource, udfResource, Language.LUA);
} Also, I am building my project with maven. I have multiple builds, one builds the jar, the other the war. The file structure in my war is a typical war structure
My jar contains the following file structure
The problem is in your register function you do this -- File file = new File(resourceLoader.getResource(resourcePath).getFile()); java.io.File is not designed to read things out of an .jar archive. I have created a github project that illustrates the issue. |
We tried your test repo and it originally failed like you described. Then we changed your last run instruction and it worked fine. Old: New: java.io.File is designed to read things out of an .jar archive. |
I have fixed my example. Changing the classpath order was allowing the classloader to find the udf directory in the filesystem (because . was loaded first). I changed the example so that the udf directory is not in the same directory as the runtime of the program. It now errors no matter how you specify the classpath. The mkyong example is showing how to read a file from the resource directory and not an example of how to read a resource from a jar file. He is using maven to compile and test a given class but maven does not generate a jar file in the compile, test-compile or test-phase. If you run maven in debug mode (mvn -X test) you will see the test classpath is similar to this.
So the target/test directory is included in the classpath and then the target/classes directory is included. The target/classes directory will contain all resources and all compiled classes, which is why the mykong example works. Looking at the documentation here - https://docs.oracle.com/javase/6/docs/api/java/io/File.html - there doesn't seem to be anything suggesting that java.io.File will handle anything but regular filesystem operations. |
Ok, I see your point. Our tests worked because the udf directory existed on the filesystem as well as the jar. Our war test also worked because tomcat expands the war file, so "WEB-INF/classes/udf" existed on the filesystem too. We will fix in the next java client release. |
Hi, Thanks |
Yes, that was fixed 9 months ago. |
…ependencies Update spring dependencies
…ike_template_misc_methods ReactiveAerospikeTemplate implementation (miscellaneous methods)
I tried upgrading to the latest aerospike client version and had an error trying to use the new register function from within a war.
AerospikeClient.register(readPolicy, contextLoader, resourcePath, name, Language.LUA)
Caused by: java.io.FileNotFoundException: /content/mywar.war/WEB-INF/lib/myjar.jar/udf/list_functions.lua (No such file or directory)
at java.io.FileInputStream.open(Native Method) [rt.jar:1.7.0_71]
The text was updated successfully, but these errors were encountered: