Accesing a class from a different PC on Internet

Hi all. I have the following problem:
I have a Java programa that access to serial port to send data to a device. It works good.
Also I have Jakarta Tomcat installed, and a servlet that instantiate the previous java program that access to serial port.
If this PC is connected directly to Internet, there are no problems to people from Internet can send data to serial port.
But I would like to put the device connected to another computer not connected directly to Internet.
I know Jakarta Topmcat should be on the PC connected directly to Internet, but...are there any possibility that my servlet call my Java serial port programme on a different computer ? E.g: using a special nomination before the class name...Also someone told I should use Java RMI...Dont know if its very difficult to use...
Would appreciate some advice or example code...
Thanks...
John

RMI seems to be a perfect solution to your problem. It isn't difficult to use, but will involve a little learning. It's a cool technology though, and should be fun to mess around with.
To learn it go to http://java.sun.com/docs/books/tutorial/rmi/index.html
The example that they use is cool, it's where I learned it first.
Dave

Similar Messages

  • Invoke a method in one class from a different class

    I am working on a much larger project, but to keep this simple, I wrote out a little test that would convey the over all theory of the program.
    What I am doing is starting out with a 2 JFrames and a Class. When the program is launched, the first JFrame opens. In this JFrame is a label and a button. When the button is clicked, the second JFrame opens. This JFrame has a textField and a button. The user puts the text in the textField and presses the button. When the button is pushed, I want the text that was just put in the textField, to be displayed in the first JFrame's label. I am trying to invoke a method in the first JFrame from the second, but nothing happens. I have also tried making the Class extend from JFrame1 and invoke it from there, but no luck. So, how do I invoke a method in a class from a different class?
    JFrame1 (I omitted the layout part. I made this in Netbeans so its pretty long)
    public class NewJFrame1 extends javax.swing.JFrame {
         private NewClass1 nC = new NewClass1();
         /** Creates new form NewJFrame1 */
         public NewJFrame1() {
              initComponents();
              jLabel1.setText("Chuck");
         public void setLabels()
              jLabel1.setText(nC.getName());
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewJFrame2 j2 = new NewJFrame2();
         j2.setVisible(true);The class
    public class NewClass1 {
         public static String name;
         public NewClass1()
         public NewClass1(String n)
              name = n;
         public String getName()
              return name;
         public void setName(String n)
              name = n;
    }The second jFrame
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewClass1 nC = new NewClass1();
         NewJFrame1 nF = new NewJFrame1();     
         nC.setName(jTextField1.getText());
         nF.setLabels();
         System.out.println(nC.getName());At this point I am begging for help. I have been trying for days to figure this out, and I just feel like I am not getting anywhere.
    Thanks

    So, how do I invoke a method in a class from a different class?Demo:
    public class Main {
        public static void main(String [] args) {
         Test1 t1 = new Test1();
         Test2 t2 = new Test2();
         int i = t1.method1();
         String s = t2.method2(i);
         System.out.println(s);
    class Test1 {
        public int method1() {
         return 10;
    class Test2 {
        public String method2(int i) {
         if (i == 10)
             return "ten";
         else
             return "nothing";
    }Output is "ten".
    Edited by: newark on May 28, 2008 10:55 AM

  • How to instantiate a class from a different package?

    I am trying to instatiate a class in a package: a.b.c from another class in a different package: d.e.f
    How could I do so?
    I've already been trying many things but didn't manage to get it to work...

    Did you include both jar files in your classpath? Use
    the -cp option of the java interpreter to specify your
    classpath.Well, I tried adding the jar file to the classpath, without any success...
    String path = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
                   String finpath = "";
                   for(int i=6;i<path.length();i++)
                        finpath = finpath+path.charAt(i);
                   System.setProperty("java.class.path",System.getProperty("java.class.path")+";"+finpath+"mm.mysql-2.0.14-bin.jar/");That's what I did and it didn't work...
    If you "unpack" the jars see if there is the correct
    packages-folders symmetry...Yes, the classes are in the package-folders they should be in..

  • Casting to an abstract class from a different classloader

    I have a class Special that extends an abstract class Base. In my code I use a URLClassLoader to load the class Special and I then want to cast Special to Base. If I do this I get a ClassCastException because the classes are loaded from different classloaders. I can't have the URLClassLoader and the class that performs the cast extend a parent ClassLoader that knows about the Base class. What I want to be able to do is something like this:
    URLClassLoader loader = new URLClassLoader(codebase, null);
    Class baseClass = loader.loadClass(className);
    Base baseObj = (Base)baseClass.newInstance();
    I have seen some post that suggest I can achieve this using Reflection but I am not sure how to go about this. Any help would be appreciated.
    Thanks
    Jim.

    Thanks for your help so far but I still can't do the casting, consider this example:
    //Base.java
    package classTest;
    public interface Base
         public abstract void execute();
    //ConcBase.java
    package classTest;
    public class ConcBase implements Base
         public void execute()
              System.out.println("execute in ConcBase called");
    I compile these files and jar them into work.jar
    I now have my application:
    //Test.java
    import java.net.*;
    import java.io.*;
    import classTest.*;
    public class Test
    public static void main(String[] args)
              Test t = new Test();
              t.test();
         public void test()
              try
                   File file = new File("D:/Projects/classloadTest/work.jar");
                   URL[] codebase = {file.toURL()};
                   ClassLoader ccl = getClass().getClassLoader();
                   ccl.loadClass("classTest.Base");
                   URLClassLoader ucl = new URLClassLoader(codebase,ccl);
                   Class conClass = ucl.loadClass("classTest.ConcBase");
                   classTest.Base b = (classTest.Base)conClass.newInstance();
                   b.execute();
              catch(Exception t)
                   System.out.println("thowable caught");
                   t.printStackTrace(System.out);
    I compile this and run it with this command:
    java -classpath D:\Projects\classloadTest\work.jar;. Test
    This runs as I would expect, however I have set the parent class loader of my custom URLClassLoader to the one that does the cast, this means that Base and ConcBase are both being picked up by the application class loader as my custom class loader delegates to its parent. This is the current behaviour I have in my proper application and it is causing problems, I don't want the class that implements Base to delegate to any class on the main applications classpath. If I change the line:
    URLClassLoader ucl = new URLClassLoader(codebase,ccl);
    In Test.java to:
    URLClassLoader ucl = new URLClassLoader(codebase,null);
    I get a ClassCastException, this is because the class that does the cast (Test) loads Base from it's classpath and ConcBase is loaded from the URLClassLoader. After spending more time looking at this problem I don't think there is anyway to resolve but if anyone thinks there is please tell me.
    Many thanks
    Jim.

  • Instanciate a class from a different sector

    I have a structure on my server like this :
    BO
    /|\
    / | \
    / | \
    A B C
    BO : My Business Objects (EJB)
    A,B,C : my different Web Applications (separated)
    How shall i have to do for instanciating in my Web application A a class of my Web application B ?
    Thanks a lot.

    Include in the WAR file of webapp A the *.class file of webapp B that you want to instantiate in webapp A, or put the *.class in someplace where the container will look for *.class files.
    Jesper

  • Importing class from different directory

    Hi, Can anyone tell me how to import a class from a different directory? I have a DGenerator class in ./generator directory.
    I have tried Import generator.DGenerator; to use the DGenerator class. However. I got the error:
    cannot access generator.DGenerator
    bad class file: ./generator/DGenerator.class
    class file contains wrong class: DGenerator
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    Help please.
    Thank you!

    I don't understand why this is a Swing question, but at any rate if you want your DGenerator class to be found in a particular directory, you must do one of two things:
    1. Put that directory in your classpath and just refer to the class as DGenerator.
    2. Make the class belong to the package "generator".

  • Updating Jlabel from a different class?

    Hi,
    Im in the middle of developing a program but swing is making it very hard for me to structure my code. The problem is I want to update the text of a Jlable from a different class when a button is pressed. THe event handling is done by a different class than the where the Jlabel is initiated which is why i think it doesnt work. But when the button is pressed it does execute a method from the main class that has the .setText() in it. Why wont the Jlabel update? Thank you

    Thanks for your help but i am still having trouble.
    This is the code from the button handler class
    public void actionPerformed(ActionEvent e)
           if ("btn3_sender".equals(e.getActionCommand()))
                JLabel j = temp2.getlblQuestion();
               j.setText("NEW TEXT");
           This is the code from the main class where the JLabel is created:
    public JLabel getlblQuestion()
        return lblQuestion;
    }How come this does not work??

  • How to call a custom action class present in one DC from a different DC

    Hi Experts,
    I have to implement one email functionality in my project.This functionality works fine if I use the Standard EmailAction class present in com.sap.isa.cic.customer package,but we need to change the email IDs in some cases so,we need to create a custom class.But if I create a custom Action class in Another DC(shext) and try to call this class from the config file present in the other DC(From where the Standard class was called),I am getting no Action Instance found for the declared Action(This Happens when the class is not present ).
    From the error I interpreted that the presence of the Custom Action class is not recognised by the The DC.
    Please confirm If my understanding is correct.
    I also tried adding a a new public part in shrext and tried adding the same in the used dc for the DC from where I am trying to call the class.But the activity fails and it gives me the error that the DCs are Broken.Do I need to build the DCs after adding a public part or a used DC?
    Please answer If anybody has faced the same issue or has a solution to it.
    Thanks
    Arpita Saxena
    Edited by: ArpitaSaxena on Jun 23, 2011 6:51 AM
    Edited by: ArpitaSaxena on Jun 23, 2011 7:01 AM

    Hi All,
    I was able to resolve this issue myself.
    I had to include the DC crm/isa/lwc and the DC mail in the used DCs of SHREXT .
    So,all the jars got included automatically and I was able to create a new custom class for the required functionality.
    Its working fine now.

  • Execution of a class from a class in different Eclipse project.

    I have 2 projects in Eclipse and i want to execute a class in one project from a class in the other project.The package hierachy of the classes are same under both the eclipse projects.
    project1:
    foo.hoo.E.java
    project2 :
    foo.hoo.F.java
    Trying to run E.java from F.java using the code below.:-
    try{     
         ProcessBuilder pb = null;
         pb = new ProcessBuilder("java",
                   "-classpath",
                   System.getProperty("java.class.path"),                         "-Xms16M",                         "-Xmx256M",                         "foo.hoo.E.java");
              Process process = pb.start();
              }catch (IOException e) {
    The excetion of E.java does not actually take.Please suggest.

    When you run the java command to start a new JVM the class name you supply is the name of the class, not the name of the java file. i.e. no .java. "foo.hoo.E" not "foo.hoo.E.java". Furthermore the class path you are using won't be likely to include the classes from the other project unless you've told eclipse to do so. (It might be enough to specifiy the E project as a run time dependancy).
    This is, by the way, a very strange interpretation of the idea of "executing one class from another". In fact, in java, we don't execute classes, we execute programs. If you want to execute code in another class it's far more often sensible to call it within the same JVM, rather than lauch a new one. That's why your question has provoked so much irritation.

  • Can not access the Instance Data of a Singleton class from MBean

    I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out.
    I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for the MBean to access and calculate some application runtime stuff. Thus during the application startup and then in the application lifecysle, i will be adding data to the SDATA instance.So, this SDATA instance always has the data.
    Now, the problem is that i am not able to access any of the data or data structures from the PerformanceStatistics MBean. if i check the data structures when i am adding the data, all the structures contains data. But when i call this singleton instance from the MBean, am kind of having the empty data.
    Can anyone explain or have hints on what's happening ? Any help will be appreciated.
    I tried all sorts of DATA class being final and all methods being synchronized, static, ect.,, just to make sure. But no luck till now.
    Another unfortunate thing is that, i some times get different "ServicePerformanceData " instances (i.e. when i print the ServicePerformanceData.getInstance() they are different at different times). Not sure whats happening. I am running this application in WebLogic server and using the JConsole.
    Please see the detailed problem at @ http://stackoverflow.com/questions/1151117/can-not-access-the-instance-data-of-a-singleton-class-from-mbean
    I see related problems but no real solutions. Appreciate if anyone can throw in ideas.
    http://www.velocityreviews.com/forums/t135852-rmi-singletons-and-multiple-classloaders-in-weblogic.html
    http://www.theserverside.com/discussions/thread.tss?thread_id=12194
    http://www.jguru.com/faq/view.jsp?EID=1051835
    Thanks,
    Krishna

    I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out.
    I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for the MBean to access and calculate some application runtime stuff. Thus during the application startup and then in the application lifecysle, i will be adding data to the SDATA instance.So, this SDATA instance always has the data.
    Now, the problem is that i am not able to access any of the data or data structures from the PerformanceStatistics MBean. if i check the data structures when i am adding the data, all the structures contains data. But when i call this singleton instance from the MBean, am kind of having the empty data.
    Can anyone explain or have hints on what's happening ? Any help will be appreciated.
    I tried all sorts of DATA class being final and all methods being synchronized, static, ect.,, just to make sure. But no luck till now.
    Another unfortunate thing is that, i some times get different "ServicePerformanceData " instances (i.e. when i print the ServicePerformanceData.getInstance() they are different at different times). Not sure whats happening. I am running this application in WebLogic server and using the JConsole.
    Please see the detailed problem at @ http://stackoverflow.com/questions/1151117/can-not-access-the-instance-data-of-a-singleton-class-from-mbean
    I see related problems but no real solutions. Appreciate if anyone can throw in ideas.
    http://www.velocityreviews.com/forums/t135852-rmi-singletons-and-multiple-classloaders-in-weblogic.html
    http://www.theserverside.com/discussions/thread.tss?thread_id=12194
    http://www.jguru.com/faq/view.jsp?EID=1051835
    Thanks,
    Krishna

  • How to shift valuation class from one material type to another material type ?

    I have came across following weird scenario:
    We already created huge no.of materials of material type say ZABC with two valuation classes say 1100 and 1200(GL accounts for these VCs for different posting keys in OBYC settings are same). Account category reference for this material type is 0010.
    After that we created new material type say ZPQR  with new Account category reference 0025, and valuation class 1200 is linked with this ACR 0025. Because of this, valuation class 1200 disappeared from material type ZABC. In order to avoid inconsistency, we need to have valuation class 1200 linked with older material type i.e.ZABC.How we can do this ? What impacts must have happened in this period (from MM/FI) in the system, where valuation class get shifted from one material type(ZABC) to another material type(ZPQR)....please help us in this scenario.

    Thanks Sana,
    We are also looking for the solution provided by you i.e. reassign ACR 0010 to Valuation class 1200.
    Your are also correct in terms of  statement "config doesnt allow me to assign same valuation class to 2 different AREF (Account reference number/Account category reference).
    I wanted to know, what are the possible impacts in the system during this re-assignment of ACR to old material type ZABC.
    Regards,
    Sudarshan.

  • ClassNotFound in case of class from jar in lib folder

    Hello,
    I get an application that I have to deploy on Weblogic AS. It is big ear with couple of wars inside. Let's say it is bigApp.ear.
    It is deployed and state is Active. When go to browser and try to run an application I get an error. In logs I found ClassNotFoundException. The error is related to a class, let's say: com.some.package.Abc - I have this class in a jar file, let's say someFile.jar and it is in a folder WLS_FOLDER\samples\domains\wl_server\lib where:
    - WLS_FOLDER is my WLS installation folder
    - wl_server - name of my domain where I deploy an application.
    I wrote a small application (simple form), let's say simpleApp.war. The application uses the class com.some.package.Abc, but the class is not put into the war (WEB-INF/lib) of my small aplication (I use Maven and dependency to someFile.jar has scope provided, so simpleApp.war does not contain it). The result is that simpleApp works fine and there is no error in logs. It creates an instance of com.some.package.Abc and correctly display toString() of the instance of the class in a browser. So this means that application simpleApp is able to see and use classes that are inside jars in WLS_FOLDER\samples\domains\wl_server\lib folder.
    So my guess is that there is something in bigApp.ear but I don't know where to search. I read about class loaders hierarchy in Weblogic and Class Loader Filtering. But I have looked inside every weblogic.xml in bigApp.ear and wars that are inside and there is no filter on "com.some.package" or "com.some" or "com" only different packages.
    Is there any other mechanism in Weblogic that could block the visibility of classes from jars from lib folder of domain to the applications that are deployed in that domain??
    Regards

    Hi,
    Place that something.jar file under Domain_Home / lib folder and restart the server it will included with in the classpath and your app will able to pick the class without any issue.
    Regards,
    Kal

  • Access a component in an mxml file from a different mxml file

    Hi,
    I want to access a component in an mxml file 1 such as this one  <mx:Image id="img" width="101" height="200" source="{product.image}"/> using the
    id
    from the actionscript function from a different mxml file 2
    public function init():void
           HERE.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );    
    so i can make it dragable, Please help me  in this if u can urgently!!!!

    okay,
    I have the image component in ProductCatalogThumbnail.mxml, which has an id of "img"
    so, i created a public variable in the file and a public function that returns the value of the object.
    public var imagecopy:Object;
            [Bindable]
             public function imagecopyfunction():Object{
             imagecopy  = img;
             return imagecopy;
    now, I want to access this image in the mxml file ProductList.mxml in a function
      public function init():void
          ProductCatalogThumbnail.imagecopy.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
         // accepting a drag/drop operation...
           this.area.addEventListener( DragEvent.DRAG_ENTER, acceptDrop );
           // handling the drop...
          //this.area.addEventListener( DragEvent.DRAG_DROP, handleDrop );
    I tried to use the variable, and then i tried to use the function:
    I got this error when I tried the variable : 1119: Access of possibly undefined property imagecopy through a reference with static type Class.
    ProductCatalogThumbnail.imagecopy.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
    and this error when i tried the function:  1061: Call to a possibly undefined method imagecopyfunction through a reference with static type Class.
    ProductCatalogThumbnail.imagecopyfunction().addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
    i made sure i imported ProductCatalogThumbnail file in the beginning of my application.
    I am not sure what went wrong.

  • Accessing custom classes from JSP

    Hi Guys,
    I am having some problems accessing my custom classes from my JSP.
    1) I've created a very simple class, SimpleCountingBean that just has accessors for an int. The class is in the package "SimpleCountingBean". I compiled this class locally on my laptop and uploaded the *.class file to my ISP.
    2) I've checked my classpath and yes, the file "SimpleCountingBean/SimpleCountingBean.class" is located off of one of the directories listed in the classpath.
    3) When I attempt to use this class in my JSP, via the following import statement:
    import "SimpleCountingBean.*"
    I get the following compile error
    java.lang.NoClassDefFoundError: SimpleCountingBean/SimpleCountingBean
    I'm pretty sure that my classpath is properly setup because when I purposely garble the import statement, I get the "package not found" compile error.
    Do I need to upload some other files in addition to the class file? Any suggestions would of course be appreciated.
    Sonny.

    Trying to get some clearer view.. so don't mind..
    So you uploaded all your .jsp files into your account which is:
    home/sonny
    and it compiles and work. But custom classes doesn't seems to be working, where did you place your classes?
    From my knowledge of tomcat, classes are normally placed in, in this case:
    home/sonny/web-inf/classes
    Maybe it differs from windows enviroment to *nix enviroment.. well, I'm just saying out so if its not the case.. don't mind me.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Importing a class from another context?

    Hi JSP techies,
    Im using RESIN and having a simple problem of figuring out how to import classes from another context, if Im using the right word.
    ie.
    My .jsp files are under $home/resin/doc/test dir. And in the jsp file, I would like to import a servlet class or a plain java class. But the servlet classes and all other classes are located under $home/resin/webapps/project/WEB-INF/classes/a/b/c
    Hence when I say
    <% page import="a.b.c.*" %>
    I get an error saying "a" not found.
    1. When I say "servlet classes are in a different CONTEXT", is that right? or is it just another directory?
    2. How can I make the jsp file import the classes from the servlets class path?
    Note: Ofcourse, when I copy the package to the
    $home/resin/doc/WEB-INF/classes dir, everything works fine. But thats simply not an efficient way to get around. Could anyone clear my doubts on this regd.?
    Thanks in advance.
    Arun

    Oh... I get it now. I'm sorry, I had you poorly misunderstood. You are trying to import servlets from another web app or servlet context. I would suggest you put servlets that are common to all web apps in the system classpath and not tie them to any particular web app. In other words create a package directory structure from the system's root directory or any where outside of any web apps and point the system classpath to the beginning of that directory structure. I have a similar thing going with Tomcat. I have a folder in my root called Java_Class which is in my classpath. I build all common utilities in this directory. So I have a com/craig/web structure that holds my AppServlet which is in package com.craig.web. This servlet is visible to all web apps via the Windows classpath. Servlets particular to an application like say an MusicOrderProcess servlet would reside in a package under the webserverhome/webapps/MusicStore/WEB-INF/classes directory where webserver home is the home directory of the webserver you are using. I've tested this across webservers as well (orionserver and Tomcat) and it works.
    From the prompt you include in your posts I am guessing that you are running on UNIX. Move your common servlets out of their respective web apps and into a common directory structure. Configure the UNIX $CLASSPATH (or is it $classpath?) environment variable to point to this sturcture and you'll be on your way!
    Post again if you have more questions!

Maybe you are looking for