tags:

views:

74

answers:

1

Jar is a convenient way to use java, as every class can be included in one jar.

I use antlr as follows, and it calls jar using -jar option.

java -jar $ANTLRDIR/antlr-3.2.jar ANTLR_CODE.g

And, this is the command that calls clojure. Instead of calling clojure.jar using -jar option. It's in the -cp, and calls some 'function'.

java -cp $CLOJURE_JAR:$CLASSPATH clojure.lang.Script CLOJURE_CODE.clj

Questions

  • What's the magic behind this method? What's 'clojure.lang.Script'?
  • Can the antlr be called with the same way? If so what's the name that should be used (something like clojure.lang.Script)?
  • How about the jar file made with other languages : clojure/scala? How do I know the name that should be called?
  • What's the difference between the two methods? Pros and cons?
+5  A: 

•What's the magic behind this method? What's 'clojure.lang.Script'?

clojure.lang.Script is the class with the main method that the jar executable is running.

•Can the antlr be called with the same way? If so what's the name that should be used (something like clojure.lang.Script)?

The antlr jar can be called the same way. You have to know the name of the main class (which is in the MANIFEST.MF file in the jar.)

•How about the jar file made with other languages : clojure/scala? How do I know the name that should be called?

I don't know... Probably depends on the language.

•What's the difference between the two methods? Pros and cons?

Executable jars are very easy for users to launch (especially in Windows). Just a double click on the jar file.

•In this post, I was told that -jar ignores all the -cp and $CLASSPATH. Why is this? Is there any reason for this?

No doubt the Sun guys did this for security reasons.

•I was also told -cp option also ignores the $CLASSPATH. Why is this? Is there any good reason for this?

The -cp option overrides the $CLASSPATH. That's the whole purpose of this option.

Starkey
-cp overrides, but wouldn't this syntax explicitly include it?
aepryus
Yes, since he includes $CLASSPATH in his -cp, it would include his $CLASSPATH. The purpose of the -cp $CLOJURE_JAR:$CLASSPATH is that anything in the clojure jar is first before anything else in the classpath.
Starkey