Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

questions about Process and Runtime()

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 74776
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic