Win a copy of Learning Regular Expressions this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Loading an application from a Java Program  RSS feed

 
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!
 
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 ]
 
Sheriff
Posts: 9087
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!