   with the java task right before executing if you need to customize any of its
   properties (classpath, library-path, etc)."
   [project form & [handler]]
-  (let [java (Java.)]
+  (let [java (Java.)
+        native-path (or (:native-path project)
+                        (find-native-lib-path project))]
     (.setProject java lancet/ant-project)
     (.addSysproperty java (doto (Environment$Variable.)
                             (.setKey "clojure.compile.path")
                             (.setValue (:compile-path project))))
-    (when-let [path (or (:native-path project)
-                        (find-native-lib-path project))]
-      (.setFork java true)
+    (when native-path
       (.addSysproperty java (doto (Environment$Variable.)
                               (.setKey "java.library.path")
                               (.setValue (cond
-                                          (= java.io.File (class path))
-                                          (.getAbsolutePath path)
-                                          (fn? path) (path)
-                                          :default path)))))
+                                          (= java.io.File (class native-path))
+                                          (.getAbsolutePath native-path)
+                                          (fn? native-path) (native-path)
+                                          :default native-path)))))
     (.setClasspath java (apply make-path
                                (:source-path project)
                                (:test-path project)
                                (:compile-path project)
                                (:resources-path project)
                                (find-lib-jars project)))
+    (when (or (= :macosx (get-os)) native-path)
+      (.setFork java true)
+      (doseq [arg (get-jvm-args)]
+        (.setValue (.createJvmarg java) arg)))
     (.setClassname java "clojure.main")
     (.setValue (.createArg java) "-e")
     (.setValue (.createArg java) (prn-str form))

  (filter #(.endsWith (.getName %) ".jar")
          (file-seq (file (:library-path project)))))

(def native-dir-names
     {"Mac OS X" "macosx"
      "Windows" "windows"
      "Linux" "linux"
      "SunOS" "solaris"
      "amd64" "x86_64"
      "x86_64" "x86_64"
      "x86" "x86"
      "i386" "x86"
      "arm" "arm"
      "sparc" "sparc"})

(defn get-native-dir-name
  "Gets a value from the native-dir-names map, but uses a regex
  to check the prop-value for a match against keys instead of just
  doing a map lookup. Reason for this is that e.g. windows may
  report different names for different OS versions but will likely
  always contain the string 'Windows'"
  [prop-value]
  (native-dir-names
   (first (drop-while #(nil? (re-find (re-pattern %) prop-value))
                      (keys native-dir-names)))))

(defn find-native-lib-path
  "Returns a File representing the directory where native libs for the
  current platform are located."
  [project]
  (let [osdir (get-native-dir-name (System/getProperty "os.name"))
        archdir (get-native-dir-name (System/getProperty "os.arch"))
        f (file "native" osdir archdir)]
    (if (.exists f)
      f
      nil)))

(defn make-path
  "Constructs an ant Path object from Files and strings."

        [leiningen.deps :only [deps]])
  (:refer-clojure :exclude [compile])
  (:import org.apache.tools.ant.taskdefs.Java
           java.lang.management.ManagementFactory
           (org.apache.tools.ant.types Environment$Variable Path)))

(defn namespaces-to-compile
