Create datasource in weblogic by python script

Hi All,

If you want to create datasources in weblogic manually or through program. You can write a python script and invoke that python script with maven to use this in devops. This is quite common requirment. If you want to setup new environment using maven, this will be really helpful.

Below is follow script used for that

adminUserName='weblogic'
adminPassword='Weblogic1'
adminURL='t3://hostname:port'
databasehost='hostname'


connect(UserName, Password, adminURL)
edit()
startEdit()

cd('/')
cmo.createJDBCSystemResource('techartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/techartifactDS')
cmo.setName('techartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDataSourceParams/techartifactDS')
set('JNDINames',jarray.array([String('jdbc/techartifactDS')], String))

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS')
cmo.setUrl('jdbc:oracle:thin:@' + databasehost + ':1521:xe')
cmo.setDriverName('oracle.jdbc.OracleDriver')
cmo.setPassword('passwordFortechartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCConnectionPoolParams/techartifactDS')
cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n\r\n')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS/Properties/techartifact')
cmo.createProperty('user')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS/Properties/techartifact/Properties/user')
cmo.setValue('techartifact')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDataSourceParams/techartifactDS')
cmo.setGlobalTransactionsProtocol('OnePhaseCommit')

cd('/SystemResources/techartifact')
set('Targets',jarray.array([ObjectName('com.bea:Name=WCP_PORTAL,Type=Cluster')], ObjectName))

activate()

Happy coding with python with Vinay

Attach sources & javadocs in maven project

Maven allows to publish project source code and javadoc with complied artifact. Maven source plugin and javadoc can do it easily for you.

Here is pom configuration for it.

Attaching source

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-sources</id>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Maven source plugin also allows to package test source codes

Attaching test source code

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-test-sources</id>
      <goals>
        <goal>test-jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Attaching javadocs

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-javadocs</id>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

you achieve it by issuing any of following maven commands

mvn package
mvn install

Please refer to maven plugin website for more information

source-plugin  http://maven.apache.org/plugins/maven-source-plugin/

javadoc-plugin http://maven.apache.org/plugins/maven-javadoc-plugin/