File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Running plain java classes in a server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Running plain java classes in a server" Watch "Running plain java classes in a server" New topic
Author

Running plain java classes in a server

Giridhar Agoram
Greenhorn

Joined: Jun 12, 2004
Posts: 4
Hi,
1) Can we run plain java classes in a server instead of a JVM
2) If yes, what are the pros / cons
Harish Kashyap
Ranch Hand

Joined: Jun 14, 2000
Posts: 118
Can you be a bit more elaborate when you say "run plain java classes in a server instead of a JVM"

can you be specific on "server" here. Because a server is just an application that responds to incoming requests and thus serving the clients. That server application can be a java class.

To run a java class, you need 'java' interpretter that needs jvm to execute.

even your server might be running under a jvm.
Giridhar Agoram
Greenhorn

Joined: Jun 12, 2004
Posts: 4
Let me elaborate..

For a certain requirement, a plain java class running in a JVM wud suffice but my architect is insistent on deploying it in a server. So, I need the pros & cons of running this class in a server so as to argue for / against this design.

Thanks
Giridhar
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
Do you mean running as a "service" - ie always running in the background and not tied to a particular user?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I like this definition of server: A process that accepts connections from clients. This kind of environment is necessary if you want the code to run on another machine or a separate process on your own machine. You connect, send your request, it does the work, sends a response.

Your architect may just want to run one copy of the code on some machine so that you or any other user can connect and have it do some work. Talk it over see what reasons they have ... better sharing, central deployment, central management for start & stop, etc. And see how they define "server". It might be ok for your POJO to open a socket and act as a server itself, or they might have reason to run within a container like a servlet or EJB engine.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi,

I also same kind of requirement. I have plain simple java class where class has its own main method, which I wanted to run in JBoss 3.2.6 so any user can use that class. To be specific I have JMS class which just send and receive messages to server. I created destination within JBoss so my JMS class has to send message to registered destination in JBoss. Could anybody enlighten me on this I know that JBoss support deployment of POJOs.
Thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Ah, you've added the special sauce that the previous part of the thread didn't have ... the JMS listener! You should be in great shape. Your listener can call methods on a POJO like String, so it can call methods on your class just as well. It can even invoke main() since main is a perfectly normal public static method.

MyClass.main( args );

I personally know zip about deployment, but you should be able to put your POJO in a "utility jar" (is that a common EJB term or just WebSphere?) or the same package & jar as your listener.

I'm a little curious what this thing is going to do. If you run main() you won't get any return value. If it just does a little work and doesn't need to report back, it should be fine, tho.

Sorry if that start out a bit smart-a** in tone. It's neat to realize how little magic there is in the world. Running inside a server is not that big a deal in many ways, and main() has no voodoo at all - it just happens to be the method that java.exe likes to call.

Let me know if all that works out for you!
[ June 10, 2005: Message edited by: Stan James ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running plain java classes in a server