Results 1 to 4 of 4
  1. #1
    MAILMIRZA is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default Compiling and using jar file for custom classes

    Hi ,

    I downloaded java classes available as attached file with this post


    I un-zippped and saved the class files in sms folder.

    I successfully compiled it using javac as below:

    C:\Program Files\Java\jdk1.6.0_11\bin>javac sms\SMSClient.java sms\Sender.java sms\SerialConnection.java sms\SerialConnectionException.java sms\SerialParameters.java

    then i created jar file using the command below:
    C:\Program Files\Java\jdk1.6.0_11\bin>jar cf SMSClientpack.jar sms\Sender.class sms\SerialConnection$KeyHandler.class sms\SerialConnection.class sms\SerialConnectionException.class sms\SerialParameters.class sms\SMSClient.class

    Then I placed that SMSClientpack.jar in

    C:\Program Files\Java\jdk1.6.0_11\lib


    Then i created a file with name DemoSMS.java to use above code

    //DemoSms.java
    import java.SMSClientpack.*;

    public class DemoSms
    {
    public static void main(String args[])
    {
    SMSClient sc = new SMSClient();
    sc.sendMessage("mycellnumber","Hello");
    }

    }
    //ends here


    It shows following error, please help where i am doing wrong?

    C:\Program Files\Java\jdk1.6.0_11\bin>javac DemoSms.java
    DemoSms.java:3: package java.SMSClientpack does not exist
    import java.SMSClientpack.*;
    ^
    DemoSms.java:10: cannot find symbol
    symbol : class SMSClient
    location: class DemoSms
    SMSClient sc = new SMSClient();
    ^
    DemoSms.java:10: cannot find symbol
    symbol : class SMSClient
    location: class DemoSms
    SMSClient sc = new SMSClient();
    ^
    3 errors


    thanks,
    Kashif
    Attached Files Attached Files

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    SMSClientpack.jar is external jar, i think.

    you may try to copy the jar to project directory
    package it, and import it

    and
    compile using -classpath to point to to SMSClientpack.jar

  3. #3
    MAILMIRZA is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default eclipse?

    Thanks, Appreciate your help.
    I am using notepad. Should I shift to Eclipse for this pupose or is there any other alternative?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What mtyoung described is the best way to get practice it. You are trying to import that external jar file in java default package, something like this,

    import java.*;
    It's not possible, not valid. What must import correct package according to your project placed.

    Almost all IDEs able to link external jar files. If you are working on an IDE, it'll added the external jar files for you.

Similar Threads

  1. cannot read file while compiling!!!
    By AMIT TAYADE in forum New To Java
    Replies: 11
    Last Post: 08-23-2008, 01:02 PM
  2. Replies: 0
    Last Post: 05-13-2008, 07:16 AM
  3. Declaring Custom File Extensions
    By Jesdisciple in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 05-07-2008, 11:44 PM
  4. Poblem in Compiling a c++ file from a java program...
    By Amit Kr. Mishra in forum New To Java
    Replies: 0
    Last Post: 11-06-2007, 11:41 AM
  5. How to use <,>,== on custom classes
    By Bojevnik in forum Advanced Java
    Replies: 4
    Last Post: 10-29-2007, 06:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •