Wednesday, November 21, 2012

JSP JSTL String length

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"  %>
<c:if test="${fn:length(string)>0}">
...
</c:if>

Saturday, November 3, 2012

Create Temporary File In Java

Get The Current Working Directory In Java

package com.javaee.insight;

public class Main {
    public static void main(String args[]) {

        String workingDir = System.getProperty("user.dir");
        System.out.println("Current working directory : " + workingDir);

    }
}

Create a File in Java

Setting up ActiveMQ with Tomcat 7

Step 1. Place the activemq-all-5.7.0.jar in [TOMCAT_HOME]/lib directory

Step 2. Open the [TOMCAT_ROOT]/conf/context.xml file and add the below resource to the Context.

<Context>
 <Resource name="jms/ConnectionFactory" 
     auth="Container" 
     type="org.apache.activemq.ActiveMQConnectionFactory" 
     description="JMS Connection Factory"
     factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
     brokerURL="tcp://localhost:61616" 
     brokerName="LocalActiveMQBroker"/>

 <Resource 
    name="jms/queue/Queue" 
    auth="Container" 
    type="org.apache.activemq.command.ActiveMQQueue" 
    description="my Queue"
    factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
    physicalName="APP.QUEUE"/>

</Context>
Step 3. Add the JNDI in your java code.
   InitialContext initCtx = new InitialContext();
        Context envContext = (Context) initCtx.lookup("java:comp/env");
        
        ConnectionFactory connectionFactory = (ConnectionFactory) envContext.lookup("jms/ConnectionFactory");
        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("jms/queue/Queue");
        MessageProducer producer = session.createProducer(destination);
        TextMessage msg = session.createTextMessage();
        msg.setText("Message sent");
        producer.send(msg);

Print the Current Project Classpath