无法加载主类

时间:2015-03-04 13:45:27

标签: java

package org;

import java.io.*;
import java.util.Hashtable;
import javax.jms.JMSException;
//Few more

public class QueueSend
{
  public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
  public final static String JMS_FACTORY="QCF";
  public final static String QUEUE="TestQ";

  private QueueConnectionFactory qconFactory;
  private QueueConnection qcon; 
  private QueueSession qsession;
  private QueueSender qsender;
  private Queue queue;
  private TextMessage msg;

 public void init(Context ctx, String queueName)
    throws NamingException, JMSException
{
   qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
   qcon = qconFactory.createQueueConnection();
   qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   queue = (Queue) ctx.lookup(queueName);
   qsender = qsession.createSender(queue);
   msg = qsession.createTextMessage();
   qcon.start();
}

    public void send(String message) throws JMSException {
    msg.setText(message);
    qsender.send(msg);
    }

    public void close() throws JMSException {
    qsender.close();
    qsession.close();
    qcon.close();
    }

    public static void main(String[] args) throws Exception {
    if (args.length != 1) {
    System.out.println("Usage: java QueueSend WebLogicURL");
    return;
    }
    InitialContext ic = getInitialContext(args[0]);
    QueueSend qs = new QueueSend();
    qs.init(ic, QUEUE);
    readAndSend(qs);
    qs.close();
    }

    private static void readAndSend(QueueSend qs) throws IOException, JMSException
    {
    String line="Test Message Body with counter = ";
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    boolean readFlag=true;
    System.out.println("\n\tStart Sending Messages (Enter QUIT to Stop):\n");
    while(readFlag)
    {
    System.out.print("<Msg_Sender> ");
    String msg=br.readLine();
    if(msg.equals("QUIT") || msg.equals("quit"))
    {
    qs.send(msg);
    System.exit(0);
    }
    qs.send(msg);
    System.out.println();
    }
    br.close();
    }

    private static InitialContext getInitialContext(String url) throws NamingException
    {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
    env.put(Context.PROVIDER_URL, url);
    return new InitialContext(env);
    }
    }

From this link

目录结构

 org 
   QueueSend.java

 pwd

   /path-to/org

编译

 javac QueueSend.java

在org中创建类文件

 cd ..

 pwd

     parent of org

运行

 java QueueSend t3://localhost:7001

无法找到或加载主类错误

然后我搬进了ord

 cd org

执行相同的运行命令并得到相同的错误。我知道我们必须使用fully qulaified name它是org.QueueSend但我错过了一些东西

可能是什么原因?怎么解决这个问题?

2 个答案:

答案 0 :(得分:1)

您必须致电java -cp ./ org.QueueSend t3://localhost:7001。包名称是类名的一部分。而且你必须添加类路径的实际路径,所以jre看起来是类。

答案 1 :(得分:0)

看起来像输入错误 - 大写S.

您的类和Java文件具有QueueSend。你的运行命令有Queuesend。