mixing clojure source with java class files problem!
Hi all, I'm having a really ridiculous problem...let's say there is jar on clojars with the following structure: --- top-level (.jar) --foo (clojure namespaces) -a.clj -b.clj -c.clj -- --bar (java .class files - no package declaration when compiled) --baz -d.class -g.class -- -- project.clj -- When i require namespaces from foo there is no problem (:require [foo.a :as A])...but when I try to import a couple of java class files from bar (:import [bar.baz d g]) it's not finding them! I compiled them specifically without package declarations so I can put them anywhere...I also tried without the bar.baz prefixing them but it doesn't work... what am I missing? any pointers? Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On Tue, Sep 18, 2012 at 10:52 AM, Jim - FooBar(); jimpil1...@gmail.com wrote: Hi all, I'm having a really ridiculous problem...let's say there is jar on clojars with the following structure: --- top-level (.jar) --foo (clojure namespaces) -a.clj -b.clj -c.clj -- --bar (java .class files - no package declaration when compiled) The package is baked into the .class file format. You can't change it after the fack by just moving files in the directory structure. You'll have to use a bytecode editor (such as Jar Jar Links: http://code.google.com/p/jarjar/) to change the package after-the-fact. What are you trying to accomplish by doing this? --Aaron -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On 18/09/12 16:00, Aaron Cohen wrote: The package is baked into the .class file format. You can't change it after the fack by just moving files in the directory structure. regardless of whether there is an actual package declaration? So, you're saying that if I compile the java source inside a replicated directory structure as the one it will be consumed from, everything will be fine? I honestly thought i could skip all that, by not having any packages at all! I also tried putting the class files right next to the clj files but again it wouldn't find them! What are you trying to accomplish by doing this? well, the short story is that I'm wrapping a library but I'm not completely satisfied with the way it does a couple of things...too many assumptions in some places - so I'm trying to sort of re-implement a couple of classes/interfaces and include them already compiled in a separate folder in the jar in case someone else faces similar issues. It took a while to write the java code and of course compile it successfully against all the prerequisites...now, apparently i need to recompile in a replicated dir structure... I did not use proxy and the gang cos it just seemed easier (mutable variables/inheritance etc etc) Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
It still not finding the compiled classes! I compiled them all using the exact same package declaration as the one found in the jar that I'm producing! I was also careful to convert the hyphen (directory name) to an underscore (in the .java file)... I am still getting a : ClassNotFoundException encog_java.customGA.CustomNeuralGeneticAlgorithm java.net.URLClassLoader$1.run (URLClassLoader.java:366) the jar i'm referring to is on clojars [enclog 0.5.6-SNAPSHOT] in case you have any doubts that the classes are in there... any pointers are greatly appreciated... Jim On 18/09/12 16:16, Jim - FooBar(); wrote: On 18/09/12 16:00, Aaron Cohen wrote: The package is baked into the .class file format. You can't change it after the fack by just moving files in the directory structure. regardless of whether there is an actual package declaration? So, you're saying that if I compile the java source inside a replicated directory structure as the one it will be consumed from, everything will be fine? I honestly thought i could skip all that, by not having any packages at all! I also tried putting the class files right next to the clj files but again it wouldn't find them! What are you trying to accomplish by doing this? well, the short story is that I'm wrapping a library but I'm not completely satisfied with the way it does a couple of things...too many assumptions in some places - so I'm trying to sort of re-implement a couple of classes/interfaces and include them already compiled in a separate folder in the jar in case someone else faces similar issues. It took a while to write the java code and of course compile it successfully against all the prerequisites...now, apparently i need to recompile in a replicated dir structure... I did not use proxy and the gang cos it just seemed easier (mutable variables/inheritance etc etc) Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
decompiling a simple interface gives: *package*encog_java.customGA; *import*org.encog.ml.MLRegression; *import*org.encog.ml.genetic.population.Population; *public**abstract**interface*CalculateScore { *public**abstract**double*calculateScore(MLRegression paramMLRegression); *public**abstract**boolean*shouldMinimize(); *public**abstract**void*setPopulation(Population paramPopulation); } the package declaration seems perfectly fine in the class files (as expected)...what on earth is happening? Tried both hyphen/underscore when :import-ing but i get the same error! Jim On 18/09/12 16:51, Jim - FooBar(); wrote: It still not finding the compiled classes! I compiled them all using the exact same package declaration as the one found in the jar that I'm producing! I was also careful to convert the hyphen (directory name) to an underscore (in the .java file)... I am still getting a : ClassNotFoundException encog_java.customGA.CustomNeuralGeneticAlgorithm java.net.URLClassLoader$1.run (URLClassLoader.java:366) the jar i'm referring to is on clojars [enclog 0.5.6-SNAPSHOT] in case you have any doubts that the classes are in there... any pointers are greatly appreciated... Jim On 18/09/12 16:16, Jim - FooBar(); wrote: On 18/09/12 16:00, Aaron Cohen wrote: The package is baked into the .class file format. You can't change it after the fack by just moving files in the directory structure. regardless of whether there is an actual package declaration? So, you're saying that if I compile the java source inside a replicated directory structure as the one it will be consumed from, everything will be fine? I honestly thought i could skip all that, by not having any packages at all! I also tried putting the class files right next to the clj files but again it wouldn't find them! What are you trying to accomplish by doing this? well, the short story is that I'm wrapping a library but I'm not completely satisfied with the way it does a couple of things...too many assumptions in some places - so I'm trying to sort of re-implement a couple of classes/interfaces and include them already compiled in a separate folder in the jar in case someone else faces similar issues. It took a while to write the java code and of course compile it successfully against all the prerequisites...now, apparently i need to recompile in a replicated dir structure... I did not use proxy and the gang cos it just seemed easier (mutable variables/inheritance etc etc) Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
What did you use to compile this? I don't believe hyphens are legal in Java package names. It will be hard to use this in clojure, clojure converts hyphens to underscores automatically behind the scenes in package names. But your package actually has a (possibly invalid) hyphen in it's name, so the mangling prevents your class from being found. --Aaron On Tue, Sep 18, 2012 at 11:58 AM, Jim - FooBar(); jimpil1...@gmail.com wrote: decompiling a simple interface gives: package encog_java.customGA; import org.encog.ml.MLRegression; import org.encog.ml.genetic.population.Population; public abstract interface CalculateScore { public abstract double calculateScore(MLRegression paramMLRegression); public abstract boolean shouldMinimize(); public abstract void setPopulation(Population paramPopulation); } the package declaration seems perfectly fine in the class files (as expected)...what on earth is happening? Tried both hyphen/underscore when :import-ing but i get the same error! Jim On 18/09/12 16:51, Jim - FooBar(); wrote: It still not finding the compiled classes! I compiled them all using the exact same package declaration as the one found in the jar that I'm producing! I was also careful to convert the hyphen (directory name) to an underscore (in the .java file)... I am still getting a : ClassNotFoundException encog_java.customGA.CustomNeuralGeneticAlgorithm java.net.URLClassLoader$1.run (URLClassLoader.java:366) the jar i'm referring to is on clojars [enclog 0.5.6-SNAPSHOT] in case you have any doubts that the classes are in there... any pointers are greatly appreciated... Jim On 18/09/12 16:16, Jim - FooBar(); wrote: On 18/09/12 16:00, Aaron Cohen wrote: The package is baked into the .class file format. You can't change it after the fack by just moving files in the directory structure. regardless of whether there is an actual package declaration? So, you're saying that if I compile the java source inside a replicated directory structure as the one it will be consumed from, everything will be fine? I honestly thought i could skip all that, by not having any packages at all! I also tried putting the class files right next to the clj files but again it wouldn't find them! What are you trying to accomplish by doing this? well, the short story is that I'm wrapping a library but I'm not completely satisfied with the way it does a couple of things...too many assumptions in some places - so I'm trying to sort of re-implement a couple of classes/interfaces and include them already compiled in a separate folder in the jar in case someone else faces similar issues. It took a while to write the java code and of course compile it successfully against all the prerequisites...now, apparently i need to recompile in a replicated dir structure... I did not use proxy and the gang cos it just seemed easier (mutable variables/inheritance etc etc) Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On 18/09/12 17:28, Aaron Cohen wrote: What did you use to compile this? I don't believe hyphens are legal in Java package names. I used regular *javac -cp blah:blah:blah encog-java/customGA/*.java* the compiler did not complain because the actual package declaration uses underscore instead of hyphen. yes hyphens are indeed illegal... that is, you cannot write package foo-bar; but you can write package foo_bar; when in fact being in the foo-bar folder. It will be hard to use this in clojure, clojure converts hyphens to underscores automatically behind the scenes in package names. But your package actually has a (possibly invalid) hyphen in it's name, so the mangling prevents your class from being found. exactly!!! when I ask from clojure (:import [encog-java.customGA aClass]) clojure should convert the hyphen to match the actual package found in the declaration of class files. UNderscores are certainly legal characters...the thing is, it doesn't matter whether i use an underscore or not when importing - I always get the same error which makes me slightly suspicious... In my desperation, I went into my ~/.m2 directory and actually modified the jar by hand so the folder encog-java was renamed to encog_java but again the same story! I don't get it!!! Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On Tue, Sep 18, 2012 at 12:39 PM, Jim - FooBar(); jimpil1...@gmail.com wrote: On 18/09/12 17:28, Aaron Cohen wrote: What did you use to compile this? I don't believe hyphens are legal in Java package names. I used regular javac -cp blah:blah:blah encog-java/customGA/*.java the compiler did not complain because the actual package declaration uses underscore instead of hyphen. yes hyphens are indeed illegal... that is, you cannot write package foo-bar; but you can write package foo_bar; when in fact being in the foo-bar folder. It will be hard to use this in clojure, clojure converts hyphens to underscores automatically behind the scenes in package names. But your package actually has a (possibly invalid) hyphen in it's name, so the mangling prevents your class from being found. I was actually wrong here, I think. I should probably check closer, but I now think that clojure only mangles its own package names when necessary. I don't think it ever mangles doing pure interop. exactly!!! when I ask from clojure (:import [encog-java.customGA aClass]) clojure should convert the hyphen to match the actual package found in the declaration of class files. UNderscores are certainly legal characters...the thing is, it doesn't matter whether i use an underscore or not when importing - I always get the same error which makes me slightly suspicious... In my desperation, I went into my ~/.m2 directory and actually modified the jar by hand so the folder encog-java was renamed to encog_java but again the same story! I don't get it!!! I actually just tried this (I don't recommend this approach though), and it worked for me, maybe you missed a step. I think you'll have best luck if you make your directory structure match the package name. --Aaron -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On 18/09/12 17:50, Aaron Cohen wrote: I actually just tried this (I don't recommend this approach though), and it worked for me, maybe you missed a step. what? seriously? You mean you downloaded the jar and managed to import some class from inside encog_java/customGA/ in some dummy project of yours ? Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On 18/09/12 17:50, Aaron Cohen wrote: I actually just tried this (I don't recommend this approach though), and it worked for me, maybe you missed a step. what jar is lein2 using? the one with the nice name or the one with the numbers at the end? which one of the 2 did you modify? Jim ps: btw thanks a million for your time -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On Tue, Sep 18, 2012 at 12:54 PM, Jim - FooBar(); jimpil1...@gmail.com wrote: On 18/09/12 17:50, Aaron Cohen wrote: I actually just tried this (I don't recommend this approach though), and it worked for me, maybe you missed a step. what jar is lein2 using? the one with the nice name or the one with the numbers at the end? which one of the 2 did you modify? Jim ps: btw thanks a million for your time The one with the full timestamp. I extracted the whole thing, renamed the directory and recompressed it. user= (import encog_java.customGA.CustomNeuralGeneticAlgorithm) encog_java.customGA.CustomNeuralGeneticAlgorithm -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: mixing clojure source with java class files problem!
On 18/09/12 17:54, Jim - FooBar(); wrote: On 18/09/12 17:50, Aaron Cohen wrote: I actually just tried this (I don't recommend this approach though), and it worked for me, maybe you missed a step. what jar is lein2 using? the one with the nice name or the one with the numbers at the end? which one of the 2 did you modify? Jim ps: btw thanks a million for your time it's the jar with the funny numbers at the end!!! I was trying the other one with the proper name! ok I guess I'll push one more SNAPSHOT without any hyphens/underscores! thanks a lot Aaron... :-) Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en