The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Swing & AWT

Thread: how to make a hidden java application in Mac

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 3 - Last Post: Jun 28, 2007 7:46 PM by: Joshua Marinacci
lewu

Posts: 4
how to make a hidden java application in Mac
Posted: Jun 27, 2007 3:00 PM
  Click to reply to this thread Reply

Hi

I want to create a java application for mac, but I do not want to show an application icon in the dock when this application is ruunig (I only want to show an icon in system tray). In the other word, this is an hidden java application. I can not find a solution via google, is there anyone can help me.

Best

Joshua Marinacci
Re: how to make a hidden java application in Mac
Posted: Jun 27, 2007 4:36 PM   in response to: lewu
  Click to reply to this thread Reply

This is a Mac specific thing. If you bundle your application as a
Mac only application (using a .app bundle) then you can set a
special flag in the Info.plist. See this tip:

http://www.macgeekery.com/gspot/2007-02/
hiding_applications_from_the_dock

This will work with any Mac application, not just Java ones.

- Josh

On Jun 27, 2007, at 3:00 PM, swing@javadesktop.org wrote:

> Hi
>
> I want to create a java application for mac, but I do not want to
> show an application icon in the dock when this application is
> ruunig (I only want to show an icon in system tray). In the other
> word, this is an hidden java application. I can not find a solution
> via google, is there anyone can help me.
>
> Best
> [Message sent by forum member 'lewu' (lewu)]
>
> http://forums.java.net/jive/thread.jspa?messageID=224351


marcel_castelo

Posts: 1
Re: how to make a hidden java application in Mac
Posted: Jun 28, 2007 11:51 AM   in response to: lewu
  Click to reply to this thread Reply

You can try something like this:

public class Test {

public static void main(String[] args) {

Test test = new Test();

if (args.length == 0) {
try {
test.reboot();
} catch (IOException e) {
e.printStackTrace();
}
} else if (args.length == 1 && args[0].equals("continue")) {
while (true) {
System.out.println("Time:"+System.currentTimeMillis());
}
}
System.exit(0);
}

public void reboot() throws IOException {
PrintStream log = null;

File logFile = new File("test.log");

log = new PrintStream(new FileOutputStream(logFile.toString(), true));

String[] command = new String[] { "java", "Test", "continue" };
final Process process = Runtime.getRuntime().exec(command);
new StreamProxy(process.getInputStream(), log).start();
process.getOutputStream().close();
}

public static class StreamProxy extends Thread {

InputStream in;
OutputStream out;

public StreamProxy(InputStream in) {
this(in, null);
}

public StreamProxy(InputStream in, OutputStream out) {
this.in = in;
this.out = out;
}

public void run() {
try {
PrintWriter pw = null;
if (out != null) {
pw = new PrintWriter(out);
}

BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = br.readLine()) != null) {
if (pw != null) {
pw.println(line);
}
//System.out.println("" + ">" + line);
}
if (pw != null) {
pw.flush();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}

Joshua Marinacci
Re: how to make a hidden java application in Mac
Posted: Jun 28, 2007 7:46 PM   in response to: marcel_castelo
  Click to reply to this thread Reply

This will work, but I'm pretty sure that the spawned Java process
will show up in the Dock on a Mac as soon as any code that uses the
AWT Toolkit is called (like a Frame or even just a graphics call).

- Josh

On Jun 28, 2007, at 11:51 AM, swing@javadesktop.org wrote:

> You can try something like this:
>
> public class Test {
>
> public static void main(String[] args) {
>
> Test test = new Test();
>
> if (args.length == 0) {
> try {
> test.reboot();
> } catch (IOException e) {
> e.printStackTrace();
> }
> } else if (args.length == 1 && args[0].equals("continue")) {
> while (true) {
> System.out.println("Time:"+System.currentTimeMillis());
> }
> }
> System.exit(0);
> }
>
> public void reboot() throws IOException {
> PrintStream log = null;
>
> File logFile = new File("test.log");
>
> log = new PrintStream(new FileOutputStream(logFile.toString(),
> true));
>
> String[] command = new String[] { "java", "Test", "continue" };
> final Process process = Runtime.getRuntime().exec(command);
> new StreamProxy(process.getInputStream(), log).start();
> process.getOutputStream().close();
> }
>
> public static class StreamProxy extends Thread {
>
> InputStream in;
> OutputStream out;
>
> public StreamProxy(InputStream in) {
> this(in, null);
> }
>
> public StreamProxy(InputStream in, OutputStream out) {
> this.in = in;
> this.out = out;
> }
>
> public void run() {
> try {
> PrintWriter pw = null;
> if (out != null) {
> pw = new PrintWriter(out);
> }
>
> BufferedReader br = new BufferedReader(new InputStreamReader(in));
> String line;
> while ((line = br.readLine()) != null) {
> if (pw != null) {
> pw.println(line);
> }
> //System.out.println("" + ">" + line);
> }
> if (pw != null) {
> pw.flush();
> }
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
> }
> }
> }
> [Message sent by forum member 'marcel_castelo' (marcel_castelo)]
>
> http://forums.java.net/jive/thread.jspa?messageID=224552

- Blasting forth in three part harmony!


[att1.html]





 XML java.net RSS