Re: How to call Clojure from Java?

2017-06-26 Thread Didier
Using gen-class or the Clojure Java API like Daniel showed are the best 
ways I know of. If you want static types in Java and auto-complete, and 
things to feel like Java, use gen-class, if not, use the Clojure Java API.

On Saturday, 24 June 2017 12:05:55 UTC-7, thelmuth wrote:
>
> Thanks for the suggestions! Daniel's code helped me a lot, thanks!
>
> One thing that had me stuck for a while is that you have to have a Clojure 
> jar in your classpath. I also worked through a different way, using an 
> uberjar of a Clojure project. I posted my guides here 
> 
>  
> for anyone else trying to do this.
>
> On Thursday, June 1, 2017 at 10:11:25 PM UTC-4, Daniel Compton wrote:
>>
>> Hi thelmuth
>>
>> Here's a fully worked example. It calls the Clojure function 
>> myco.dashed-namespace.app.core/start!. Save it to 
>> src/myco/dashed_namespace/app/Main.java.
>>
>> package myco.dashed_namespace.app;
>>
>> import clojure.java.api.Clojure;
>> import clojure.lang.IFn;
>>
>> public class Main {
>> public static void main(String[] args) {
>> try {
>> IFn require = Clojure.var("clojure.core", "require");
>> require.invoke(Clojure.read("myco.dashed-namespace.app.core"));
>>
>> Clojure.var("myco.dashed-namespace.app.core", "start!").invoke();
>> }
>> catch (Throwable e) {
>> System.out.println(e.getMessage());
>> }
>> }
>> }
>>
>>
>> On Fri, Jun 2, 2017 at 1:24 PM James Reeves  
>> wrote:
>>
>>> There's a brief section on this on the Clojure website:
>>>
>>> https://clojure.org/reference/java_interop#_calling_clojure_from_java
>>>
>>> On 2 June 2017 at 01:35, thelmuth  wrote:
>>>
 What is the best way to call a Clojure function from Java?

 Most of the resources I have found are either very old or don't go into 
 enough detail. I am a Clojure programmer with very little Java background, 
 and have been having trouble with the methods I've found, especially 
 classpath issues.

 -- 
 You received this message because you are subscribed to the Google
 Groups "Clojure" group.
 To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> -- 
>>> James Reeves
>>> booleanknot.com
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to call Clojure from Java?

2017-06-24 Thread thelmuth
Thanks for the suggestions! Daniel's code helped me a lot, thanks!

One thing that had me stuck for a while is that you have to have a Clojure 
jar in your classpath. I also worked through a different way, using an 
uberjar of a Clojure project. I posted my guides here 

 
for anyone else trying to do this.

On Thursday, June 1, 2017 at 10:11:25 PM UTC-4, Daniel Compton wrote:
>
> Hi thelmuth
>
> Here's a fully worked example. It calls the Clojure function 
> myco.dashed-namespace.app.core/start!. Save it to 
> src/myco/dashed_namespace/app/Main.java.
>
> package myco.dashed_namespace.app;
>
> import clojure.java.api.Clojure;
> import clojure.lang.IFn;
>
> public class Main {
> public static void main(String[] args) {
> try {
> IFn require = Clojure.var("clojure.core", "require");
> require.invoke(Clojure.read("myco.dashed-namespace.app.core"));
>
> Clojure.var("myco.dashed-namespace.app.core", "start!").invoke();
> }
> catch (Throwable e) {
> System.out.println(e.getMessage());
> }
> }
> }
>
>
> On Fri, Jun 2, 2017 at 1:24 PM James Reeves  > wrote:
>
>> There's a brief section on this on the Clojure website:
>>
>> https://clojure.org/reference/java_interop#_calling_clojure_from_java
>>
>> On 2 June 2017 at 01:35, thelmuth  wrote:
>>
>>> What is the best way to call a Clojure function from Java?
>>>
>>> Most of the resources I have found are either very old or don't go into 
>>> enough detail. I am a Clojure programmer with very little Java background, 
>>> and have been having trouble with the methods I've found, especially 
>>> classpath issues.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> James Reeves
>> booleanknot.com
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to call Clojure from Java?

2017-06-04 Thread Mark Bastian
I recently put together a project that demonstrates a few ways to call Clojure 
from Java:

https://github.com/markbastian/java-calls-clojure

Hope that helps.

-Mark

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to call Clojure from Java?

2017-06-01 Thread Daniel Compton
Hi thelmuth

Here's a fully worked example. It calls the Clojure function
myco.dashed-namespace.app.core/start!. Save it to
src/myco/dashed_namespace/app/Main.java.

package myco.dashed_namespace.app;

import clojure.java.api.Clojure;
import clojure.lang.IFn;

public class Main {
public static void main(String[] args) {
try {
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("myco.dashed-namespace.app.core"));

Clojure.var("myco.dashed-namespace.app.core", "start!").invoke();
}
catch (Throwable e) {
System.out.println(e.getMessage());
}
}
}


On Fri, Jun 2, 2017 at 1:24 PM James Reeves  wrote:

> There's a brief section on this on the Clojure website:
>
> https://clojure.org/reference/java_interop#_calling_clojure_from_java
>
> On 2 June 2017 at 01:35, thelmuth  wrote:
>
>> What is the best way to call a Clojure function from Java?
>>
>> Most of the resources I have found are either very old or don't go into
>> enough detail. I am a Clojure programmer with very little Java background,
>> and have been having trouble with the methods I've found, especially
>> classpath issues.
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> James Reeves
> booleanknot.com
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to call Clojure from Java?

2017-06-01 Thread James Reeves
There's a brief section on this on the Clojure website:

https://clojure.org/reference/java_interop#_calling_clojure_from_java

On 2 June 2017 at 01:35, thelmuth  wrote:

> What is the best way to call a Clojure function from Java?
>
> Most of the resources I have found are either very old or don't go into
> enough detail. I am a Clojure programmer with very little Java background,
> and have been having trouble with the methods I've found, especially
> classpath issues.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
James Reeves
booleanknot.com

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to call Clojure from Java?

2017-06-01 Thread thelmuth
What is the best way to call a Clojure function from Java?

Most of the resources I have found are either very old or don't go into 
enough detail. I am a Clojure programmer with very little Java background, 
and have been having trouble with the methods I've found, especially 
classpath issues.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.