Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading an application from a Java Program  RSS feed

 
Flo Powers
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am wondering how difficult (or possible?) it is to load a webpage from a CLI program written in Java. I am imagining a menu based program, where the user can enter a URL as a String, whereupon the program loads the default browsers (or a particular browser for that matter) and directs it to the entered URL.

I tried searching the forums for this, but may have entered the wrong search criteria as I came up with nothing.

Thanks!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never tried this myself, but I think you will want to look at the ProcessBuilder class (new with Java 1.5) and/or the exec method in the Runtime class. Searching for examples using these should get you headed in the right direction.

EDIT: I found this Sun Developer tip comparing Runtime.exec and ProcessBuilder. Hope it helps.
[ February 05, 2006: Message edited by: marc weber ]
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Flo Powers:
I am imagining a menu based program, where the user can enter a URL as a String, whereupon the program loads the default browsers (or a particular browser for that matter) and directs it to the entered URL.


One problem might be that Java wouldn't know what the default browser is as it is OS independent. I've written an applet that takes a URL and directs the browser to that URL. I imagine that you would probably, at least, have to write code to start the browser of your choice using the exec() method.
[ February 05, 2006: Message edited by: Marilyn de Queiroz ]
 
Flo Powers
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for the replies. I've managed to make the program load the browser, but am unsure about the part that directs the browser to a particular URL. The program inputs from the user a URL as a String. I guess what I'm looking for is the DOS command to load a web browser and direct it to a particular URL...

Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!