I came to know that weblogic provides some ant tasks to deploy our application with build.xml. I need to create a weblogic user for existing domain whenever I deploy the application into my one of the server instances. Is there any task available into WLserver to achieve this?? Please give me some suggestions for this.
Code snippets are highly appreciable.
Thanks.
WLST is the way to go for this. See Using the WebLogic Scripting Tool for details on calling this from Ant and WLST Command and Variable Reference for command details, but below is a sample build.xml and wlst script to create a group, a user and add the user to the group.
build.xml
<?xml version="1.0" encoding="windows-1252" ?>
<project default="create_user">
<property environment="env"/>
<path id="wl.classpath">
<pathelement location="${env.ORACLE_HOME}/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar"/>
<pathelement location="${env.ORACLE_HOME}/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar"/>
<pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
<pathelement location="${env.ORACLE_HOME}/wlserver_10.3/server/lib/weblogic_sp.jar"/>
<pathelement location="${env.ORACLE_HOME}/wlserver_10.3/server/lib/weblogic.jar"/>
<pathelement location="${env.ORACLE_HOME}/modules/features/weblogic.server.modules_10.3.6.0.jar"/>
<pathelement location="${env.ORACLE_HOME}/wlserver_10.3/server/lib/webservices.jar"/>
<pathelement location="${env.ORACLE_HOME}/modules/org.apache.ant_1.7.1/lib/ant-all.jar"/>
<pathelement location="${env.ORACLE_HOME}/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar"/>
<fileset dir="${env.ORACLE_HOME}/oracle_common/common/wlst/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${env.ORACLE_HOME}/oracle_common/common/wlst/resources">
<include name="*.jar"/>
</fileset>
<pathelement location="${env.ORACLE_HOME}/utils/config/10.3/config-launch.jar"/>
</path>
<target name="create_user">
<taskdef name="wlst"
classname="weblogic.ant.taskdefs.management.WLSTTask" classpathref="wl.classpath" />
<wlst debug="true" failonerror="true" executeScriptBeforeFile="true" fileName="create_user.py">
<classpath>
<path refid="wl.classpath"/>
</classpath>
</wlst>
</target>
</project>
create_user.py
from weblogic.management.utils import AlreadyExistsException
connect('weblogic', 'password', 't3://localhost:7001')
serverConfig()
authenticator = cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')
try:
print("Creating group.")
authenticator.createGroup('groupName', 'groupDescription')
print("Group created.")
except AlreadyExistsException:
print("Ignoring group as it already exists.")
pass
print("Creating user 'groupName'.")
authenticator.createUser('userName', 'userPassword%!1', 'userDescription')
print("Addding user to group.")
authenticator.addMemberToGroup('groupName', 'userName')
disconnect()
Related
I have the following ANT script that gives me a list of websphere libraries at runtime based on the websphere root directory. I need to convert the resulting string into separate path location elements
My current script is
<?xml version="1.0" encoding="UTF-8"?>
<project name="TestPath" basedir="." default="print-dirset">
<target name="init" description="Define websphere libraries">
<property name="compile.lib.dir" value="C:\Software\WAS85" />
</target>
<target name="print-dirset" depends="init" description="">
<path id="websphere.libs">
<dirset dir="${compile.lib.dir}">
<include name="*" />
</dirset>
</path>
<property name="websphere.libs.list" refid="websphere.libs" />
<echo message="websphere.libs.list: ${websphere.libs.list}" />
<pathconvert property="websphere.libs.convert" pathsep="${file.separator}*${path.separator}">
<path path="${websphere.libs.list}" />
</pathconvert>
<echo message="websphere.libs.convert: ${websphere.libs.convert}" />
</target>
</project>
which outputs a string like below
[echo] websphere.libs.list: C:\Software\WAS85\Scheduler;C:\Software\WAS85\UDDIReg;C:\Software\WAS85\bin;C:\Software\WAS85\configuration;....C:\Software\WAS85\web;C:\Software\WAS85\wlp
[echo] websphere.libs.convert: C:\Software\WAS85\Scheduler\*;C:\Software\WAS85\UDDIReg\*;C:\Software\WAS85\bin\*;C:\Software\WAS85\configuration\*;...C:\Software\WAS85\web\*;C:\Software\WAS85\wlp
I would like to translate the second string above into a structure like below
<path id="websphere.classpath">
<pathelement location="C:\Software\WAS85\Scheduler\*" />
<pathelement location="C:\Software\WAS85\UDDIReg\*" />
<pathelement location="C:\Software\WAS85\bin\*" />
<pathelement location="C:\Software\WAS85\configuration\*" />
......
<pathelement location="C:\Software\WAS85\web\*" />
<pathelement location="C:\Software\WAS85\wlp\*" />
</path>
The last element in the conversion also needs to add the '\*' part which is not in the original string.
which can then be used with a structure like
<path id="compile.classpath">
<path refid="ext.classpath"/>
<path refid="websphere.classpath"/>
<path refid="module.compile.classpath"/>
</path>
The purpose of the above attempt is to reduce the length of classpath by using wildcard classpath provided by JDK 1.6 and which is available in ANT starting ANT 1.8.2. I am using ANT 1.8.4.
I am not an expert in ANT, I can just get by, by looking at examples.
Is there a way to achieve what I am trying to do? How can I do it? Any example would be very helpful.
If all of your dependencies reside in C:\Software\WAS85, you can use fileset to catch all of your dependencies:
<fileset dir="${compile.lib.dir}" id="compile.files">
<include name="**/*.java"/>
<!-- include name="**/*.jar" /-->
</fileset>
You can then use to refer to this fileset as compile.files elsewhere in your build.xml.
I was able to get the wildcard part to work by using the fork="yes" and executable="path-to-my-executable" attributes in the javac task.
I do not want to mark the question answered, because my basic question was about converting the string. But since the answer received didn't talk about that and also didn't mention how to get wildcard classpath working, and the purpose of my question was to get the wildcard classpath working, i have noted it here for whoever is trying to get that to work
I still need some help in converting the semi-colon separated string to construct like below
<path id="websphere.classpath">
<pathelement location="C:\Software\WAS85\Scheduler\*" />
<pathelement location="C:\Software\WAS85\UDDIReg\*" />
<pathelement location="C:\Software\WAS85\bin\*" />
<pathelement location="C:\Software\WAS85\configuration\*" />
......
<pathelement location="C:\Software\WAS85\web\*" />
<pathelement location="C:\Software\WAS85\wlp\*" />
</path>
Update:
I wrote a custom ANT task to get the wildcard classpath working
I am new to jsf and jsp.
I know weblogic 12 c comes with jsf 2.0 but when ever i try to deloy my application, i got an stack error., i guess this is due to my build.xml which can not get my jars and wars from weblogic server,
Below is the code of build.xml,please help me asap, will be very thankful.
<property name="weblogic.home" value="/bea/wlserver_12.1/"/>
<path id="WebLogic System Libraries.libraryclasspath">
<pathelement location="../../../../bea/wlserver_12.1/server/lib/api.jar"/>
<pathelement location="../../../../bea/wlserver_12.1/server/lib/wls-api.jar"/>
<pathelement location="../../../../bea/wlserver_12.1/common/deployable-libraries/jsf-2.0.war"/>
<pathelement location="../../../../bea/wlserver_12.1/common/deployable-libraries/jstl-1.2.war"/>
</path>
<path id="Security_Search.classpath">
<pathelement location="build/classes"/>
<path refid="WebLogic System Libraries.libraryclasspath"/>
</path>
<target name="init">
<mkdir dir="build/classes"/>
<mkdir dir="dist" />
</target>
<path id="compile.classpath">
<fileset dir="${weblogic.home}/common/deployable-libraries">
<include name="*.war"/>
</fileset>
<pathelement location="../../../../bea/wlserver_12.1/common/deployable-libraries/jsf-2.0.war"/>
</path>
<target name="compile" depends="init" >
<javac destdir="build/classes" debug="true" srcdir="src">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="dist/security_Search_JSF.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent">
<exclude name="*.jar"/>
</fileset>
<classes dir="build/classes"/>
</war>
</target>
<target name="clean">
<delete dir="dist" />
<delete dir="build/classes"/>
</target>
<target name="build"/>
</project>
TTP:101064][WebAppModule(security_Search_JSF:security_Search_JSF.war)] Error parsing descriptor in Web appplication "C:\bea_deploy\security_Search_JSF.war" weblogic.application.ModuleException: VALIDATION PROBLEMS WERE FOUND problem: cvc-complex-type.2.3: Element 'weblogic-web-app#http://xmlns.oracle.com/weblogic/weblogic-web-app' with element-only content type cannot have text content.: at weblogic.servlet.internal.WebAppModule.loadDescriptor(WebAppModule.java:1494) at weblogic.servlet.internal.WebAppModule.init(WebAppModule.java:253) at weblogic.servlet.internal.WebAppModule.init(WebAppModule.java:636) at weblogic.application.internal.flow.ScopedModuleDriver.init(ScopedModuleDriver.java:162) at weblogic.application.internal.ExtensibleModuleWrapper.init(ExtensibleModuleWrapper.java:74) at weblogic.application.internal.flow.ModuleListenerInvoker.init(ModuleListenerInvoker.java:84) at weblogic.application.internal.flow.InitModulesFlow.initModule(InitModulesFlow.java:312) at weblogic.application.internal.flow.InitModulesFlow.initModules(InitModulesFlow.java:325) at weblogic.application.internal.flow.InitModulesFlow.prepare(InitModulesFlow.java:378) at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:706) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:237) at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:48) at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:158) at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:207) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:96) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:229) at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747) at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216) at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250) at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:13) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:46) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545) a
now i am getting this error.. please help,,,,
Its error in weblogic.. please
About the original error, it states that your weblogic.xml file has an invalid format.
Here's a sample of a valid weblogic.xml that references the JSF 2.0 shared library you want to use:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.1</wls:weblogic-version>
<wls:context-root>store</wls:context-root>
<wls:library-ref>
<wls:library-name>jsf</wls:library-name>
<wls:specification-version>2.0</wls:specification-version>
<wls:exact-match>true</wls:exact-match>
</wls:library-ref>
If you already solved this error, please provide details on the next one - is it happening during deployment? Can you print the whole stacktrace?
Cheers,
Fabio
I am trying to integrate yuicompressor with Ant to automate the minification of our CSS and JS files. However, I keep getting the following error message when I try to run build.xml:
BUILD FAILED
/Applications/MAMP/htdocs/zanadu-dev/build/build.xml:64: taskdef A class needed by class com.yahoo.platform.yui.compressor.YUICompressTask cannot be found: org/mozilla/javascript/EvaluatorException
using the classloader AntClassLoader[/usr/share/ant/lib/YUIAnt.jar:/usr/share/ant/lib/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar:/usr/share/ant/lib/yuicompressor-2.4.6/lib/rhino-1.6R7.jar]
Here is the code in my build.xml file:
<target name="minify" depends="build" description="Minifiy CSS and JS files">
<available file="${antlib.dir}/YUIAnt.jar" property="YUIANT_AVAILABLE" />
<fail unless="YUIANT_AVAILABLE" message="YUIAnt.jar not found" />
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<pathelement path="${antlib.dir}/YUIAnt.jar" />
<pathelement path="${antlib.dir}/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar" />
<pathelement path="${antlib.dir}/yuicompressor-2.4.6/lib/rhino-1.6R7.jar" />
</classpath>
</taskdef>
<mkdir dir="${jsminify.dir}" />
<yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true"
outputfolder="${jsmin.dir}">
<fileset dir="${js.dir}" >
<include name="**/*.js" />
</fileset>
</yuicompress>
<mkdir dir="${cssminify.dir}" />
<yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true"
outputfolder="${cssmin.dir}">
<fileset dir="${css.dir}" >
<include name="**/*.css" />
</fileset>
</yuicompress>
</target>
I have tried following several online examples on this, but all seem to yield the same error message. Not sure exactly where I can find the EvaluatorException class that seems to be missing.
Any idea what I may be doing wrong?
Cheers!
Your taskdef is missing one lib.
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<pathelement path="${antlib.dir}/YUIAnt.jar" />
<pathelement path="${antlib.dir}/yuicompressor-2.4.6.jar" />
<pathelement path="${antlib.dir}/rhino-1.6R7.jar" />
</classpath>
</taskdef>
EDIT:,
The problem is somehow related to the jar locations and Ant's class-loader, see this post
One workaround is to copy YUIAnt.jar, yuicompressor-2.4.6.jar and rhino-1.6R7.jar to one directory. Then use it like above. I've tried and it works.
if you use http://code.google.com/p/yui-compressor-ant-task/ for me solution was to use classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask" instead of classname="com.yahoo.platform.yui.compressor.YUICompressTask"
I defined a path in a file called unittest.xml in the following way(line 26):
<path id="tasks.path">
<pathelement location="${publish.home}/INSIDE/UnitTest/testinganttasks.jar"/>
</path>
next I tried to use the path in the following way:
<classpath>
<path refid="tasks.path" />
</classpath>
in a taskdef tag.
when I run my ant code, it does everything well until I get the following error:
BUILD FAILED unittest.xml:296: The
following error occurred while
executing this line: unittest.xml:281:
Reference tasks.path not found.
How can I resolve this issue?
You should see this example at http://ant.apache.org/manual/using.html#references
<project ... >
<path id="project.class.path">
<pathelement location="lib/"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</path>
<target ... >
<rmic ...>
<classpath refid="project.class.path"/>
</rmic>
</target>
<target ... >
<javac ...>
<classpath refid="project.class.path"/>
</javac>
</target>
</project>
I think your problem is that in classpath you should not nest path element, but give id of the path for the classpath element itself.
I have a main build file with a path declaration
<path id="path.app.src">
<pathelement location="myfolder/src"/>
</path>
Then i call a task in sub file with <ant>
<ant antfile="subbuild.xml" inheritAll="false" inheritRefs="false">
<reference refid="path.app.src"/>
</ant>
in subbuild.xml i have:
<path id="subpath.app.src">
<pathelement location=".. some locations .."/>
<path refid="path.app.src" />
</path>
In my understanding the call to <ant> with a nested should overwrite path.app.src in subbuild.xml.
But i get an error like: subbuild.xml:xx: Reference path.app.src not found.
Am i doing something wrong ? is it a bug in ant ?
I'm using Apache Ant version 1.7.0 compiled on December 13 2006
Thanks,
Lionel
in fact it seems to have the right behavior now, but i can't explain what i did wrong the first time.
here is the code sample:
build.xml
<?xml version="1.0"?>
<project name="test" default="build" basedir=".">
<path id="mainpath">
<pathelement location="my/main/path"/>
</path>
<target name="build">
<ant antfile="subbuild.xml" target="test">
<reference refid="mainpath" torefid="globalpathid"/>
<reference refid="mainpath" torefid="localtotargetpathid"/>
</ant>
</target>
</project>
subbuild.xml
<?xml version="1.0"?>
<project name="subbuild">
<path id="globalpathid">
<pathelement location="my/sub/location"/>
</path>
<target name="test">
<path id="localtotargetpathid">
<pathelement location="my/target/location"/>
</path>
<property name="p.localtotargetpathid" refid="localtotargetpathid" />
<echo>p.localtotargetpathid: ${p.localtotargetpathid}</echo>
<property name="p.globalpathid" refid="globalpathid" />
<echo>p.globalpathid: ${p.globalpathid}</echo>
</target>
</project>
here is the console log:
$ ant
Buildfile: build.xml
build:
[ant] Parent project doesn't contain any reference 'mainpath'
test:
[echo] p.localtotargetpathid: d:\my\target\location
[echo] p.globalpathid: d:\my\main\path
BUILD SUCCESSFUL
Total time: 0 seconds
we can see globalpathid has been override but not localtotargetpathid, which is the behvior mentioned in the spec.
still I can't explain the first message ...
I think you have an incomplete declaration here in the subbuild file of refid path.app.src.
<path id="subpath.app.src">
<pathelement location=".. some locations .."/>
<path refid="path.app.src" /> <=======
</path>
It should not have the 2nd nested path element () since there is no location associated with it. The way you wrote the main build file to overwrite no reference //other than// this refid looks good to me.