Complete newbie question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Complete newbie question

loial-3
Having come from a pure python background, trying to understand jython and java
 
Why does this work :
 
$JAVA_HOME/bin/java -jar jython-2.5.3.jar hello.py
hello
 
But not this :
 
CLASSPATH=jython-2.5.3.jar
export CLASSPATH
 
$JAVA_HOME/bin/java -cp $CLASSPATH hello.py
Error: Could not find or load main class hello.py
The jar file is in the current directory.
 
hello.py contains
 
def main():
    print "hello"
if __name__ == '__main__':
    main()
 
Any help appreciated. Please be gentle!

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Complete newbie question

Johan Van Noten

Hi John,

 

When launching a Java application, Java is looking for a main class.

There are two ways to provide this main class:

·         Either specify it directly on the command-line:
java myMainClass

·         Either specify a jar (whose manifest points to the main class):
java –jar myJarFile.jar

(see https://docs.oracle.com/javase/tutorial/deployment/jar/run.html for some background)

 

In your second example, you are just providing jython as a library on the classpath.

This instructs Java to browse through that library for any required classes.

You don’t specify though which class it should be executing.

 

Johan

 

Van: John Dunn [mailto:[hidden email]]
Verzonden: woensdag 26 november 2014 17:26
Aan: [hidden email]
Onderwerp: [Jython-users] Complete newbie question

 

Having come from a pure python background, trying to understand jython and java

 

Why does this work :

 

$JAVA_HOME/bin/java -jar jython-2.5.3.jar hello.py

hello

 

But not this :

 

CLASSPATH=jython-2.5.3.jar
export CLASSPATH

 

$JAVA_HOME/bin/java -cp $CLASSPATH hello.py
Error: Could not find or load main class hello.py

The jar file is in the current directory.

 

hello.py contains

 

def main():
    print "hello"

if __name__ == '__main__':
    main()

 

Any help appreciated. Please be gentle!


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users