Java Forum / General / November 2005
NamingException
gk - 07 Nov 2005 07:11 GMT i have a JMS sender application and a JMS receiver application. i have compiled . when i am trying to run the sender application . i got "NamingException"....whats the mistake ?
i have compiled and run the application with -classpath .;c:\j2ee.jar....
i am using no server. does JMS application needs a server ? i am running from the command prompt with -classpath .;c:\j2ee option....whats wrong ?
Roedy Green - 07 Nov 2005 08:24 GMT > i got >"NamingException"....whats the mistake ? 1. Not showing any code. 2. not giving a copy/paste verbatim copy of the error message and stack trace.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
gk - 07 Nov 2005 09:43 GMT stack trace message
javax.naming.NoInitialContextException: Need to specify class name in environmen t or system property, or as an applet parameter, or in an application resource f ile: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.lookup(Unknown Source) at MessageSender.main(MessageSender.java:10)
> > i got > >"NamingException"....whats the mistake ? [quoted text clipped - 5 lines] > Canadian Mind Products, Roedy Green. > http://mindprod.com Java custom programming, consulting and coaching. gk - 07 Nov 2005 09:46 GMT and here is the code....
import javax.jms.*; import javax.naming.*; public class MessageSender {
public static void main(String[] args) { QueueConnection queueConnection = null; try { Context context = new InitialContext(); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup("QueueConnectionFactory"); String queueName = "MyQueue"; Queue queue = (Queue) context.lookup(queueName); queueConnection = queueConnectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender queueSender = queueSession.createSender(queue); TextMessage message = queueSession.createTextMessage(); message.setText("This is a TextMessage"); queueSender.send(message); System.out.println("Message sent."); } catch (NamingException e) { e.printStackTrace(); // error message } catch (JMSException e) { System.out.println("JMS Exception"); } finally { if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) {} } } } }
HalcyonWild - 07 Nov 2005 10:43 GMT > and here is the code.... > [quoted text clipped - 38 lines] > } > }
>From what you have posted it seems that you have set up your Jndi service properly. I dont know about Jboss, but you can set up your Jndi Properties in Weblogic and websphere from the console.
gk - 07 Nov 2005 10:57 GMT but i am not using any server . i have kept j2ee.jar in my classpath of course.
do you mean , i must use a server ?
without server i can not run a "hello world" JMS application ?
i am a beginner in JMS
Thomas G. Marshall - 07 Nov 2005 13:52 GMT gk coughed up:
> and here is the code.... > > import javax.jms.*; ...[non indented code snipped out of existance]...
Your code (as viewed by internet explorer, and the message source itself) has all of its indentation removed. (I'm assuming you put it there originally).
This can happen when you cut and paste from some editors directly into a newspost. This is almost always because you are using hard tabs.
If you insist on using hard tabs (instead of having them converted to spaces), then try pasting your example directly into another editor first. On windows, for example, if you paste into something like WordPad IIRC, you can cut and paste it from there to a post.
 Signature Everythinginlifeisrealative.Apingpongballseemssmalluntilsomeoneramsitupyournose.
Roedy Green - 07 Nov 2005 10:28 GMT >javax.naming.NoInitialContextException: Need to specify class name in >environmen >t or system property, or as an applet parameter, or in an application >resource f You still are keeping secret your source code. Somewhere in there you construct a context e..g something like:
InitialLdapContext lctx = new InitialLdapContext(env, critConnCtls);
The env is a hashtable of properties. The exception is complaining it is not complete. For example, you need a property called java.naming.factory.initial which names a factory class.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
gk - 07 Nov 2005 10:55 GMT >You still are keeping secret your source code. Somewhere in there you >construct a context e..g something like: but that is the code written in my book. i am learning from the book. so , i copied from the book and compiled. but at the run time i got exception.
what more code i have to add into my program ?
plz add the additional code so that i can run and test and understand.
i cant make it working.
Roedy Green - 07 Nov 2005 11:41 GMT >but that is the code written in my book. i am learning from the book. >so , i copied from the book and compiled. but at the run time i got >exception. Then there is something else you must do to get JMS prepared. Textbooks tend to leave out the platform specific steps. See what you can find on the web by searching for the classes you are using, to find some other sample code, hopefully with some additional hints.
Also read the docs that came with your JMS implementation about any configuration files you need to set up.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
gk - 07 Nov 2005 12:43 GMT as you know JMS...will you please tell ..whats the code snippet is missingin my above code ?
you told..
InitialLdapContext lctx = new InitialLdapContext(env, critConnCtls);
these are not clear to me .... and also i did not find it in my book....you are using LDAP...
can you please post the needed code snippet ?
gk - 07 Nov 2005 12:59 GMT do i need a server at all ? i have a standalone application.
HalcyonWild - 07 Nov 2005 13:10 GMT > do i need a server at all ? > i have a standalone application. Yes my dear friend, you need a server to provide you JNDI services and JMS. Try using jboss or trial edition of websphere/weblogic. Sun also provides a test server with J2eeSdk.
BTW, which text are you referring. Guess you jumped to the chapter on JMS without reading earlier chapters. You need to.
Roedy Green - 07 Nov 2005 13:43 GMT >Yes my dear friend, you need a server to provide you JNDI services and >JMS. Try using jboss or trial edition of websphere/weblogic. Sun also >provides a test server with J2eeSdk. JMS is not built in. You need a JMS implementor. See http://mindprod.com/jgloss/jms.html follow the link to a list of implementors.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Thomas G. Marshall - 07 Nov 2005 14:10 GMT HalcyonWild coughed up:
>> do i need a server at all ? >> i have a standalone application. [quoted text clipped - 5 lines] > BTW, which text are you referring. Guess you jumped to the chapter on > JMS without reading earlier chapters. You need to. Suggest to him the easiest book on the subject you can imagine. I don't know of any myself.
 Signature Everythinginlifeisrealative.Apingpongballseemssmalluntilsomeoneramsitupyournose.
HalcyonWild - 07 Nov 2005 16:06 GMT > HalcyonWild coughed up: > > [quoted text clipped - 7 lines] > > BTW, which text are you referring. Guess you jumped to the chapter on > > JMS without reading earlier chapters. You need to.
> Suggest to him the easiest book on the subject you can imagine. I don't > know of any myself. I am really not sure if you can run JNDI or JMS without a server like weblogic or jboss or sun app server or even tomcat. I have never come across any JMS impl without a server. I am sure of Servlets, JSP and EJB though, you need a server.
Regarding the book, I got my knowledge on the job, and online. Never read any book, except java complete by herbert schildt, and thinking in java by bruce eckel print edition (read a bit online, then i thought i must buy it). I was very much more into C++ in college, and the first job I got was on Java. I had a course on Java though, for which I read Herb Schildt.
for j2ee, the best book, IMHO , I have ever seen (havent read it completely though) is java server programming by subrahmanyam allamaraju ( a BEA engineer ), and others. very clear and lucid. Guess it is apress or wrox publication.
Daniel Dyer - 07 Nov 2005 16:19 GMT > I am really not sure if you can run JNDI or JMS without a server like > weblogic or jboss or sun app server or even tomcat. I have never come > across any JMS impl without a server. I am sure of Servlets, JSP and > EJB though, you need a server. There are JMS implementations that are decoupled from J(2)EE containers. I think ActiveMQ (http://www.activemq.org) can run standalone.
Dan.
 Signature Daniel Dyer http://www.dandyer.co.uk
Roedy Green - 07 Nov 2005 13:41 GMT >as you know JMS...will you please tell ..whats the code snippet is >missingin my above code ? I have never used JMS. I have done Email server lookups. Maybe this code I wrote might give you hint what is wrong with yours.
/** * Gets all matching dns records as an array of strings. * * @param domain domain, e.g. oberon.ark.com or oberon.com which you want * the DNS records. * * @param types e.g. new String {"MX","A"} * to describe which types of record you want. * @return ArrayList of Strings */ static ArrayList getDNSRecs (String domain, String[] types) throws NamingException { ArrayList results = new ArrayList(15); DirContext ictx = new InitialDirContext(); Attributes attrs = ictx.getAttributes("dns://" + dnsServer + "/" + domain, types); for ( Enumeration e = attrs.getAll(); e.hasMoreElements(); ) { Attribute a = (Attribute) e.nextElement(); int size = a.size(); for ( int i=0; i<size; i++ ) { // MX string has priority (lower better) followed by associated mailserver // A string is just IP results.add(a.get(i)); } // end inner for } // end outer for
return results; }
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Thomas G. Marshall - 07 Nov 2005 14:13 GMT Roedy Green coughed up:
>> as you know JMS...will you please tell ..whats the code snippet is >> missingin my above code ? [quoted text clipped - 4 lines] > /** > * Gets all matching dns records as an array of strings. ...[rip]...
Is it my imagination, or is everyone now bending over backwards to not insult newbies. Bravo everyone. That is far tougher than it sounds.
 Signature Everythinginlifeisrealative.Apingpongballseemssmalluntilsomeoneramsitupyournose.
Andrew Thompson - 07 Nov 2005 14:28 GMT ...
> Is it my imagination, or is everyone now bending over backwards to not > insult newbies. Bravo everyone. That is far tougher than it sounds. Of course, it becomes much easier if the noobs post to a particular group*, then you can simply ignore that group if you do not have the time or patience to 'bend over backwards'.
If this trend contiinues, c.l.j.p will become full of words of niceness, ..but less technical content, and ultimately, less of the more experienced posters will find the time to wade through the dross.
Looking forward to it?
* Gee.. guess which group I'm thinking of.
Thomas G. Marshall - 07 Nov 2005 16:06 GMT Andrew Thompson coughed up:
...[rip]...
> If this trend contiinues, c.l.j.p will become full of > words of niceness, Overstated. To have beginner questions in .programmer was established anyway, and there was no reason to expect otherwise, especially given that the description of the group does not specify what you insist it should. You can invent all the pretend rules you like, but once you started calling ignorant questions in .programmer "stupid", I'll no longer put up with it. We've been through this before. I did not intend to reopen this debate---I intended this as a compliment toward something difficult to do---I should have kept my mouth shut since it seemed to have gotten better.
...[rip]...
 Signature Onedoctortoanother:"Ifthisismyrectalthermometer,wherethehell'smypen???"
HalcyonWild - 07 Nov 2005 16:12 GMT > ... > > Is it my imagination, or is everyone now bending over backwards to not [quoted text clipped - 13 lines] > > * Gee.. guess which group I'm thinking of. ----------
Andrew, Guess you can just tell them to post on a noob group, rather than making fun of them. If you ridicule them, they will just ignore your posts and continue posting here.
Thomas G. Marshall - 07 Nov 2005 17:01 GMT HalcyonWild coughed up:
>> ... >>> Is it my imagination, or is everyone now bending over backwards to not [quoted text clipped - 18 lines] > than making fun of them. If you ridicule them, they will just ignore > your posts and continue posting here. Right. There is nothing wrong with urging them to post to c.l.j.help if you think that there are more newbies there at the moment. Just don't {insert the prior points here}."
 Signature If I can ever figure out how, I hope that someday I'll succeed in my lifetime goal of creating a signature that ends with the word "blarphoogy".
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|