-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Calling of java methods in a .jar file fails, but listing methods works fine. #139
Comments
Hi Rainer, See if this works for you: julia> using JavaCall
julia> begin
JavaCall.init(["-Djava.class.path=$(joinpath(@__DIR__, "jars","View5D.jar"))"])
V = @jimport view5d.View5D
jArr = Vector{jfloat}
myJArr = rand(jfloat, 5,5,5,5,5)
myViewer = jcall(V, "Start5DViewerF", V, (jArr, jint, jint, jint, jint, jint), myJArr[:], 5, 5, 5, 5, 5)
end
created data 5
JavaObject{Symbol("view5d.View5D")}(JavaCall.JavaLocalRef(Ptr{Nothing} @0x0000000067418ea0)) Mark Kittisopikul, Ph.D. |
You are a star! This works like a charm saving me days of figuring this out! I will update the viewer to now work also in Julia very soon! V = @jimport view5d.View5D
createMethods(V,"Start5DViewer")
Start5DViewer(JuliaArray, size(1),size(2),size(3),size(4),size(5)) Rainer |
For julia> using JavaCall
julia> JavaCall.init()
julia> jls = @jimport java.lang.System
JavaObject{Symbol("java.lang.System")}
julia> out = jfield(jls, "out", @jimport java.io.PrintStream )
JavaObject{Symbol("java.io.PrintStream")}(JavaCall.JavaLocalRef(Ptr{Nothing} @0x0000000062b60830))
julia> jcall(out, "println", Nothing, (JString,), "Hello world")
Hello world I guess the analog would be About methods, one approach I am interested in is making
Hidden within JavaCall there is a subpackage called JProxies that attempted to do that: It could use some refactoring though. |
That's great! I should give this a try. |
I'll have to take a deeper look. A few things to consider:
|
I see the problem now. You want:
With your current code I was getting
Your code was looking for the |
I think the problem is different. This is copied from the current gitHub repository: |
Note that my version has an extra I'm also using VSCode. How are you loading the module to test it? Does the module live under |
Here's the initial diagnostic I did with your package:
|
Thanks a lot. the current mast branch has version 82f3457 |
With https://github.com/mkitti/View5D.jl/blob/82f345760c1a9798db980d1e1fdb09c7960722e1/src/View5D.jl#L154
In a new REPL, I am also able to fix it:
mkitti/View5D.jl@34a1c2d#diff-65fd30959efdc3bea2f43738e03f77584a68e5737b924733e704eeb1f563b0b4R154 I cannot reproduce the error after the change. https://github.com/mkitti/View5D.jl/blob/34a1c2d25308906a6bb677301f81a74ed078c4bf/src/View5D.jl#L154 |
Brilliant! Sorry. I somehow missed the apparently crucial |
Is there something special when it comes to supplying nested types to JavaCall? jfloatArrArr = Vector{Vector{jfloat}}
jcall(myviewer, "ImportMarkerLists", Nothing, (jfloatArrArr,), marker_lists); which yields julia> import_marker_lists(a)
ERROR: MethodError: no method matching jvalue(::Vector{Vector{Float32}})
Closest candidates are:
jvalue(::Integer) at C:\Users\pi96doc\.julia\packages\JavaCall\aVXyt\src\core.jl:179
jvalue(::Float32) at C:\Users\pi96doc\.julia\packages\JavaCall\aVXyt\src\core.jl:180
jvalue(::Float64) at C:\Users\pi96doc\.julia\packages\JavaCall\aVXyt\src\core.jl:181 Any idea what could be the problem here? |
Let me see if I can come up with a snippet for the short term. |
This is a hack, but it works for now. using JavaCall
using View5D
import View5D: import_marker_lists, get_viewer
JavaCall.metaclass(::Type{T}) where T <: AbstractVector = JavaCall.metaclass(Symbol(JavaCall.signature(T)))
JavaCall.javaclassname(::Type{T}) where T <: AbstractVector = JavaCall.signature(T)
JavaCall.signature(arg::Type{JavaObject{T}}) where {T <: AbstractVector} = string(JavaCall.javaclassname(T))
function import_marker_lists(marker_lists::Vector{Vector{T}}, myviewer=nothing) where {T}
myviewer=get_viewer(myviewer)
if T != Float32
marker_lists = [convert.(Float32,marker_lists[n]) for n in 1:length(marker_lists)]
end
jfloatArrArr = Vector{JavaObject{Vector{jfloat}}}
converted = JavaCall.convert_arg.(Vector{jfloat}, marker_lists)
GC.@preserve converted begin
jcall(myviewer, "ImportMarkerLists", Nothing, (jfloatArrArr,), [c[2] for c in converted]);
end
return
end Demo: julia> viewer = View5D.view5d( rand(Float32, 5, 4, 3, 2, 1) )
Initializing JavaCall with callpath: ["-Djava.class.path=C:\\Users\\kittisopikulm\\.julia\\dev\\View5D\\jars\\View5D.jar"]
created data 2
JavaObject{Symbol("view5d.View5D")}(JavaCall.JavaLocalRef(Ptr{Nothing} @0x000000000c9a7718))
julia> marker_lists = [rand(Float32,5) for i in 1:6]
6-element Vector{Vector{Float32}}:
[0.7869251, 0.16082549, 0.84801865, 0.81543195, 0.72889245]
[0.12232578, 0.7346517, 0.8028685, 0.9892626, 0.38214874]
[0.2725159, 0.24991906, 0.6246897, 0.82423186, 0.7155572]
[0.7211771, 0.05370474, 0.2918185, 0.28415167, 0.2144965]
[0.3052622, 0.64955544, 0.09476519, 0.22565961, 0.23076034]
[0.07435727, 0.23536158, 0.37190127, 0.00080156326, 0.9454497]
julia> import_marker_lists(marker_lists, viewer)
|
Thanks a lot! Great! Would you like to do a pull request with this? |
Here we go: RainerHeintzmann/View5D.jl#3 |
I am struggling with being able to call java routines, whos classes are inside a subfolder
view5d/
in the jar file. I tried in vain for days. After opening the library
works fine as do
listmethods(V)
or
yet when calling the function I always obtain a message that this method does not exist.
I also tried different version ("view5d/Start5FViewerF","view5d.Start5FViewerF","View5D.Start5FViewerF") and also calling a method like
wait()
with a much simpler signature, but the result is always the same.The code can be accessed under:
https://github.com/RainerHeintzmann/View5D.jl
(.jar file included)
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: