cornercorner
FeaturesPluginsDocs & SupportCommunityPartners

NBzhCNfaq20081023

NetBeans 有问必答活动 - 2008/10/23

  • 1:【有问必答】NetBeans 6.1 在 New Project 时是如何决定使用哪个 Encoding 的?

开始接触 NetBeans 6.1
安装好后预设建立新项目是使用 UTF-8 的编码
当需要建立一个使用 Big5 编码的新项目却无法在过程中决定使用的编码
必须产生 UTF-8 编码的项目然后再去调整编码,还要手动个别去修改预设产生的程序的编码
而转换过项目编码后,后续新建项目就会变成使用 Big5 的编码
还要再次转换某个项目编码为 UTF-8 后,才会回复成新建项目为 UTF-8 编码
真是有些繁琐
不知道有何方法来直接决定新建项目的编码呢?
Rebecca: 目前来说好像不行呢,只有建了项目以后再去属性里更改,是比较麻烦,希望你可以去netbeans.org上提出一个"Enhancement";如果有需求的人比较多,他们就会考虑加这个feature。***

  • 2:【有问必答】请问MDB Destination在netbeans 6 & glassfish V2的设定问题


大家好, 今天我在读MDB的时候, 想要实作看看, 可是遇到一些好像是设定上的问题,
上网查也没看到明显的解答

情形描述如下.
我只做MessageProducer的时候都没问题, 可以把destination信息印出来, 执行后也没有异常状况.
Producer的程序如下:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
@Stateless
public class TestMessageProducer implements ITestMessageProducer {

   @Resource(name="TestQueueConnectionFactory")
private ConnectionFactory queueConnectionFactory;
private Connection queueConnection;
@Resource(name="TestQueueDestination")
private Destination queueDestination;
@Resource(name="TestTopicConnectionFactory")
private ConnectionFactory topicConnectionFactory;
private Connection topicConnection;
@Resource(name="TestTopicDestination")
private Destination topicDestination;
@PostConstruct
private void init() {
try {
queueConnection = queueConnectionFactory.createConnection();
topicConnection = topicConnectionFactory.createConnection();
} catch (JMSException ex) {
Logger.getLogger(TestMessageProducer.class.getName()).log(Level.SEVERE, null, ex);
}
}
@PreDestroy
private void destroy() {
try {
queueConnection.close();
topicConnection.close();
} catch (JMSException ex) { Logger.getLogger(TestMessageProducer.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void produceQueueMsg() {
try {
if ( queueConnection != null ) {
Session session = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queueDestination);
System.out.println("queueConnection:" + queueConnection);
System.out.println("queueDestination" + queueDestination);
TextMessage textMsg = session.createTextMessage();
textMsg.setText("This is queue text message");
producer.send(textMsg);
session.close();
}
} catch (JMSException ex) {
Logger.getLogger(TestMessageProducer.class.getName()).log(Level.SEVERE, null, ex);
}
}
   public void produceTopicMsg() {
try {
if ( topicConnection != null ) {
Session session = topicConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topicDestination);
System.out.println("topicConnection:" + topicConnection);
System.out.println("topicDestination:" + topicDestination);
TextMessage textMsg = session.createTextMessage();
textMsg.setText("This is topic text message");
producer.send(textMsg);
session.close();
}
} catch (JMSException ex) {
Logger.getLogger(TestMessageProducer.class.getName()).log(Level.SEVERE, null, ex);
}
}

}



可是当我加上MDB的时候就不行了
12345678910111213141516171819202122
@MessageDriven(

   activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destinationName", propertyValue = "TestQueueDestination")
}

)
public class TestSimpleQueueMDB implements MessageListener {

   @Resource
private MessageDrivenContext context;
public void onMessage(Message message) {
try {
TextMessage txtMsg = (TextMessage) message;
System.out.println( this + " get message: " + txtMsg.getText() );
} catch (JMSException ex) {
context.setRollbackOnly();
Logger.getLogger(TestSimpleQueueMDB.class.getName()).log(Level.SEVERE, null, ex);
}
}

}



