Monday, November 3, 2014

Creating JMS Resources using Maven and WLST in 12c


As a first step we need to install maven plugin wls-maven-plugin.

This plugin present in the ORACLE_HOME/wlserver_12.1/server/lib

Open a command prompt and navigate to the above location

Now we need to install this plugin to our repository( here by default the repository will be the local repository which is present at  c:/users/<username>/.m2  (for windows)).

To install the plugin use the following command


mvn install:install-file -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml

Once the installation is successful we can verify whether the required goals are available using the following command

mvn com.oracle.weblogic:wls-maven-plugin:help

Here we can see the wlst task is available. 

Now we are ready to execute the WLST script using maven

Create a jms.properties file as shown below(change the values as per your requirement)
==================
domain.name=DefaultDomain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

jms.jmsserver=TEST_JMSSerer
jms.jmssystemresource=TEST_JMSSystemResource
jms.subdeployment=TEST_JMSSubdeployment
jms.queue=TEST_JMSQUEUE
jms.queue.jndi=jms/TEST_JMSQUEUE
jms.topic=TEST_JMSTOPIC
jms.topic.jndi=jms/TEST_JMSTOPIC
jms.targetserver=DefaultServer
============================================

Save the following python script as jmsobjects.py

note : remember to give the exact path to the jms.properties file)

========start of python script ==========

from java.io import FileInputStream

propInputStream = FileInputStream("path\\to\\jms.properties")
configProps = Properties()
configProps.load(propInputStream)

domainName=configProps.get("domain.name")
adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")

jms_server=configProps.get("jms.jmsserver")
jms_systemResource=configProps.get("jms.jmssystemresource")
jms_queue=configProps.get("jms.queue")
jms_queue_jndi=configProps.get("jms.queue.jndi")
jms_subdeployment=configProps.get("jms.subdeployment")
jms_topic=configProps.get("jms.topic")
jms_topic_jndi=configProps.get("jms.topic.jndi")
jms_targetserver=configProps.get("jms.targetserver")


#connect('weblogic','weblogic1', 't3://localhost:7101')
connect(adminUserName, adminPassword, adminURL)

# Creating a JMS Server

edit()
startEdit()
cd('/')
print 'Creating JMS Server.'
cmo.createJMSServer(jms_server)
cd('/JMSServers/'+jms_server)
cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
activate()

# Creating a Module

startEdit()
cd('/')
cmo.createJMSSystemResource(jms_systemResource)
cd('/JMSSystemResources/'+jms_systemResource)
cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
cmo.createSubDeployment(jms_subdeployment)
activate()

# Creating Queue

startEdit()
print 'Creating Queue & Topic '
cd('/')
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
cmo.createQueue(jms_queue)
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Queues/'+jms_queue)
set('JNDIName',jms_queue_jndi)
set('SubDeploymentName',jms_subdeployment)
cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
cmo.addTarget(getMBean('/JMSServers/'+jms_server))
activate()

# Creating Topic

startEdit()
cd('/')
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
cmo.createTopic(jms_topic)
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Topics/'+jms_topic)
set('JNDIName',jms_topic_jndi)
set('SubDeploymentName',jms_subdeployment)
cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
set('Targets',jarray.array([ObjectName('com.bea:Name='+jms_server+',Type=JMSServer')],ObjectName))

activate()

========================end of python script===============

Now open command prompt

Execute the following command after correcting the path as per your soa installation

mvn wls:wlst -DfileName=path/to/jmsobjects.py  - DmiddlewareHome=path/to/oraclehome 
-DdomainHome=path/to/domainhome 

No comments:

Post a Comment