Olá!

Quando criamos um programa em java e queremos mostrar alguma mensagem no console usamos inconscientemente o System.out.println(), mas e para gravar essas mesmas mensagens em um arquivo texto? Muito simples, basta dar um System.setOut() passando o PrintStream desejado. No exemplo abaixo alteramos a saída padrão, que era no console, para um arquivo texto.

String path = "D:\\saida.txt";
FileOutputStream fileOutputStream = null;
	try {
		fileOutputStream = new FileOutputStream(path);
		System.setOut(new PrintStream(fileOutputStream, true));
		System.out.println("Teste");
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}

Até mais
Roberto

Share

Olá!

Faz tempo que eu não posto nada no blog, então hoje vou deixar um exemplo bem simples de serviço de mensageria JMS.

JMS – Java Messaging Service é uma arquitetura existente no universo J2EE que permite troca de mensagens de maneira assíncrona.

Este exemplo consiste em duas classes, Main que envia um MDB (Message Drive Bean) e a JMSProcessBean que recebe a mensagem e exibe no console o valor do atributo “nome”.

No projeto JMSTester verificar se as bibliotecas abaixos estão corretamente referenciadas. Utilizei a instalação padrão do netbeans 6.7.1 e do glassfish v2.1.

C:\Sun\AppServer\lib\appserv-admin.jar
C:\Sun\AppServer\lib\appserv-rt.jar
C:\Sun\AppServer\imq\lib\imq.jar
C:\Sun\AppServer\lib\install\applications\jmsra\imqjmsra.jar
C:\Sun\AppServer\lib\j2ee.jar
C:\Sun\AppServer\lib\install\applications\jaxr-ra\jaxr-ra.jar
C:\Sun\AppServer\imq\lib\jms.jar

Na administração do Glassfish é possível verificar se o JMS foi corretamente implantado.

jms-glassfish

Ao executar a classe Main teremos a saída abaixo (observe a última linha):

run:
13/11/2009 23:10:58 com.sun.appserv.naming.RoundRobinPolicy setClusterInstanceInfo
WARNING: NAM1005 : No Endpoints selected. Please specify using system property com.sun.appserv.iiop.endpoints.
13/11/2009 23:10:58 com.sun.appserv.naming.RoundRobinPolicy getEndpointForProviderURL
WARNING: NAM1001: No Endpoints selected in com.sun.appserv.iiop.endpoints property. Using JNDI Provider URL iiop://127.0.0.1:3700 instead
13/11/2009 23:10:59 com.sun.appserv.naming.RoundRobinPolicy setClusterInstanceInfo
INFO: endpoint.weight after checking isWeight = 10
13/11/2009 23:10:59 com.sun.appserv.naming.RoundRobinPolicy setClusterInstanceInfo
INFO: sumOfAllWeights = 10
13/11/2009 23:10:59 com.sun.appserv.naming.S1ASCtxFactory getCorbalocURL
INFO: list[i] ==> 127.0.0.1:3700
13/11/2009 23:10:59 com.sun.appserv.naming.S1ASCtxFactory getCorbalocURL
INFO: corbaloc url ==> iiop:1.2@127.0.0.1:3700
13/11/2009 23:11:00 com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: SJSMQ JMS Resource Adapter starting…
13/11/2009 23:11:00 com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: SJSMQ JMSRA Started:REMOTE
13/11/2009 23:11:00 com.sun.messaging.jms.ra.ManagedConnectionFactory setAddressList
INFO: MQJMSRA_MF1101: setAddressList:NOT setting default value=localhost
13/11/2009 23:11:00 com.sun.messaging.jms.ra.ManagedConnectionFactory setPassword
INFO: MQJMSRA_MF1101: setPassword:NOT setting default value
13/11/2009 23:11:00 com.sun.messaging.jms.ra.ManagedConnectionFactory setUserName
INFO: MQJMSRA_MF1101: setUserName:NOT setting default value=guest
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=1:xacId=6281999144483361280:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=2:xacId=6281999144483371776:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=3:xacId=6281999144483379200:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=4:xacId=6281999144483388416:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=5:xacId=6281999144483394816:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=6:xacId=6281999144483402752:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=7:xacId=6281999144483408896:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
13/11/2009 23:11:01 com.sun.messaging.jms.ra.ManagedConnection <init>
INFO: MQJMSRA_MC1101: constructor:Created mcId=8:xacId=6281999144483415808:Using xacf config={imqOverrideJMSPriority=false, imqConsumerFlowLimit=1000, imqOverrideJMSExpiration=false, imqAddressListIterations=3, imqLoadMaxToServerSession=true, imqConnectionType=TCP, imqPingInterval=30, imqSetJMSXUserID=false, imqConfiguredClientID=, imqSSLProviderClassname=com.sun.net.ssl.internal.ssl.Provider, imqJMSDeliveryMode=PERSISTENT, imqConnectionFlowLimit=1000, imqConnectionURL=http://localhost/imq/tunnel, imqBrokerServiceName=, imqJMSPriority=4, imqBrokerHostName=localhost, imqJMSExpiration=0, imqAckOnProduce=, imqEnableSharedClientID=false, imqAckTimeout=0, imqAckOnAcknowledge=, imqConsumerFlowThreshold=50, imqDefaultPassword=guest, imqQueueBrowserMaxMessagesPerRetrieve=1000, imqDefaultUsername=guest, imqReconnectEnabled=true, imqConnectionFlowCount=100, imqAddressListBehavior=RANDOM, imqReconnectAttempts=3, imqSetJMSXAppID=false, imqConnectionHandler=com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler, imqSetJMSXRcvTimestamp=false, imqBrokerServicePort=0, imqDisableSetClientID=false, imqSetJMSXConsumerTXID=false, imqOverrideJMSDeliveryMode=false, imqBrokerHostPort=7676, imqQueueBrowserRetrieveTimeout=60000, imqSetJMSXProducerTXID=false, imqSSLIsHostTrusted=false, imqConnectionFlowLimitEnabled=false, imqReconnectInterval=5000, imqAddressList=mq://Furutani:7676/, imqOverrideJMSHeadersToTemporaryDestinations=false}
Mensagens enviadas!

No console do Glassfish v2.1 teremos a seguinte saída:

13/11/2009 23:08:51 com.sun.enterprise.admin.servermgmt.launch.ASLauncher buildCommand
INFO:
C:/Program Files/Java/jdk1.6.0_11\bin\java
-Dcom.sun.aas.instanceRoot=C:/Sun/AppServer/domains/domain1
-Dcom.sun.aas.ClassPathPrefix=
-Dcom.sun.aas.ClassPathSuffix=
-Dcom.sun.aas.ServerClassPath=
-Dcom.sun.aas.classloader.appserverChainJars.ee=
-Dcom.sun.aas.classloader.appserverChainJars=admin-cli.jar,admin-cli-ee.jar,j2ee-svc.jar
-Dcom.sun.aas.classloader.excludesList=admin-cli.jar,appserv-upgrade.jar,sun-appserv-ant.jar
-Dcom.sun.aas.classloader.optionalOverrideableChain.ee=
-Dcom.sun.aas.classloader.optionalOverrideableChain=webservices-rt.jar,webservices-tools.jar
-Dcom.sun.aas.classloader.serverClassPath.ee=Does not exist/lib/hadbjdbc4.jar,C:/Sun/AppServer/lib/SUNWjdmk/5.1/lib/jdmkrt.jar,Does not exist/lib/dbstate.jar,Does not exist/lib/hadbm.jar,Does not exist/lib/hadbmgt.jar,C:/Sun/AppServer/lib/SUNWmfwk/lib/mfwk_instrum_tk.jar
-Dcom.sun.aas.classloader.serverClassPath=C:/Sun/AppServer/lib/install/applications/jmsra/imqjmsra.jar,C:/Sun/AppServer/imq/lib/jaxm-api.jar,C:/Sun/AppServer/imq/lib/fscontext.jar,C:/Sun/AppServer/imq/lib/imqbroker.jar,C:/Sun/AppServer/imq/lib/imqjmx.jar,C:/Sun/AppServer/lib/ant/lib/ant.jar,C:/Sun/AppServer/lib/SUNWjdmk/5.1/lib/jdmkrt.jar
-Dcom.sun.aas.classloader.sharedChainJars.ee=appserv-se.jar,appserv-ee.jar,jesmf-plugin.jar,Does not exist/lib/dbstate.jar,Does not exist/lib/hadbjdbc4.jar,jgroups-all.jar,C:/Sun/AppServer/lib/SUNWmfwk/lib/mfwk_instrum_tk.jar
-Dcom.sun.aas.classloader.sharedChainJars=javaee.jar,C:/Program Files/Java/jdk1.6.0_11/lib/tools.jar,install/applications/jmsra/imqjmsra.jar,com-sun-commons-launcher.jar,com-sun-commons-logging.jar,C:/Sun/AppServer/imq/lib/jaxm-api.jar,C:/Sun/AppServer/imq/lib/fscontext.jar,C:/Sun/AppServer/imq/lib/imqbroker.jar,C:/Sun/AppServer/imq/lib/imqjmx.jar,C:/Sun/AppServer/imq/lib/imqxm.jar,webservices-rt.jar,webservices-tools.jar,mail.jar,appserv-jstl.jar,jmxremote_optional.jar,C:/Sun/AppServer/lib/SUNWjdmk/5.1/lib/jdmkrt.jar,activation.jar,appserv-rt.jar,appserv-admin.jar,appserv-cmp.jar,C:/Sun/AppServer/updatecenter/lib/updatecenter.jar,C:/Sun/AppServer/jbi/lib/jbi.jar,C:/Sun/AppServer/imq/lib/imqjmx.jar,C:/Sun/AppServer/lib/ant/lib/ant.jar,dbschema.jar
-Dcom.sun.aas.configName=server-config
-Dcom.sun.aas.configRoot=C:/Sun/AppServer/config
-Dcom.sun.aas.defaultLogFile=C:/Sun/AppServer/domains/domain1/logs/server.log
-Dcom.sun.aas.domainName=domain1
-Dcom.sun.aas.installRoot=C:/Sun/AppServer
-Dcom.sun.aas.instanceName=server
-Dcom.sun.aas.processLauncher=SE
-Dcom.sun.aas.promptForIdentity=true
-Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
-Dcom.sun.enterprise.overrideablejavaxpackages=javax.help,javax.portlet
-Dcom.sun.enterprise.taglibs=appserv-jstl.jar,jsf-impl.jar
-Dcom.sun.enterprise.taglisteners=jsf-impl.jar
-Dcom.sun.updatecenter.home=C:/Sun/AppServer/updatecenter
-Ddomain.name=domain1
-Djava.endorsed.dirs=C:/Sun/AppServer/lib/endorsed
-Djava.ext.dirs=C:/Program Files/Java/jdk1.6.0_11/lib/ext;C:/Program Files/Java/jdk1.6.0_11/jre/lib/ext;C:/Sun/AppServer/domains/domain1/lib/ext;C:/Sun/AppServer/javadb/lib
-Djava.library.path=C:\Sun\AppServer\lib;C:\Sun\AppServer\lib;C:\Sun\AppServer\bin;C:\Sun\AppServer\bin
-Djava.security.auth.login.config=C:/Sun/AppServer/domains/domain1/config/login.conf
-Djava.security.policy=C:/Sun/AppServer/domains/domain1/config/server.policy
-Djava.util.logging.manager=com.sun.enterprise.server.logging.ServerLogManager
-Djavax.management.builder.initial=com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder
-Djavax.net.ssl.keyStore=C:/Sun/AppServer/domains/domain1/config/keystore.jks
-Djavax.net.ssl.trustStore=C:/Sun/AppServer/domains/domain1/config/cacerts.jks
-Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
-Djmx.invoke.getters=true
-Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000
-client
-XX:+UnlockDiagnosticVMOptions
-XX:MaxPermSize=192m
-Xmx512m
-XX:NewRatio=2
-XX:+LogVMOutput
-XX:LogFile=C:/Sun/AppServer/domains/domain1/logs/jvm.log
-cp
C:/Sun/AppServer/lib/jhall.jar;C:\Sun\AppServer\lib\appserv-launch.jar
com.sun.enterprise.server.PELaunch
start
CORE5076: Using [Java HotSpot(TM) Client VM, Version 1.6.0_11] from [Sun Microsystems Inc.]
SEC1002: Security Manager is OFF.
Using MQ RA for Broker lifecycle control
SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
WEB0114: SSO is disabled in virtual server [server]
WEB0114: SSO is disabled in virtual server [__asadmin]
REgistering Custom ContextConfig
REgistering Custom Context
JTS5014: Recoverable JTS instance, serverId = [3700]
ADM1079: Initialization of AMX MBeans started
ADM1504: Here is the JMXServiceURL for the Standard JMXConnectorServer: [service:jmx:rmi:///jndi/rmi://Furutani:8686/jmxrmi].  This is where the remote administrative clients should connect using the standard JMX connectors
ADM1506: Status of Standard JMX Connector: Active = [true]
JMS Service Connection URL is :mq://Furutani:7676/
MQJMSRA_RA1101: SJSMQ JMS Resource Adapter starting…
MQJMSRA_EB1101: EMBEDDED broker started with code =0
MQJMSRA_RA1101: SJSMQ JMSRA Started:DIRECT
LDR5010: All ejb(s) of [MEjbApp] loaded successfully!
EJB5109:EJB Timer Service started successfully for datasource [jdbc/__TimerPool]
LDR5010: All ejb(s) of [__ejb_container_timer_app] loaded successfully!
endpoint.determine.destinationtype
LDR5010: All ejb(s) of [JMSProcess-ejb] loaded successfully!
JBIFW0010: JBI framework ready to accept requests.
WEB0302: Starting Sun-Java-System/Application-Server.
WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 8080
WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 8181
WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 4848
SMGT0007: Self Management Rules service is enabled
Application server startup complete.
MQJMSRA_MF1101: setAddressList:NOT setting default value=localhost
MQJMSRA_MF1101: setPassword:NOT setting default value
MQJMSRA_MF1101: setUserName:NOT setting default value=guest
Jundi
Furutani
Roberto

O que realmente importa são as três últimas linhas, elas indicam que as mensagens foram corretamentes enviadas e processadas.

Link: [download id=”25″ format=”2″]

Saiba mais sobre JMS acessando o tutorial da SUN neste link.

Até mais,
Roberto

Share

Olá!

Nada como um bom projeto open source para facilitar a nossa vida. Hoje fiz um teste com o Flying Saucer para capturar um screenshot (printscreen) de um site.

É muito, mas muito fácil fazer isso com esse projeto.

Basicamente só é preciso das três linhas abaixo.

BufferedImage buff = null;
buff = Graphics2DRenderer.renderToImageAutoSize("htt://www.furutani.com.br", 1024);
ImageIO.write(buff, "PNG", new File("d:/site.png"));

Para testar a geração de imagens de um site você pode usar essa aplicação que fiz: http://www.furutani.com.br/Html2Image/

O parser dele é bem rigorso, o site não pode ter nenhuma tag faltando fechar senão a imagem não é gerada.

Até mais,

Roberto

Flying SaucerFlying Saucer

Share

Olá!

Para ler um arquivo texto apartir de um ponto utilize o RandomAccessFile, esta classe possui o método seek() que permite posicionar o cursor em um determinado ponto do arquivo antes de começar a leitura linha-a-linha.
No exemplo abaixo, o método gerarArquivoGigante() cria um arquivo de 96MB e o método main() lê apenas os últimos 521KB desse arquivo.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;

public class LeitorArquivo {

public static void main(String[] args) {
// Inicia a leitura do arquivo
File file = new File(“D:\\ArquivoGigante.txt”);

try {
// Abre o arquivo em modo de leitura apenas
RandomAccessFile raf = new RandomAccessFile(file, “r”);
String linha = null;

// Lê apenas os 512KB do final do arquivo
raf.seek(raf.length() – 1024 * 512);

while ((linha = raf.readLine()) != null) {
// Mostra as linhas no console
System.out.println(linha);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

/*
* Gera um arquivo gigante (96,3MB)
*/
public static void gerarArquivoGigante() {
File file = new File(“D:\\ArquivoGigante.txt”);
try {
FileOutputStream fos = new FileOutputStream(file);
String linha = “ABCDEFGHACMNSHTYUEILOKJHSNMALOQPLOASGTEBH” +
“YNSDFGJMKLAKSJDQOEWIAAANNSJS”
+”JHGQYAUSKDOEPPKLKJHHGFQWERTYUJ”
+ System.getProperty(“line.separator”);
for (int idx = 0; idx < 1000000; idx++) fos.write(linha.getBytes()); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } [/sourcecode]

Share

Olá!

O Eclipse provê muitos tipos de buscas, desde os mais básicos como o Ctrl + F até busca por referências, declarações e etc.

Hoje vou deixar a dica da busca F4. F4 é a tecla de atalho para a busca da hierarquia de alguma classe ou interface. Na figura abaixo, mostro um exemplo do resultado dessa busca.

Eclipse

Eclipse

Para usar o F4, posicione o cursor sobre a classe ou interface no código-fonte e aperte F4, o resultado é mostrado na view Hierarchy.
Até mais,
Roberto

Share