Help...problems using java comm API

Hi all
im using Fedora Core and in order to list all the available serial ports for my computer i'm using the classic program TestEnumeration, but when running from jbuilder 2005 not from shell i received the following errors:
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path
Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver
warning: no ports found - make sure javax.comm.properties file is found
i have followed all the instruction to install comm API but i received the same error i need help plz if someone can
thx

import java.io.*;
import java.util.*;
import javax.comm.*;
import java.lang.*;
import java.Buff.*;
public class SimpleRead implements Runnable, SerialPortEventListener
     static CommPortIdentifier portId;
     static Enumeration portList;
     InputStream inputStream;
     SerialPort serialPort;
     Thread readThread;
     public static void main(String[] args)
     {//System.out.println("hello");
          portList = CommPortIdentifier.getPortIdentifiers();
          while (portList.hasMoreElements())
               portId = (CommPortIdentifier) portList.nextElement();
               if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
          if (portId.getName().equals("COM1"))
               // if (portId.getName().equals("/dev/term/a")) {
          SimpleRead reader = new SimpleRead();
     public SimpleRead()
     try
          serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
     catch (PortInUseException e)
                              System.out.println(e);
     try
     inputStream = serialPort.getInputStream();
     catch (IOException e)
                    System.out.println(e);
               try
serialPort.addEventListener(this);
               catch (TooManyListenersException e)
                    System.out.println(e);
     serialPort.notifyOnDataAvailable(true);
     try
     serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
          catch (UnsupportedCommOperationException e)
                    System.out.println(e);
try {
out = new OutputStreamWriter(serialPort.getOutputStream());
out.write("ATQ0V1E0");
out.flush();
out.write("ATQ0V1E0");
Out.close();
//System.out.println("ATQ0V1E0");
catch (IOException e) {}
try {
int line;
int result ;
InputStream = serialPort.getInputStream();
int num= inputStream.available();
InputStreamReader reader = new InputStreamReader(inputStream);
System.out.println(reader.ready());
while ((line = reader.read()) <= 0)
result =reader.read();
System.out.println("Success " + result);
reader.close();
catch (IOException e) {}
readThread = new Thread(this);
readThread.start();
try {
OutputStream = SerialPort.getOutputStream();
catch (IOException e) {}
          System.out.println("ATQ0V1E0");
public void run()
     try
Thread.sleep(500);
catch (InterruptedException e)
               System.out.println(e);
public void serialEvent(SerialPortEvent event)
switch(event.getEventType())
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try
while (inputStream.available() > 0)
int numBytes = inputStream.read(readBuffer);
System.out.print(new String(readBuffer));
catch (IOException e)
                    System.out.println(e);
break;
hi friends am getting these errors
C:\programs>javac SimpleRead.java
SimpleRead.java:115: illegal start of expression
public void run()
^
SimpleRead.java:159: ';' expected
^
2 errors
please help me....
its very urgent....this is the first program of mine.... am so tensed..
i should finish this soon... please help me...
this is my mail ID
[email protected]

Similar Messages

  • Problem in Accessing serial port using java comm Api

    I have installed java comm Api in my pc.
    i have gone through the instalation instruction which comes on this package.
    I have done the instalation like this
    Copy win32com.dll to my <JDK>\bin directory.
    Copy comm.jar to my <JDK>\lib directory.
    Copy javax.comm.properties to my <JDK>\lib directory.
    and restart the system.
    But when i run the BlackBox , it is giving me message
    "serial port not found".
    Can any one tell me , what is the exact problem ?

    I'm not sure what you mean by BlackBox, but I have used the COMM api extensively.
    The majority of problems is that the api cannot see the serial port (which is what you are describing) and this is caused by incorrect placing of the javax.comm.properties file.
    As well as <JDK>\lib, try putting it into <JRE>\lib as well. That has often solved problems on my setup.

  • Problem using Java Mail API with WLS 7.0

    Hi All,
    I am trying to use the Java Mail API provided by WLS 7.0. I have made the
    settings metioned in the WLS 7.0 docs. However when I try to run the program I
    am getting the following error:
    javax.naming.NoInitialContextException: Need to specify class name in environment
    or system property, or as an applet parameter, or in an application resource file:
    java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    46)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
    a:283)
    at javax.naming.InitialContext.lookup(InitialContext.java:350)
    The code that I have written is as follows
    import java.util.*;
    import javax.activation.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.naming.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    public class MailTo {
         public static void main(String args[])
              try
                   //Context ic = getInitialContext();
                   InitialContext ic = new InitialContext();
    /* My jndi name is "testSession" */
                   Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
    IN THIS LINE */
                   Properties props = new Properties();
                   props.put("mail.transport.protocol", "smtp");
                   props.put("mail.smtp.host", "XX.XX.XX.XX");
    /* For security reasons I have written the ip add in this format */
                   props.put("mail.from", "[email protected]"); /* for security reasons i have
    changed the mail address */
                   Session session2 = session.getInstance(props);
                   Message msg = new MimeMessage(session2);
                   msg.setFrom();
                   msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
    false));
                   msg.setSubject("Test Message");
                   msg.setSentDate(new Date());
                   MimeBodyPart mbp = new MimeBodyPart();
                   mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
                   Multipart mp = new MimeMultipart();
                   mp.addBodyPart(mbp);
                   msg.setContent(mp);
                   Transport.send(msg);
              catch(Exception e)
                   e.printStackTrace();
         }//end of main
    public static Context getInitialContext()
         throws NamingException
              Properties p = new Properties();
              p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
              p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
                   p.put(Context.SECURITY_PRINCIPAL, "weblogic");
                   p.put(Context.SECURITY_CREDENTIALS, "weblogic");
              return new InitialContext(p);
    }//end of class
    Can anyone please tell me what is the problem. I thought that we cannot directly
    do
    InitialContext ic = new InitialContext();
    So I had written a method getInitialContext() as shown in the above piece of code,
    but that too did not work.
    Eagerly awaiting a response.
    Jimmy Shah

    You can use InitialContext ic = new InitialContext() only if you are using a startup class, servlet or a JSP i.e
    server side code.
    If you are using a java client you need to use Context ic = getInitialContext();
    Try this code
    import java.util.*;
    import javax.activation.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.naming.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    public class MailTo {
    public static void main(String args[])
    try {
    Properties h = new Properties();
    h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    h.put(Context.PROVIDER_URL, "t3://localhost:7001");
    Context ic = new InitialContext(h);
    Session session = (Session) ic.lookup("testSession");
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", "XX.XX.XX.XX");
    props.put("mail.from", "[email protected]");
    Session session2 = session.getInstance(props);
    Message msg = new MimeMessage(session2);
    msg.setFrom();
    msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false));
    msg.setSubject("Test Message");
    msg.setSentDate(new Date());
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp);
    msg.setContent(mp);
    Transport.send(msg);
    catch(Exception e)
    e.printStackTrace();
    }//end of main
    }//end of class
    We have shipped a javamail example in the samples\server\src\examples\javamail folder.
    Jimmy Shah wrote:
    Hi All,
    I am trying to use the Java Mail API provided by WLS 7.0. I have made the
    settings metioned in the WLS 7.0 docs. However when I try to run the program I
    am getting the following error:
    javax.naming.NoInitialContextException: Need to specify class name in environment
    or system property, or as an applet parameter, or in an application resource file:
    java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    46)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
    a:283)
    at javax.naming.InitialContext.lookup(InitialContext.java:350)
    The code that I have written is as follows
    import java.util.*;
    import javax.activation.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.naming.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.Properties;
    import java.util.Date;
    public class MailTo {
    public static void main(String args[])
    try
    //Context ic = getInitialContext();
    InitialContext ic = new InitialContext();
    /* My jndi name is "testSession" */
    Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
    IN THIS LINE */
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", "XX.XX.XX.XX");
    /* For security reasons I have written the ip add in this format */
    props.put("mail.from", "[email protected]"); /* for security reasons i have
    changed the mail address */
    Session session2 = session.getInstance(props);
    Message msg = new MimeMessage(session2);
    msg.setFrom();
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
    false));
    msg.setSubject("Test Message");
    msg.setSentDate(new Date());
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp);
    msg.setContent(mp);
    Transport.send(msg);
    catch(Exception e)
    e.printStackTrace();
    }//end of main
    public static Context getInitialContext()
    throws NamingException
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
    p.put(Context.SECURITY_PRINCIPAL, "weblogic");
    p.put(Context.SECURITY_CREDENTIALS, "weblogic");
    return new InitialContext(p);
    }//end of class
    Can anyone please tell me what is the problem. I thought that we cannot directly
    do
    InitialContext ic = new InitialContext();
    So I had written a method getInitialContext() as shown in the above piece of code,
    but that too did not work.
    Eagerly awaiting a response.
    Jimmy Shah--
    Rajesh Mirchandani
    Developer Relations Engineer
    BEA Support

  • How to use java comm API in 64 bit javn on solaris 10

    hi,
    I want to connect to a device through serial port on sparc Solaris 10 in 64-Bit JVM, but i cannot find the correct API for that, i have tried using RXTX but it has many issues.
    I noticed SUNWjcomx package is removed in Solaris 10.
    Please some one help

    hi,
    I want to connect to a device through serial port on sparc Solaris 10 in 64-Bit JVM, but i cannot find the correct API for that, i have tried using RXTX but it has many issues.
    I noticed SUNWjcomx package is removed in Solaris 10.
    Please some one help

  • Deploying Java Comm API

    Hi,
    I am developing an applet which uses Java Comm API. I'm running into some deployment issue. My understanding is that Java Comm API needs to have win32com.dll and javax.comm.properties files installed on the client machine for my applet to use Comm API. Is there a way around this? The ideal way will be to have everything (win32com.dll and javax.comm.properties) in a jar file so that it doesn't need to install any file on the client machine. However looking at previous posts, I don't think that's possible with Java Plug-in. Will I be able to utilize Java WebStart to accomplish this? I'll be interested to find how other people deploy Java Comm API. Thanks in advance.
    Regards,
    Joy

    I�ve developed a solution to this problem. I created a class that creates the javax.comm.properties file where the comm.jar lib looks for it. The trick is to run the method that creates the file before the lib looks for it.
    I show you the example of my code:
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    public final class PrinterInit {
        public static void printerInit(){
            String archivoConf =
                System.getProperty("java.home") + File.separator + "lib" +
                File.separator + "javax.comm.properties";
            try {
                BufferedWriter out = new BufferedWriter(new FileWriter(archivoConf));
                out.write(
                    "#"+ "\n" +
                    "# Drivers loaded by the Java Communications API standard extension"+ "\n" +
                    "# at initialization time "+ "\n" +
                    "# "+ "\n" +
                    "# Format: "+ "\n" +
                    "#   Each line must contain ONE driver definition only "+ "\n" +
                    "#   Each line must be of the form: "+ "\n" +
                    "#           driver=<ClassName> "+ "\n" +
                    "#       No spaces or tabs in the line. "+ "\n" +
                    "#       ClassName must implement the interface javax.comm.CommDriver "+ "\n" +
                    "#           example: driver=Win32Serial"+ "\n" +
                    "#   "+ "\n" +
                    "#"+ "\n" +
                    "# The hash(#) character indicates comment till end of line."+ "\n" +
                    "#"+ "\n" +
                    "# Windows Serial Driver"+ "\n" +
                    "Driver=com.sun.comm.Win32Driver" + "\n");
                out.close();
            } catch (IOException e) {
                System.err.println("No se pudo crear el archivo:" + "javax.comm.properties");
                System.err.println("Ruta completa:" + archivoConf);
    }Before opening the port I call
    PrinterInit.printerInit();This example writes de javax.comm.properties file needed for a windows implementation. You can change the value of the Driver property for the system you are using.
    Good Luck!

  • Exception while using Java Comm and Java Web Start together

    Hello Java Experts!
    Here's the problem that's been bothering me. The application i'm developing uses Java Comm API to listen to Serial Ports. The application works absolutely fine when it is run locally.
    Now, I need to deploy this remotely using java web start. All resources(dependent jar files) are present on the server and are referenced properly in the JNLP file. All jar files are signed properly.
    Still, it throws the following exception.
    java.lang.NullPointerException: name can't be null
         at java.io.FilePermission.init(Unknown Source)
         at java.io.FilePermission.<init>(Unknown Source)
         at java.lang.SecurityManager.checkDelete(Unknown Source)
         at javax.comm.CommPortIdentifier.getPortIdentifiers(CommPortIdentifier.java:70)
    The exact line of code where it apparently seems to error out is...
    Enumeration portList = CommPortIdentifier.getPortIdentifiers();
    Are there any security issues involved here? Can a application deployed through java web start access serial ports on the system?
    Any pointers as to what the problem might be would be much appreciated.
    Thanks in advance!

    I have the IBM Communications API. I've
    been told that it works with Java Web Start but I
    have not tried it. IBM has changed it's download site
    so.... I can't point you to it. But I have it(55k zip'ed)
    and can send it to you if you post your E-Mail address
    of where you would like it sent.
    Bruce Houghton
    PS If it does work with Web Start please post the
    news here. I will be watching.

  • Need some help on JAVA COMM API's

    Hi all,
    I am working on Java for first time,,and I am working on serial interface ,I need some documentation of JAVA COMM API's ,Please forward some links

    Have you read any of these?
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22chat+server%22&col=javaforums

  • How to use the COMM API in a JAR file

    I have developed an application, using the NetBeans IDE, to communicate with a modem over the COM1 serial port using the Java Comm API. The application works fine within the IDE, but when a JAR file is created and "double-clicked", the application launches correctly, but when the code is executed to "talk" over the COM1 serial port - nothing happens. No exceptions and no warnings are thrown. My environment is XP, SP1.
    The manifest file is as follows:
    Manifest-Version: 1.0
    Class-Path: ../j2sdk1.4.2/jre/lib/ext/TimerBean.jar ../j2sdk1.4.2/jre/
    lib/ext/AbsoluteLayout.jar ../j2sdk1.4.2/jre/lib/ext/comm.jar
    Created-By: NetBeans IDE
    Specified-By: Projects/TheApp/Files/TheApp.jarContent
    Main-Class: Main
    According to the Comm API installation instructions, the following files are copied:
    copy comm.jar \j2sdk1.4.2\jre\lib\ext
    copy wind32com.dll \j2sdk1.4.2\bin
    copy javax.comm.properties \j2sdk1.4.2\jre\lib
    I suspect it has something to do with the paths.
    Any help would be greatly appreciated. Thanks.

    Thanks for your input, but after trying what you suggested the problem still exists. I think your right to be suspicous of the javax.comm.properties file. The application, that worked in the IDE, exhibits the same behavoir as the JAR file if the javax.comm.properties file is removed from the ../jre/lib directory. In other words it compiles correctly in the IDE, but when executed, nothing happens when the code that "talks" to the serial port is run.
    I've tried moving the javax.comm.properties file into the working directory. Also, the CLASSPATH and PATH system variables were modified to include the path to javax.comm.properties.
    If you have anymore ideas, please let me know.
    Thanks.

  • Java comm api in 64-bit Linux

    I apologise if this is off-topic. I can't find a suitable forum, I tried posting in the Java plugin forum, but no luck there. I would appreciate any ideas to find a solution.
    I am trying to use the java comm api to read and write to the serial port but I am getting the following error:
    Error loading LinuxSerialParallel: java.lang.UnsatisfiedLinkError: /usr/lib64/libLinuxSerialParallel.so: Can't load IA 32-bit .so on a AMD 64-bit platform
    I am using openSUSE 10.2 (X86-64) which uses Linux 2.6.18.2-34-default x86_64.
    I tried Switching to a 32-bit version of java (1.4.2) from within Eclipse and I always run Eclipse in 32-bit java (/usr/share/eclipse/eclipse -vm /usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre/bin/java) but I still get this error.
    Is there anything I can do to get the java comm api working on a 64-bit system?
    Is the java comm api still being developed and maintained? It does not look like it is?
    I've done some searching on the web and I find there is an open source version of the java comm api called RXTX but the website at http://www.rxtx.org/ is not very readable. I don't think I know enough to install this on my system.
    I would appreciate any ideas to get this working.
    Thanks,
    Martin

    I'm stuck again so I would appreciate some more help.
    I've managed to install the Sun 1.6 JDK and configure
    and make rxtx.Any small amount of progress is still progress. :)
    >
    But it still does not work, I get the following error
    when I run the SerialDemo:<snip>
    >
    It seems to be com.sun.comm which is not finding its
    native binary not rxtx! No, it's finding the shared library, unless there are a few more lines at the start of your error message that look like this:
    Error loading LinuxSerialParallel: java.lang.UnsatisfiedLinkError:
    no LinuxSerialParallel in java.library.pathIt's not finding the function it is looking for in that library.
    This is what confuses me, the
    instructions say install the Solaris version of comm
    api (http://www.rxtx.org/ how-to said Solaris Sparc
    and the rxtx INSTALL file said Solaris x86 so I tried
    both in turn and neither worked) Same here after downloading the latest stuff to my x86 Linux box. I received a similar UnsatisfiedLinkError. I checked the shared libraries and the functions were not in it.
    normally these would
    call the Solaris binary drivers but I assume this has
    to be redirected to rxtx which calls its own
    binaries?Yes. There is a part of RXTX called JCL (Java Comm for Linux) that handles that.
    http://www.geeksville.com/~kevinh/linuxcomm.html
    However, I think the problem is that Sun's API has changed since the RXTX How-To was written. Try downloading the 'comm.jar' at the bottom of the page. It says:
    comm.jar, 2.0.3, generic, English (3rd party backward compatibility, only), EnglishUnzip it and copy the comm.jar file to the 'jre/lib/ext' folder of the JDK/JVM where everything else RXTX created was placed.
    After doing this the SerialDemo app started for me without errors.
    Jim S.

  • How to calculate call duration using java card API

    Hi,
    I am developing an application using Java card API. I want to calculate duration of otgoing calls in it. I am trying to start timer at the beginning of call in Call Control event. Can someone kindly check following code of Call control event? Here timerManagement function is sending proactive command for starting timer for 3 hours. Here I am asuming that maximum call will be of 3 hours. In callDisconnect event i can get current value of timer and use it to calculate duration of call. But this scenario is also not working.
    Problem is that during code execution program stuck at send command (proHdlr.send();) of timmerManagement function. I am sending postAsBERTLV command before starting timer so may be reason is that it is not possible to send proactive command while phone is busy.
    But I also cannot send postAsBERTLV after timerManagement function. Because it is mention in specification that "The EnvelopeResponseHandler content must be posted before the first invocation of a ProactiveHandler.send method or before the termination of the processToolkit, so that the GSM applet can offer these data to the ME (eg 9Fxx/9Exx/91xx). After the first invocation of the ProactiveHandler.send method the EnvelopeResponseHandler is no more available"
    Take a look at following code
                     * Method illustrating the use of the Call Control event.
                    private void callControlService() {
                                    /** @todo: Replace following sample code with your implementation */
                                    ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
                                    EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
                                    ProactiveResponseHandler rspHdlr = ProactiveResponseHandler
                                                                    .getTheHandler();
                                    EnvelopeResponseHandler envRspHdlr = EnvelopeResponseHandler
                                                                    .getTheHandler();
                                    durationCount = 0;
                                     // allow call with no modifications
                                    envRspHdlr.postAsBERTLV((byte)0x9F, (byte)0x00);
                                    // start clock using timer
                                    timerManagement(proHdlr, rspHdlr, (byte) 0x0, timer_id, tempBuffer);
                                    return;
                    }Please help me in this regard
    Thanks
    Yasir

    I am also unable to start timer in call connected event. I cannot send any proactive command while phone is busy. I am using Gemalto development Suite and there simulators (Simulation 2G chain).
    Is it limitation of simulator that you cannot send any proactive command while phone is busy?
    Is there any other work around for getting call duration?

  • Troubles with Java Comm API

    I am trying to use the Java Comm API with Windows 2000 and I can enumerate the ports (I am almost sure that the problem is the dll). Do anybody knows a solution?

    Where is the problem?

  • How can i access gmail's smtp server using java mail api

    i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
    if anybody can help me in this regard i m thnkful to him/her.
    thnks in advance.
    jogin desai

    Here's an example of using SSL + Authentication
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums

  • Using Java Mail API from Tomcat

    Hello,
    Purely as an academic exercise I have written a JSP page which, upon being requested from the client's browser, should send me a default email using Java Mail Api.
    here is the code :
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class TestMail {
        static String msgText1 = "success this time 12";
        static String msgText2 = "This is the text in the message attachment.";
        public String sendIt() {
            String to = "<my email";
            String from = "<anything>";
            String host = "<my ip address of smtp server>";
            boolean debug = false;
            Properties props = new Properties();
            props.put("mail.smtp.host", host);
            Session session = Session.getInstance(props, null);
    .....The code works fine as a stand alone app but when called from JSP page it hangs on the Session.getInstance line. I can only guess that this might be a security issue with the container not allowing access to the smtp server ?
    Can anyone give me a clue ???

    Your Tomcat log files should spell out the problem for you.
    My Tomcat installation does not come with the Java Mail API. I had to add the mail and activation jar files to the server/common.lib directory (or the server's shared/lib or the WEB-INF/lib of your application.)
    HTH.

  • HOW TO USE JAVA OWB API

    I'm sorry for my English.
    I try to use java owb api to execute process flow of my owb project from my web application. I use oracle 11g.
    I have found only this thread about use of owb api (https://kr.forums.oracle.com/forums/thread.jspa?threadID=248256&tstart=0).
    I can establish a connection, obtain the project, process flow or mapping object but i can't understand how to run it.
    Help me please
    Stefano

    > JMX and instrumentation are quite different things.
    Not that I know a great deal about either, but this is from the API:
    "Provides services that allow Java programming language agents to instrument programs running on the JVM."
    And this is from the overview I linked:
    "The Java virtual machine (JVM) is instrumented for monitoring and management, providing built-in ("out-of-the-box") management capabilities for for both remote and local access."
    That sounds at least superficially similar to me. I'll do more research when I have the time/need. Thanks for pointing it out, though.
    ~

  • Using Java mail API from JSPDynPage

    Hi Experts,
    I am working on a Portal Assignment that requiresto sent work flow mails on the basis of error conditions.
    Can u please suggest if at all I can use Java Mail APIs from JSP page within the JSP DYN Page Framework.
    If at all Java Mail can be used could u please suugest some help docs on the same.
    Thanks for the help.
    Manab C Ghosh
    EP Consultant
    Kolkata INDIA
    +919830603327

    Hi Experts,
    Thanks for all the responses to my Mail question(mailing from JSPDynPage).
    I have found the solution.
    Here is how I have got the things: (pls note there are other solns)
    Using Java Mail APIs;
    Create a Java file in the scr.core / src.api
    MailSender.java
    * Created on Jul 21, 2005
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    package com.mailsend.test;
    import java.util.Date;
    import java.util.Properties;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    * Edited on Jul 24, 2005
    * @author Manab C Ghosh
    public class MailSender {
         public String sendMessage(){
            String msg ="Hello mail Test";
            String smtpServer ="mySMTPServer";
            String smtpSender = "senderemailaddress";
            String smtpRecipient="receipientemailaddress";
            String stBody =  msg ;
            //String stDate = new Date().toString() ;
            String stSubject = "Mail Test ";
            Send(     smtpServer,          //SMTPServer
                      smtpSender,          //Sender
                      smtpRecipient,     //Recipient
                      stSubject,          //Subject
                      stBody               //Body
                        );               //Attachments                    
         return "Mail Success";
    public static void Send(String SMTPServer,
                                  String From,
                                  String To,
                                  String Subject,
                                  String msgText1
            // Error status;
            int ErrorStatus = 0;
            // create some properties and get the default Session
            Properties props = System.getProperties();
            props.put("mail.smtp.host", SMTPServer);
            Session session = Session.getDefaultInstance(props, null);     
            try {
                 // create a message
                 MimeMessage msg = new MimeMessage(session);
                 msg.setFrom(new InternetAddress(From));
                 InternetAddress[] address = {new InternetAddress(To)};
                 msg.setRecipients(Message.RecipientType.TO, address);
                 msg.setSubject(Subject);
                 // create and fill the first message part
                 MimeBodyPart mbp1 = new MimeBodyPart();
                 mbp1.setText(msgText1);
                 // create the Multipart and its parts to it
                 Multipart mp = new MimeMultipart();
                 mp.addBodyPart(mbp1);
                 //mp.addBodyPart(mbp2);
                 // add the Multipart to the message
                 msg.setContent(mp);
                 // set the Date: header
                 msg.setSentDate(new Date());
                 // send the message
                 Transport.send(msg);
            } catch (MessagingException mex) {
    Call this file from the JSP page (which is set at JSPDynPage controller)
    one important thing-----
    Create a dir under PORTAL-INF and import the following jars-- activation.jar, mail.jar,imap.jar,smtp.jar, mailapi.jar.
    This works..
    Thanks once again to the Experts.
    happy mailing
    Manab Ghosh.
    INDIA (+919830603327)

Maybe you are looking for

  • Unable to Close project

    We are unable to close the project because it is created for plant xxxx that was never used and is wrong anyhow. When attempting to close the Project xxxxx we get message stating that Purchase orders are open. By listing all PO's applicable to the pr

  • How to know if a property file that I use in my program is updated

    Hi everyone, I was wondering how my program can know as soon as the property file/any file that I'm intersted in, has been updated at runtime. Something like JBoss descriptor etc, as soon as we make a change the app server knows of that change ? I ne

  • Stop old music from syncing?

    Recently, my iPhone 4s has been backing up my music from a very long time ago. Since then my music tastes have seriously changed and the old stuff is taking up room on my phone. I have tried a few things to fix it by fiddling with the settings, but I

  • Two cursors with interdependency: how to code ?

    Hi, I'm a newbe to pl/sql. I've two tables: customers and purchases. A customer can have more than on purchase. I want to create invoices, for each customer one invoice for all purchases in this year. (Simplified for this situation). I created a curs

  • Purpose of IS SUPPLIED and IS REQUESTED

    Hi, What is the purpose of "IS SUPPLIED" and "IS REQUESTED" and in which cases we do these ABAP statements. Thanks, Sandeep