Re: Importing gen-class classes from one namespace into another, like Java?

603 views
Skip to first unread message

Ryan Cole

unread,
Jan 26, 2013, 5:35:25 PM1/26/13
to clo...@googlegroups.com
I forgot to mention, I also tried replacing the dashes with underscores, in the import namespace in the core.clj file. Same error.

Ryan

On Saturday, January 26, 2013 4:21:24 PM UTC-6, Ryan Cole wrote:
I'm basically writing a jar to be used entirely from a Java application, in Clojure. I don't know if it's better to just use Java for this yet, or not. I'm experimenting, though.

I've got every namespace in my Clojure project compiling using AOT. In one namespace, I use gen-class to create a class. In another namespace, I need to create an instance of that class. Do I have to import that class like I would Java classes? I've tried several methods and I keep getting class not found exceptions.

Below is my pretty basic code:

core.clj
(ns com.rycole.bukkit-plugin.core
  (:import [com.rycole.bukkit-plugin.listeners PlayerLoginListener])
  (:gen-class :name com.rycole.bukkit-plugin.core.Main
              :extends org.bukkit.plugin.java.JavaPlugin))

(defn -onEnable [this]
  (.info (.getLogger this) "PLUGIN ENABLED")
  (.registerEvents (.getPluginManager (.getServer this)) (com.rycole.bukkit-plugin.listeners.PlayerLoginListener.) this))

(defn -onDisable [this]
  (.info (.getLogger this) "PLUGIN DISABLED"))

listeners.clj
(ns com.rycole.bukkit-plugin.listeners
  (:gen-class :name com.rycole.bukkit-plugin.listeners.PlayerLoginListener
              :implements org.bukkit.event.Listener
              :methods [[^{org.bukkit.event.EventHandler true} onPlayerLoggedIn [org.bukkit.event.PlayerLoginEvent] void]]))

(defn -onPlayerLoggedIn [this evnt]
  (.info (.getLogger this) "PLAYER LOGGED IN")) 

Meikel Brandmeyer

unread,
Jan 26, 2013, 5:53:01 PM1/26/13
to clo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

you have to add a (:require com.rycole.bukkit-plugin.listeners) before
you import the class. And you have to replace dashes with underscores
on import.

Kind regards
Meikel

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRBF5NAAoJEM2sO9pIirXjOIQP+wRl6ETFDq20FATfSIWL/Mc7
moWbX/rAu5czC5VAi2r5nBM5qALH6nWxW+yrzwMk3Tq/+SFd+DwAs3jTqhRIzNgF
RIHMkjRCDiux33aSznojpW9DgVDC/20piyfgMCBvIWcYFVr8OW1Xuj9Vm8NAOm9M
O6mVHU4C9vJ7a+SAt+UeaNrLeSQrrQTkBei5O2RkG9z89HNNmvLKfW4nr1xlTV2K
QNXIG3nScgMpiQZyQNvQ4OQT1bhajz6QuGUtnz778yVju+fzg4b3tPKQtSHza0Li
jL+pJbsl4T0tPzDIlX8wc2+NEhFYJopd4zWCNjL4rf1itVIXT+Q3gZmw6RD29O4u
u6+vVyNbZfuCTqc4vT3W8/ZijGSWi229yQ8AchEYUlJBd3K1FWTb8vrmyQhPYbM8
IMWJ44aw9wSW8RFyJ8ST3YJT7g/3/q2H9iEVu8gXE62Hcl7Gy4rvsXOj/qj+FNo4
vfLQfLSiOQXYxZTKJyFQSwSbf0RvJdsnVoZvJJ3iIgj0m26cGHW00elTpAt3oWdy
EBvNaqmukV/HmYouN1TcBExrUa6XP62nCzA6jgVKYgDbORzZ514A1CpTW0h+HUCa
rIaGGCJSZPxj3rKlHRPIqMMNIrvBV36UMysHikllrGimojoLORUVoLjVLJbzglJY
iR9C8Rv8pBnLOM/PwYn5
=2A1Z
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages