permaculture playing cards*
The moose likes Java in General and the fly likes questions about Process and Runtime() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "questions about Process and Runtime()" Watch "questions about Process and Runtime()" New topic
Author

questions about Process and Runtime()

yi sun
Greenhorn

Joined: Aug 08, 2010
Posts: 6
Hi All,

I'm new to java. Here is what I was trying to do:

I have a java application, a scala script and a jar library.
The Java application is a Jframe application.
THe scala script simply adds a button to a JFrame.
The jar library is just a normal java class contains a HashMap<String, JFrame>.
I imported this jar file to my java application and my scala script also has reference to it.

What I need to achieve is when the java application starts, it set the HashMap <"main",frame> and then execute the scala script. the script reads the HashMap and retrieve the JFrame from the Hashmap and then add a button to the retrieved JFrame.

The java program successfully put the jframe into the Hashmap. I use Runtime.getRuntime().exec to run the scala script but the script reads "null" from the Hashmap.

Is this because the scala script is running in a separate process? please could anyone advise how could achieve what I need? Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You may be able to use the Scala class directly; it depends on what functionality it uses.

It's easier to use Java from Scala than vice-versa.

http://www.scala-lang.org/faq/4#4n291
yi sun
Greenhorn

Joined: Aug 08, 2010
Posts: 6
Thanks. The reason why I did not use scala class directly is because I want to make the Java application configurable.. i.e. if the scala script exists in a certain directory, the java program executes it and then the scala script adds a button to the java application. if the script does not exist in the directory, the java program will not do anything...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you're using Java 6 you should be able to do this through the standard Java scripting engine, although I haven't done it myself.

http://code.google.com/p/netgents/downloads/list
http://people.apache.org/~mduerig/scala4scripting/

I'm not convinced that Scala's a great scripting language, though--is there a particular reason you want to script in Scala rather than a better-supported language like JavaScript, Groovy, etc.?
yi sun
Greenhorn

Joined: Aug 08, 2010
Posts: 6
Thanks David, I will have a look at the two links..

yi sun
Greenhorn

Joined: Aug 08, 2010
Posts: 6
I've got it work using java standard scripting engine and javascript. the scala scripting engine in the above link does not seem to work properly...

Thanks David
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
And welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: questions about Process and Runtime()