他会出现以下错误
1234567891011121314151617181920
MDB00017: TestSimpleQueueMDB: Exception in creating message-driven bean container: com.sun.enterprise.connectors.ConnectorRuntimeException: JMS resource not created :
com.sun.enterprise.connectors.ConnectorRuntimeException
com.sun.enterprise.connectors.ConnectorRuntimeException: JMS resource not created :

       at 
com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.getPhysicalDestinationFromConfiguration(ActiveJmsResourceAdapter.java:1528)
at com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.updateMDBRuntimeInfo(ActiveJmsResourceAdapter.java:1379)
at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:170)
at com.sun.ejb.containers.MessageBeanContainer.<init>
(MessageBeanContainer.java:209) at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:524)
at com.sun.enterprise.server.AbstractLoader.loadEjbs(AbstractLoader.java:536)

...(略过) EJB5090: Exception in creating EJB container com.sun.enterprise.connectors.ConnectorRuntimeException: JMS resource not created :
appId=ServletStateless moduleName=ServletStateless-ejb_jar ejbName=TestSimpleQueueMDB
LDR5004: UnExpected error occured while creating ejb container
com.sun.enterprise.connectors.ConnectorRuntimeException: JMS resource not created :

       at 
com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.getPhysicalDestinationFromConfiguration(ActiveJmsResourceAdapter.java:1528)
at
com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.updateMDBRuntimeInfo(ActiveJmsResourceAdapter.java:1379)
at com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:170)
at com.sun.ejb.containers.MessageBeanContainer.<init>(MessageBeanContainer.java:209)
at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:524)

...(略过)



我有去查log中的一些壮况代号, 主要是说我有实做错或设定档没设好.
但由于我没有设定档, 都用annotation, 而且MDB我只实做简单的东西, 应该也不太会错才对.
不知道是不是JNDI没mapping好呢?
我尝试过几种命名, 也把producer的destination印出来打到MDB上都不行.

现在是如果MDB的设定不删掉, 连deploy都不行.
不知道有没有人知道这是为什么呢? 感谢



  • 3:【有问必答】NetBeans 6.01的清理问题

当我导入了第三方库的时候,比如Myfaces的tomahawk,再使用清理/生成功能时,总是不能删除 tomahawk.jar而失败。何故?还望指教
Michael: 试着把运用服务器关掉再做类似操作。这可能是运用服务器的一个BUG。*******



  • 4:【有问必答】在NetBeans 6.0.1建立Rails Project...


原本刚装好NetBeans 6.0.1时
内建的Rails版本是1.2
建立Rails Project时都正常

可是当我将Rails版本Update成2.0.2时
建立Rails Project出来的Folder里
只有 nbproject 跟 spec 两个folder...
这是怎么回事
Michael: 不同版本生成的项目结构有肯能不一样,关键是影响开发吗?如果开发一样的话,不必多虑到底生成几个folder****


  • 5:【有问必答】SelectionKey.isReadable()返回true,为什么还是读不到数据?


我在用别人写的一个叫做QuickServer的东西……发现有些时候它会意外地出现一些“无法从SocketChannel读取数据”的错误,经过调试定位到下面这段代码(已有简化,只展示关键逻辑):


iterator = selector.selectedKeys().iterator();
key = (SelectionKey) iterator.next();
if(key.isValid() && key.isReadable()) {

 _ch = (ClientHandler)key.attachment();
logger.finest("socket channel readable: available: " +
_ch.getSocketChannel().socket().getInputStream().available());

}
当if条件成立的时候,从log文件中看到的内容却是:
10-25-2008 09:44:35,671
org.quickserver.net.server.QuickServer.runNonBlocking - socket channel readable: available: 0

我理解如果SelectionKey.isReadable()返回true,就是说相关的socketChannel能读到数据,其read方法返回值不应该是-1。但是从上面的log和可以看出,相关联的socket的available()是0,之后的代码中,相关的socketChannel的read方法返回-1,完全就是没有数据可读的状态。

发生这个矛盾的原因是什么呢?是我对SelectionKey.isReadable()的理解不对?盼高手指教。
Michael: 这个我也没用过,还是阅读SelectionKey的javadoc更好些。****