title: Using EJBs with regular java classes. Trying to instantiate a stateless EJB
body: <p>I have a large web project in Java EE 6 so far everything is working great. </p>
  
  <p>Now I'm adding a new class that takes twitter information and returns a string. So far the strings have been extracted from the JSON file from twitter and are ready to be persisted in my database. My problem is I'm not sure how to pass information from the EJB that normally handles all of my database calls. I'm using JPA and have a DAO class that managers all database access. I already have a method there for <code>updateDatabase(String)</code>. I'd like to be able to call <code>updateDatabase(String)</code> from the class that has the strings to add but I don't know if it's good form to instantiate a stateless bean like that. Normally you inject beans and then call just their class name to access their methods. I could also maybe try and reference the twitter string generating class from inside of the EJB but then I'd have to instantiate it there and mess with main() method calls for execution. I'm not really sure how to do this.  Right now my Twitter consuming class is just a POJO with a main method. For some reason some of the library methods did not work outside of main in face IOUtils() API directly says "Instances should NOT be constructed in standard programming".  </p>
  
  <p>So on a higher level bottom line, I'm just asking how POJO's are normally "mixed" into a Java EE project where most of your classes are EJBs and servlets.  </p>
  
  <p>Edit: the above seems confusing to me after rereading so I'll try to simplify it. basically I have a class with a main method. I'd like to call my EJB class that handles database access and call it's <code>updateDatabase(String)</code> method and just pass in the string. How should I do this?</p>
  
  <p>Edit: So it looks like a JNDI lookup and subsequence reference is the preferred way to do this rather than instantiating the EJB directly? </p>
  
  <p>Edit: these classes are all in the same web project. In the same package. I could inject one or convert the POJO to an EJB. However the POJO does have a main method and some of the library files do not like to be instantiated so running it in main seems like the best option. </p>
  
  <p>My main code:</p>
  
  <pre><code>public class Driver {
  
      @EJB
      static RSSbean rssbean;   
  
      public static void main(String[] args) throws Exception {
  
          System.setProperty("http.proxyHost", "proxya..com");
          System.setProperty("http.proxyPort", "8080");
          /////////////auth code///////////////auth code/////////////////
          String username = System.getProperty("proxy.authentication.username");
          String password = System.getProperty("proxy.authentication.password");
          if (username == null) {
              Authenticator.setDefault(new ProxyAuthenticator("", ""));
          }
          ///////////////end auth code/////////////////////////////////end
  
          URL twitterSource = new URL("http://search.twitter.com/search.json?q=google");
          ByteArrayOutputStream urlOutputStream = new ByteArrayOutputStream();
  
          IOUtils.copy(twitterSource.openStream(), urlOutputStream);
          String urlContents = urlOutputStream.toString();
          JSONObject thisobject = new JSONObject(urlContents);
          JSONArray names = thisobject.names();
          JSONArray asArray = thisobject.toJSONArray(names);
          JSONArray resultsArray = thisobject.getJSONArray("results");
          JSONObject(urlContents.substring(urlContents.indexOf('s')));                
          JSONObject jsonObject = resultsArray.getJSONObject(0);
  
          String twitterText = jsonObject.getString("text");          
          rssbean.updateDatabase("twitterText"); 
      }
  }  
  </code></pre>
  
  <p>I'm also getting a <code>java.lang.NullPointerException</code> somewhere around <code>rssbean.updateDatabase("twitterText");</code></p>