This discussion is archived
12 Replies Latest reply: Dec 13, 2012 10:48 AM by 938489 RSS

How to use context lookup without  jboss and tomcat

938489 Newbie
Currently Being Moderated
We have read this sample http://blog-milind.blogspot.com/search/label/Enterprise%20Java which shows an example on distributed transaction for java. The problem here they implemented jboss and tomcat. We just need pure java application without anything to do with the web. So how to build for e.g. DataSource ds1 = (DataSource)ctx.lookup("java:ds1"); ? Any idea?
  • 1. Re: How to use context lookup without  jboss and tomcat
    rp0428 Guru
    Currently Being Moderated
    >
    We have read this sample http://blog-milind.blogspot.com/search/label/Enterprise%20Java which shows an example on distributed transaction for java. The problem here they implemented jboss and tomcat. We just need pure java application without anything to do with the web. So how to build for e.g. DataSource ds1 = (DataSource)ctx.lookup("java:ds1"); ? Any idea?
    >
    So find another example that does whatever unknown thing it is that you want to do.

    When you post a thread you need to firt state what you ARE trying to do. Saying what you do NOT want to do doesn't really tell us what you DO want to do.

    1. So start over and identify your goal.
    2. Search the web and try to find documentation and examples for that goal.
    3. Read the documentation for the technical areas involved in your project.
    4. Try one, or more, of those examples

    If you run into a problem then post ALL of the information about what you did in steps 1 thru 4 above and ask questions about what you don't understand.
    >
    We just need pure java application without anything to do with the web.
    >
    Tomcat and JBOSS ARE Java applications. You can use them both on one pc or in a network and not use the 'web' (whatever you mean by that) at all.
    >
    So how to build for e.g. DataSource ds1 = (DataSource)ctx.lookup("java:ds1"); ? Any idea?
    >
    Good start; that is step #1: state an actual question or goal.

    Now for step #2: Search the web and try to find documentation and examples for that goal

    A 'ctx' usually means a JNDI context so if I use my favorite search engine and search for 'java jndi tutorial' right on the very first page is this:

    The JNDI Tutorial - Building Directory-Enabled Java Applications
    http://docs.oracle.com/javase/jndi/tutorial/

    Amazing! A JNDI Tutorial! And from the URL is appears to be part of the Oracle documentation for Java Standard Edition.

    There are links for the Basics
    http://docs.oracle.com/javase/jndi/tutorial/basics/index.html
    >
    The lessons in this trail explain how to write applications that access naming and directory services. They give you the basics of how to interact with the directory using the JNDI, from preparing the environment, to looking up objects from the namespace, to searching the directory.
    The Preparations lesson covers how to set up your environment to compile and run JNDI programs.

    The Naming Operations lesson explains how to perform naming operations, such as looking up objects and removing them from the naming service.

    The Directory Operations lesson discusses how to perform directory operations, including searching and modifying entries in the directory.
    >
    Naming operations
    http://docs.oracle.com/javase/jndi/tutorial/basics/naming/index.html
    >
    You can use the JNDI to perform naming operations, including read operations and operations for updating the namespace. The following operations are described in this lesson:

    Looking up an object
    Listing the contents of a context
    Adding, overwriting, and removing a binding
    Renaming an object
    Creating and destroying subcontexts
    >
    And a complete trail covering the entire subject matter of JNDI.

    If you do the same search you will find many, many more such tutorials and examples, including some on YouTube.
  • 2. Re: How to use context lookup without  jboss and tomcat
    938489 Newbie
    Currently Being Moderated
    Dear rp0428,
    Sorry for my vague post earlier. My problem is actually quite simple. What I am going to do is on very minute run a daemon on this local machine and check for available data to be inserted into a remote machine. So I was thinking by using distributed transaction I can ensure that the local data and both the remote are sync well. That is the key reason me looking for distributed transaction hope you can shed some light on this matter.
  • 3. Re: How to use context lookup without  jboss and tomcat
    rp0428 Guru
    Currently Being Moderated
    Nothing in what you just posted has anything to do with what you originally asked in this thread.
    >
    So how to build for e.g. DataSource ds1 = (DataSource)ctx.lookup("java:ds1"); ? Any idea?
    >
    I provided information that will answer your original question. If you now have a different question you need to create a new thread for it in the appropriate forum.
  • 4. Re: How to use context lookup without  jboss and tomcat
    938489 Newbie
    Currently Being Moderated
    Dear Rp028,
    Ok accordingly I will create a new thread to eliminate confusion. Sorry.
  • 5. Re: How to use context lookup without  jboss and tomcat
    Joe Weinstein Expert
    Currently Being Moderated
    If I can try re-interpreting your question, could it be:

    "I would like to run an XA transaction involving multiple resources, in a standalone
    Java program, with no container or external XA controller etc. For my first step,
    how do I get a DataSource to use for my transaction/connection, without knowing
    about or wanting JNDI lookup?".

    Is that correct?
  • 6. Re: How to use context lookup without  jboss and tomcat
    938489 Newbie
    Currently Being Moderated
    Dear Joe,
    Yes you got me right this is what I want to run the distributed transaction if possible without JNDI lookup is that possible?
  • 7. Re: How to use context lookup without  jboss and tomcat
    Joe Weinstein Expert
    Currently Being Moderated
    Well certainly, the first step in this is simple. Your DBMS resources will have specific
    DataSource objects associated with the, such as the Oracle thin driver's
    oracle.jdbc.xa.client.OracleXADataSource. Simply instantiate all needed data sources
    and initiate them according to their documentation. Then you would get and
    manipulate XAConnections and Connections...
  • 8. Re: How to use context lookup without  jboss and tomcat
    938489 Newbie
    Currently Being Moderated
    Dear Joe,
    For this I must use JNDI or Tomcat or Apache is it? I am trying to avoid all this if possible. I am using mysql db is the Xa support available for it? Thank you.
  • 9. Re: How to use context lookup without  jboss and tomcat
    Joe Weinstein Expert
    Currently Being Moderated
    I am sorry there is too much to learn to do what you want.
  • 10. Re: How to use context lookup without  jboss and tomcat
    938489 Newbie
    Currently Being Moderated
    Dear Joe,
    Meaning to say that for the distributed transaction to work I cant avoid JBoss and Tomcat is it?
  • 11. Re: How to use context lookup without  jboss and tomcat
    Joe Weinstein Expert
    Currently Being Moderated
    No, you don't need those. I could write a 100-line java program to do an XA transaction.
    You just have to read the spec for the Java objects I talked about.
  • 12. Re: How to use context lookup without  jboss and tomcat
    938489 Newbie
    Currently Being Moderated
    I have google using this key words java mysql xa but if you look most of it are linking to Jboss. IS there any reference where I can follow for me to start off with out this Jboss or Tomcat? Thank you.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points