Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

questions about Process and Runtime()

 
yi sun
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David, I will have a look at the two links..

 
yi sun
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic