Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2006

Tip: Looking for answers? Try searching our database.

starting java

Thread view: 
Jean Pierre Daviau - 22 Dec 2006 10:49 GMT
Hi everybody,

There is no problem to start an application on windows (at least for me).
How do you start an appication on Unix and on Mac?
Is ther few lines of code I can get like it is on windows?
I have a friend who has a Mac. I sent her an application but her Mac does
not know how to start it . I found this

--------- start.sh  -------
#!/bin/sh
java -cp . myApplication
--------- end start.sh  -------

Signature

Thanks for your attention.

Jean Pierre Daviau
--
windows Xp
asus p4 s533/333/133
Intel(R) Celeron (R) CPU 2.00 GHz
Processor Radeon7000 0x5159 agp

Steve W. Jackson - 22 Dec 2006 15:35 GMT
> Hi everybody,
>
[quoted text clipped - 8 lines]
> java -cp . myApplication
> --------- end start.sh  -------

You haven't provided anywhere near enough information to give a
definitive answer.

The above command line only works if "myApplication.class" exists in the
directory where it's executed.  That's true on Unix systems.  And the
modern Mac OS X system is based on BSD, so that it can work there as
well if your friend is willing to go into the Terminal program and type
the command at the right location.  Most Mac users, however, aren't
familiar with this environment.

You need to provide more details.  Better still, you should package up
your application, perhaps putting it into a jar file.  I can assure you
that her Mac will know how to launch that if it's designed to be self
contained -- though it won't be all that pretty.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Jean Pierre Daviau - 22 Dec 2006 18:48 GMT
> The above command line only works if "myApplication.class" exists in the
> directory where it's executed.  That's true on Unix systems.  And the
> modern Mac OS X system is based on BSD, so that it can work there as
> well if your friend is willing to go into the Terminal program and type
> the command at the right location.  Most Mac users, however, aren't
> familiar with this environment.

The jar is signed and clickable: at least on windows
-------------------------------------------------------
// File:  SendMailDelayed.java - A tiny application
import java.io.*;
import java.lang.Character;
import sun.net.smtp.*;
import java.util.Properties;

public class PosteProps {
 static String sTO = "daviaujp@videotron.ca";
 static String subj = "Java System Information";
 static String message;
 static File file;

 public static void main (String[] args)throws Throwable {
   getData();
   System.out.println();
   System.out.println("Sending EMail...");
   if (SendMailDelayed(getData()))
     System.out.println("EMail sent...");
   else
     System.out.println("Trouble sending your EMail...");
   System.out.println();
 }

 static public String getData() throws IOException {
   int i = 2000;
   InputStream in2 = null;
   char byteArray[] = new char[i];
   StringBuffer strbuf = new StringBuffer();
   Properties sysprops = System.getProperties();

   strbuf.append(sysprops);

   for (int j = 0;j < strbuf.length() ;j++ ) {
     if (strbuf.charAt(j) == ',') {
       j++;
       strbuf.insert(j, "<br>");
     }
   }
   String liste = strbuf.toString();
   System.out.println (liste);
   return liste;
 }
 static boolean SendMailDelayed (String texte) {
   boolean bSuccess = true;
   try {
     String sFROM = "videotron.ca";
     System.out.println (getData());
     System.out.println("Beginning to send...");
     SmtpClient smtp = new SmtpClient(".ca");
     smtp.from(sFROM);
     smtp.to(sTO);
     PrintStream msg = smtp.startMessage();
     msg.print("From: Jean Pierre Daviau\n");
     msg.print("Subject: " + subj + "\n");
     //msg.print("To: You\n");
     msg.println("Content-Type: text/html");
     msg.println("");
     msg.println("");

     msg.println(texte);
     msg.println("");
     smtp.closeServer();
     System.out.println("Success:  EMmail sent to: " + sTO);
   } catch (java.net.UnknownHostException e) {
     System.out.println(e);
     System.out.println("  probably caused by bad host name, not connected
to the Internet,...");
     bSuccess = false;
   } catch (IOException e) {
     System.out.println(e);
     bSuccess = false;
   }
   return bSuccess;
 }
}
Steve W. Jackson - 22 Dec 2006 19:28 GMT
> > The above command line only works if "myApplication.class" exists in the
> > directory where it's executed.  That's true on Unix systems.  And the
[quoted text clipped - 4 lines]
>
> The jar is signed and clickable: at least on windows

[ code snipped ]

What's in the code isn't relevant to the question you raised.

Your original question asked whether "java -cp . myApplication" would
work.  It won't unless myApplication.class is present in the directory
where this command is issued.

If the application in question is inside a jar file (signed or not) with
a proper manifest that identifies its main class, then double clicking
works on Windows and in Mac OS X.  But because of the difference in the
Mac's interface, it won't look too pretty.

If your Mac-using friend is comfortable enough to use a command line,
she could instead use "java -jar JarFileName.jar" if it's got a proper
manifest.  If not, then the name of any class inside with a proper main
method can be used with "java -cp JarName.jar ClassName".

What you might notice is that what I just described is *precisely* the
same as it works on Windows systems.

When you install Java on Windows, the installer usually gives you a file
association for jar files that causes "javaw -jar filename" to get
invoked so that double-clicking works -- except it'll fail if there's
not a proper manifest.  The very same is true in Mac OS X.

Other Unix systems (including Linux) may or may not have a graphical
mechanism like the double-click available, depending on configuration.  
The command line technique should work equally for all.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Jean Pierre Daviau - 22 Dec 2006 20:12 GMT
Greg R. Broderick - 23 Dec 2006 17:21 GMT
>> The above command line only works if "myApplication.class" exists in
>> the directory where it's executed.  That's true on Unix systems.  And
[quoted text clipped - 8 lines]
> import java.io.*;
> import java.lang.Character;

// [grb] directly using sun.* packages is generally a Very Bad Idea(tm)!
> import sun.net.smtp.*;
> import java.util.Properties;
[quoted text clipped - 38 lines]
>     boolean bSuccess = true;
>     try {

// [grb] BAD, WRONG, etc.:  this is not a valid email address, as required by
RFC 2821, section 4.1.1.2
>       String sFROM = "videotron.ca";

// [grb] you're calling getData() a second time here, why not just println
(texte), which contains the value passed into the method, from the prior
invocation of the getData() method.
>       System.out.println (getData());
>       System.out.println("Beginning to send...");

// [grb]  if the parameter ".ca" is intended to be the hostname used in the
HELO/EHLO SMTP greeting, then it is not valid, insofar as it is not a valid
FQDN.  C.f. RFC2821, section 4.1.1.1

// [grb] ??? where / how to you specify the hostname / IP address of the SMTP
server to which your SmtpClient is supposed to connect?  I don't see this
anywhere in your code.
>       SmtpClient smtp = new SmtpClient(".ca");
>       smtp.from(sFROM);
[quoted text clipped - 24 lines]
>  }
>}

Somewhat off-topic, the messages that your code is sending are not compliant
with RFC 2822, because they do not contain the required "Date:" header.

Your code is also not compliant with RFC 2821 (SMTP) as the "email address"
that you have specified

For MIME, you also need more than just the "Content-Type:" header.  You need
at least:

MIME-Version: 1.0
and
Content-transfer-encoding:

Furthermore, if your message contains eight bit data (very likely, if you're
using accented characters), you will need to encode it to be seven-bit,
because SMTP only guarantees seven-bit data transmission.  The two popular
methods of encoding are QP (quoted-printable) and base64.

I'd personally recommend that you use something such as JavaMail instead of
attempting to do this all yourself.

Cheers!
GRB

Signature

---------------------------------------------------------------------
Greg R. Broderick            gregb+usenet200612@blackholio.dyndns.org

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------

Jean Pierre Daviau - 24 Dec 2006 17:51 GMT
// File:  SendMailDelayed.java - A tiny application that sends an EMail
message using SMTP
// A superior way to send (and receive) EMail is to use Sun's JavaMail
support
// But, that is far more complex...  and requires downloading additional
libraries
// So, for now, this tiny example should suffice

/*  Furthermore, if your message contains eight bit data (very likely, if
you're
using accented characters), you will need to encode it to be seven-bit,
because SMTP only guarantees seven-bit data transmission.  The two popular
methods of encoding are QP (quoted-printable) and base64.  */
/*

import java.io.*;
import java.lang.Character;
import sun.net.smtp.*; // Note that sun.net.* packages are UNSUPPORTED
import java.util.Properties;
import java.util.Date;

public class PosteProps {
 static String sTO = ".ca";
 static String subj = "Java System Information";
 static String message;
 static File file;

 public static void main (String[] args)throws Throwable {
   System.out.println();
   System.out.println("Sending EMail...");
   if (SendMailDelayed(getData()))
     System.out.println("EMail sent...");
   else
     System.out.println("Trouble sending your EMail...");
   System.out.println();
 }

 static public String getData() throws IOException {
   int i = 2000;
   InputStream in2 = null;
   char byteArray[] = new char[i];
   StringBuffer strbuf = new StringBuffer();
/*
final String separator = System.getProperty(line.separator);
final int separatorLength = separator.length();

for (int j=0;j<strbuf.length() ;j++ )
{
 if(strbuf.charAt(j) == ','){
  strbuf.insert(j, separator);
  j += separatorLength;
 }
}

*/
   Properties sysprops = System.getProperties();

   strbuf.append(sysprops);

   for (int j = 0;j < strbuf.length() ;j++ ) {
     if (strbuf.charAt(j) == ',') {
       j++;
       strbuf.insert(j, "<br>");
     }
   }

   String liste = strbuf.toString();

   System.out.println (liste);

   return liste;
 }

 static boolean SendMailDelayed (String texte) {
   boolean bSuccess = true;
// [grb] directly using sun.* packages is generally a Very Bad Idea(tm)!
   try {
     String sFROM = "vidn.ca";
     System.out.println("Beginning to send...");
     SmtpClient smtp = new SmtpClient(".ca");
     smtp.from(sFROM);
     smtp.to(sTO);
     PrintStream msg = smtp.startMessage();
     //msg.setText(msg, "fr-ascii");//us-ascii  deleteMe
/* msg.println(new Date().toString());*/
    msg.println("MIME-Version: 1.0");
  msg.println("Content-transfer-encoding: CHARSET=ISO-8859-1");

     msg.println("Content-Type: text/html");
     msg.print("From: Jean Pierre Daviau\n");
     msg.print("Subject: " + subj + "\n");
     msg.print("To: You\n");

     msg.println("éàô££££");
     msg.println("");

     msg.println(texte);
     msg.println("");
     smtp.closeServer();
     System.out.println("Success:  EMmail sent to: " + sTO);
   } catch (java.net.UnknownHostException e) {
     System.out.println(e);
     System.out.println("  probably caused by bad host name, not connected
to the Internet,...");
     bSuccess = false;
   } catch (IOException e) {
     System.out.println(e);
     bSuccess = false;
   }
   return bSuccess;
 }
}

=============
Why does it work?

I took off the personnal  informatons

Received: from jean-pier([66.131])
by VL-MH-MR002.ip.videotron.ca
(Sun Java System Messaging Server 6.2-2.05 (built Apr 28 2005))
with SMTP id <0JAS0089Avtron.ca> for
.ca; Sun, 24 Dec 2006 12:45:17 -0500 (EST)
Date: Sun, 24 Dec 2006 12:45:17 -0500 (EST)
Date-warning: Date header was inserted by VL-MH-MR002.ip.videotron.ca
From: Jean Pierre Daviau
Subject: Java System Information
To: .ca
Message-id: <0JAS0089CHMH-.ca>
MIME-version: 1.0
Content-type: text/html
*/
___
éàô££££ {user.language=fr,
java.home="C:\Program Files\Java\jre1.5.0",
etc.
---
JPD
Greg R. Broderick - 24 Dec 2006 20:32 GMT
"Jean Pierre Daviau" <Once@WasEno.ugh> wrote in news:V6zjh.10062$Ld4.127448
@wagner.videotron.net:

> Why does it work?

Because the particular mail server that you're using is obeying one of the
prime principles of the Internet, "Be liberal in what you accept and
conservative in what you produce.", and is accepting your broken email,
which you should not be producing.

Not all mail systems will necessarily be so accepting of broken emails such
as yours, therefore it is highly recommended that you follow the published
Internet Standards documents to the absolute best of your ability to do so.    
This will insure maximum interoperability.

Cheers
GRB

Signature

---------------------------------------------------------------------
Greg R. Broderick            gregb+usenet200612@blackholio.dyndns.org

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.