Comments (8)
Can you provide the code snippet where register was called?
I would like to see how the classloader was obtained and the resourcePath used.
Also, where is the resource file located on disk?
from aerospike-client-java.
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();
client.register(policy, cl, "udf/list_functions.lua", "list_functions.lua", Language.LUA);
from aerospike-client-java.
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
META-INF/
WEB-INF/lib/myjar.jar
My jar contains the following file structure
udf/list_functions.lua
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.
https://github.com/kevinmic/java_readFileFromResource
from aerospike-client-java.
We tried your test repo and it originally failed like you described.
Then we changed your last run instruction and it worked fine.
Old:
java -classpath myjar.jar:. TestIt
New:
java -cp .:myjar.jar TestIt
java.io.File is designed to read things out of an .jar archive.
See: http://www.mkyong.com/java/java-read-a-file-from-resources-folder
from aerospike-client-java.
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.
[DEBUG] test classpath: /apps/code/git/ax/model/target/test-classes /apps/code/git/ax/model/target/classes
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.
from aerospike-client-java.
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.
from aerospike-client-java.
Hi,
I want to know in Aerospike Client Java 3.2, this error is fixed?
Thanks
from aerospike-client-java.
Yes, that was fixed 9 months ago.
from aerospike-client-java.
Related Issues (20)
- Streaming support for batch operations HOT 2
- rename Record to AerospikeRecord HOT 1
- View screenshot link is broken HOT 1
- Type Erasure in 5.1.11 HOT 7
- Fully support surrogates symbol in Strings HOT 5
- Wrong condition for aeropsike client connectivity HOT 6
- Add RetryListener HOT 7
- Security contact? HOT 2
- Aerospike Cluster Peer Invalid Node Docker HOT 3
- Node name is null HOT 1
- Error 20: Partition map empty ( Issue for java client ) HOT 8
- Add support for findBySinceUpdate using since_update in metadata HOT 2
- What is the difference between `BatchRecordArrayListener` and `RecordArrayListener`? HOT 2
- How to make async queries faster? HOT 3
- java.lang.NullPointerException in AerospikeClient.put() HOT 4
- Setters for Spring HOT 2
- Enable releases in github HOT 4
- Problem reading Date type with client version 7.X HOT 2
- When compiling lua, the client discards the exception which has the lua compilation error details. HOT 2
- Add listener for node addition / deletion HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aerospike-client-java.