How can I run a J2EE client on a machine other than locahost machine?

I 've developed and deployed a simple J2EE application which can run on localhost where J2EE server(Sun's RI) is running as well as cloudscape. When I run the applicaiton client I have to have both someApp.ear and someClient.jar in one directory and use the command "runclient -client someApp.ear -name -someClient", now I am wondering how I can run the client on other machines, do I need to install the same version of j2sdkee on the other machine? what files should I copy to the other machine? what environment variables should I set up for that? Is there any other way to run the client instead of using "runclient" command provided by J2sdkee?


Thanks a lot! Look forward to any help.
kindyAsked:
Who is Participating?
 
girionisConnect With a Mentor Commented:
 Ok. I assume that your client runs on a differet machine than your application server, i.e. the computer where your EJB is deployed has a different I.P. address from the computer where your client is running.

  Before we proced just do a last thing. In your main method please put the following (just before the "try" statement):

  System.out.println("java.naming.factory.initial: " + System.getProperty("java.naming.factory.initial"));
  System.out.println("java.naming.provider.url: " + System.getProperty("java.naming.provider.url"));

  The first one is to see which class acquires the initial context and the second is to see the provider of the naming service (if any).

  Can you let us know what the output of the two System.out.println statements is?

 
0
 
antonsigurCommented:
I think you must install J2EE on the client computer.
You must also edit one file:
orb.properties under C:\j2sdkee1.3.1\config (or where you install j2ee)
It probably contains:
port=1050
host=localhost

Localhost should be the server computer

You could create a batch script, and let it run your client. In windows:
@runclient -client someApp.ear -name -someClient inside a cmd file.

The j2ee_home and j2ee\bin directory must be set in the environment.

I have not been running on many computers, but this did work for me, possible someone knows some shortcuts. Like you probably just need j2ee.jar and the config files +runclient batch file... but I'm not sure how to set up like that
0
 
kindyAuthor Commented:
Thank you very much for the reply. It looks so tiring to have a J2ee applicaiton/client run.  I am always wondering why there is no any easy way to do that, why do people like Java while they have to set up so many things in different directories/different config files etc. The correct deployment always seem a terrible task for me. I really hate setting up those environment variables manually, also really hate the moment when app. is compiled and deployed, but cannot run, and I don't know what's wrong with it.

You know, usually when we install a software, we just need to run a single command "setup.exe" r "install.exe", then we can use that immediately,  much easier than Java stuff....

Maybe I am just a beginner? so it seems difficult for me?-:)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
antonsigurCommented:
I agree, they might have better installers with theyr packages so these "must be there" environmental variables are setup right.

I'v been working on a J2EE program (running on theweb) and I hate the errors I recive when something is missing/wrong... Hard to debug...without expensive tools...

There must be aĆ° better way to run J2EE applications... there must be....
0
 
kindyAuthor Commented:
Thank you very much for the reply. It looks so tiring to have a J2ee applicaiton/client run.  I am always wondering why there is no any easy way to do that, why do people like Java while they have to set up so many things in different directories/different config files etc. The correct deployment always seem a terrible task for me. I really hate setting up those environment variables manually, also really hate the moment when app. is compiled and deployed, but cannot run, and I don't know what's wrong with it.

You know, usually when we install a software, we just need to run a single command "setup.exe" r "install.exe", then we can use that immediately,  much easier than Java stuff....

Maybe I am just a beginner? so it seems difficult for me?-:)
0
 
girionisCommented:
 If you just want to run your client you shouldn't have to install J2EE on the client machine as well (although you do need the JVM). You only need the client jar file (and probably the .ear file - this depends on the vendor's application server implementation) and nothing else. Sure you need JNDI libraries in order to locate the EJBs but JNDI is part of the latest J2SE and you do not have to download it seperately.
0
 
antonsigurCommented:
What about J2EE.JAR you will need that, won't you?
0
 
girionisCommented:
 Yes you will, sorry, I took it for granted. When I said you don't need to install J2EE I meant you do not have to install the whole package that contains the RI and Cloudsape since they are server-side components. I should have clarified it :-)
0
 
kindyAuthor Commented:
I 've copied App.ear , AppClient.jar, j2ee.jar, j2ee-ri-svc.jar to the other machine, but how about runclient.bat?
The other machine I want to run client is a Sun solaris not Windows machine, so just a copy doesn't work.
0
 
girionisCommented:
 Run the client using the "java" command instead:

  java -classpath <path to the j2ee.jar file and to your client jar file> <the client class file name>.

  For example if your client class is called "MyClient.class" and your client jar file is called "MyClientJar.ja" and your j2ee.jar and your "MyClientJar.jar" files are under the /home/kindy folder do a:

  java -classpath /home/kindy/j2ee.jar;/home/kindy/MyClientjar.jar;. Myclient
0
 
kindyAuthor Commented:
I used:
java -classpath './j2ee.jar:./myAppClient.jar' myClient -textauth

I am wondering why we didn't use App.ear? The above command failed, the following is the error message. There are tons of error messages which didn't tell us what the real problem is at all! Who designed Java??? (sorry, just feel debug a java app. is so frustrating) Thanks for help!


java.io.FileNotFoundException: .../private/tmp/config/security.properties (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init
...
        at myClient.main(Unknown Source)
java.io.FileNotFoundException: ..../private/tmp/config/ejb.properties (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>
...
  Warning: unable to read transaction.interoperability config property, Caught an exception.
javax.naming.NameNotFoundException: No object bound for java:comp/env/ejb/SimpleScenes at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at myClient.main(Unknown Source)

0
 
girionisCommented:
 Are you trying to read from your client those files missing?
0
 
kindyAuthor Commented:
I used:
java -classpath './j2ee.jar:./myAppClient.jar' myClient -textauth

I am wondering why we didn't use App.ear? The above command failed, the following is the error message. There are tons of error messages which didn't tell us what the real problem is at all! Who designed Java??? (sorry, just feel debug a java app. is so frustrating) Thanks for help!


java.io.FileNotFoundException: .../private/tmp/config/security.properties (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init
...
        at myClient.main(Unknown Source)
java.io.FileNotFoundException: ..../private/tmp/config/ejb.properties (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>
...
  Warning: unable to read transaction.interoperability config property, Caught an exception.
javax.naming.NameNotFoundException: No object bound for java:comp/env/ejb/SimpleScenes at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at myClient.main(Unknown Source)

0
 
kindyAuthor Commented:
what am I missing? I use the same .ear, .jar under windows where I developed and deployed and app.
0
 
girionisCommented:
 I repeat my question. Are you, anywhere in your client code, trying to process any configuration files?

  And btw your classpaht does not need the single quotes. It should be:

java -classpath ./j2ee.jar:./myAppClient.jar myClient -textauth
0
 
kindyAuthor Commented:
what am I missing? I use the same .ear, .jar under windows where I developed and deployed and app.
0
 
kindyAuthor Commented:
here are the client code, just modified from savingsaccountclient.java in j2ee tutorial, no idea about
configuration file...

import java.util.*;
import java.math.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class myClient {

   public static void main(String[] args) {

       try {
           Context initial = new InitialContext();
           Object objref = initial.lookup("java:comp/env/ejb/SimpleScenes");

           ScenesHome home =
               (ScenesHome)PortableRemoteObject.narrow(objref,
                                            ScenesHome.class);

           Scenes scene01 = home.create("101", "scence01", "url01");        
           scene01.remove();

           Scenes scene02 = home.create("186", "scene02", "url02");        
           Scenes scene002 = home.findByPrimaryKey("186");
               System.out.println("186' sceneName " + scene002.getSceneName());    
               System.out.println("186' sceneURL " + scene002.getSceneURL());

           Scenes scene03 = home.create("145", "scene03", "sameurl");      
           Scenes scene04 = home.create("158", "scene04", "sameurl");        
           Scenes scene05 = home.create("268", "scene05", "sameurl");
       
           scene05.updateSceneURL("diffurl");

           Collection c = home.findBysceneURL("sameurl");
           Iterator i=c.iterator();

           while (i.hasNext()) {
              Scenes account = (Scenes)i.next();
              String id = (String)account.getPrimaryKey();
       
              System.out.println(id + ": ");
           }
             
           System.out.println("158's sceneName = " + scene04.getSceneName());                  
             scene04.updateSceneName("scene06");
             System.out.println("158's sceneName = " + scene04.getSceneName());    
             
           Scenes pete = home.create("800", "scene06", "url03");              
           Scenes sally = home.create("900", "scene06", "url04");
           
           c = home.findBysceneName("scene06");
           i=c.iterator();

           while (i.hasNext()) {
              Scenes account = (Scenes)i.next();
              String id = (String)account.getPrimaryKey();
       
              System.out.println(id + ": ");
           }
           
           c = home.findAllScenes();
           i=c.iterator();

             System.out.println("id     sceneName     sceneURL");
           while (i.hasNext()) {
              Scenes curscene = (Scenes)i.next();
              String id = (String)curscene.getPrimaryKey();
       
              System.out.println(id + "     " + curscene.getSceneName() + "\t" + curscene.getSceneURL());
           }
           
       
           System.exit(0);
           
           

       }  catch (Exception ex) {
           System.err.println("Caught an exception." );
           ex.printStackTrace();
       }
   }
}
0
 
girionisCommented:
 I don't know what exactly is going on but it tries to find some files and it's failing. It would be godo to copy these files on the client side as well, under the same structure and try again.
0
 
antonsigurCommented:
I think you need the configuraton files, at least some of them, that installs with J2ee, then you must, I think, set the J2EE_HOME env variable.

See above:
orb.properties under C:\j2sdkee1.3.1\config (or where you install j2ee)
It probably contains:
port=1050
host=localhost

It probably reads this file, when looking up the server (then again, it might also reado other files... too)
0
 
kindyAuthor Commented:
my EJB is still running on Windows machine(localhost) where J2EE is installed. qirionis said we don't need to install j2ee on other machine if we just want to run a client. I think orb.properties refer to where server is.
0
 
antonsigurCommented:
Yes, probably it is reading the whole config directory... where all the .properties files are...
0
 
girionisCommented:
 No you shouldn't need the whole J2EE installed on the client, just the client files (jar & ear) and the j2ee.jar. EJBs should take care fo the rest. I am not sure why it's doing that but I never experienced problems with stand alone clients.
0
 
antonsigurCommented:
Where are informations about wich server to connect to stored?
0
 
girionisCommented:
 That should be obtained from the JNDI context.
0
 
antonsigurCommented:
this is the lookup:
initial.lookup("java:comp/env/ejb/SimpleScenes");
Here is nothing about any server...
0
 
girionisCommented:
 Well naturally not. The lookup is not intented to look up a naming service but rather an object residing on that naming service. The above code just locates the EJB, does not indicate the JNDI server to use. The URI for the JNDI service should be provided as a property to the client otherwise it couldn't acquire the InitialContext.

  Most of the application servers provide their own property files which are usually bundled into the client JAR file (if you use a tool to create the JAR file and not create it manually). I guess what happens here is that it tries to find the property file and it's failing.

  The second thing that can be done (no properties file included) is to define such properties into the code using the System.setProperty() method.
0
 
kindyAuthor Commented:
it seems that i have no way to let the client run.... I copied config/ejb.properties, security.properties, but it seems not a way to figure out the problem.

Thanks for help
0
 
girionisCommented:
 What is the problem this time? Still the same error messages?
0
 
antonsigurCommented:
So it is running when you copy these files?
0
 
kindyAuthor Commented:
Now I use:
tmp $ java -classpath ./j2ee.jar:./j2ee-ri-svc.jar:./myScenesAppClient.jar ScenesClient -textauth


Caught an exception.
javax.naming.NameNotFoundException: No object bound for java:comp/env/ejb/SimpleScenes
        at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at ScenesClient.main(Unknown Source)


it seems that errors become less, but this happened when I relog in the machine the other day after I copied config/ejb.properties, security.properties to tmp/


why isn't there any instruction on the web about running j2ee client on different machines? it is said that J2EE is
great for distributed application, Java is portable, but porting is so much trouble....
0
 
kindyAuthor Commented:
what should we do with myScenesApp.ear?  maybe that includes sth. we need?
0
 
girionisCommented:
 Can you post the contents of your ejb.properties file?
0
 
kindyAuthor Commented:
Here it is:

audit.log.file=audit.log
repository.directory=repository
applications.directory=applications
http.port=9191

transaction.interoperability=true
transaction.jtsclient-policycheck=false
0
 
girionisCommented:
 Hmm... it does not help me. Hwo do you obtain the information for the naming service?
0
 
kindyAuthor Commented:
i have no idea. almost desperate...
0
 
girionisCommented:
 Do not worry, we will find a solution. How were you accessing the EJB when client and J2EE were running on the same computer? Did you use a naming sevrice somewhere on the web or did you use the naming service that runs with your J2EE server?
0
 
kindyAuthor Commented:
i have no idea. almost desperate...
0
 
kindyAuthor Commented:
I just use the naming service that comes with J2EE server, actually, I don't know how to use other naming service.
0
 
kindyAuthor Commented:
I put the above too lines into client main method, just below this statement:
Object objref = initial.lookup("java:comp/env/ejb/SimpleScenes");

and I redeploy the app. and rerun the client, still on the localhost machine. The results are:

java.naming.factory.initial: null
java.naming.provider.url: null

any clue? seems weird.
0
 
girionisCommented:
 What happens if you run the same client from the same physical computer as the one that runs the J2EE application server (client and server on the same computer)? What is the output?
0
 
kindyAuthor Commented:
that is the result, I can only run client on the same machines where EJB is deployed.
0
 
girionisCommented:
 Does your EJB Home interface extend EJBHome or EJBLocalHome?
0
 
CleanupPingCommented:
kindy:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to antonsigur

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.