Java in MAC OS

Discussion in 'Mac Programming' started by chidambaram, Apr 17, 2009.

  1. macrumors member

    Joined:
    Mar 9, 2008
    #1
    Hai,

    I am trying to create a application file in mac, using the below code.

    Code:
    
    FileOutputStream fout;	
    try		
    {		   
     fout = new FileOutputStream("/Users/laserwords/Desktop/fileopening.app");   		
      new PrintStream(fout).println ("tell application \"Finder\" \n set myFil to \"Macintosh HD:sample1.pdf\" as string	open file myFil \nend tell");		 
       fout.close();		
    }	
    catch (IOException e)	
    {	
    		System.err.println ("Unable to write to file");
    	
    		System.exit(-1);	
    }
    Above mentioned application file is created, But its type is, created as
    Application (Classic).

    So that file is, not executable.

    If we manually create, it is working properly.

    Can anyone help to resolve this?

    Thanks in advance.
     
  2. macrumors newbie

    Joined:
    Apr 15, 2009
    #2
    a stacktrace.

    How do you manually create it? I assume you need to set the umask to the file or even set some attributes to it.
    Ast this is mac specific java may not be the right choice to create those files, as the option should also be avaible on windows.

    plz ignore previous post as it was a matter of not reading the question..
    j.
     
  3. macrumors newbie

    Joined:
    Apr 15, 2009
    #3
    Giving it a second or rather third thought:
    grab a terminal, cd to the directory you're manuall creating the file in. And do a
    Code:
    ls -l@
    (assuming you're doing leopard).
    You than need to figure out how to get java created file, have the same umask and attributes as the manually created file.
    You than should use java.lang.Runtime to modify this file.
    Hope this helps.
     
  4. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #4
    I open the script editor, Typed this

    Code:
    tell application "Finder" 
     set myFil to "Macintosh HD:sample1.pdf" as string
    open file myFil end tell
    Saved this as,
    fileopen.app


    If i double click the file "fileopen.app", it will open ,sample1.pdf

    it is just like a bat file in Windows.
     
  5. macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #5
    The problem is that AppleScripts aren't plain text, but rather a cryptic binary format.
     
  6. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #6
    Thanks for your reply,

    is it possible to change plain text into cryptic binary format.

    So that it will be executable....
     
  7. macrumors 6502

    Joined:
    Sep 15, 2006
    #7
    the best alternative would be to download eclipse or netbeans, import the code and then export it as a runnable jar file with the main entry point to be the file you defined your "public static void main"... ... it'll be a .jar and not a .app, but it will do the trick and work just as well.
     
  8. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #8
    Hi,

    Thanks for ur reply.

    Actually my requirement to open a pdf file using java program. I installed netbeans in my Mac Machine.

    Without using this type of batch file ,can i open that file in any other way?
     
  9. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #9
    Use /usr/bin/open:
    Code:
    open -a ~/Desktop/fileopening.app /sample1.pdf
     

Share This Page