How to start weblogic though build.gradle

Hi,

I am trying to start weblogic through build.gradle…I have tried two ways 1)I have written wlst script to start weblogic but when try to execute this script through build.gradle, I get very strange error while starting weblogic that "Provide_URL is not set. Although when I run this wlst script through command line directly,weblogic starts properly. wlst command to start weblogic in build.gradle:

task startWeblogic(type: JavaExec) {

def weblogicScriptingClasspath = fileTree(‘C:\bea-10.3.6\wlserver_10.3\server\lib’) {

includes = [’**/*.jar’]

}

def weblogicDomainDirectory = 'C:\bea-10.3.6\user_projects\domains\domainlocal

main = ‘weblogic.WLST’

classpath = weblogicScriptingClasspath

args = [‘weblogicScript-Start.py’] as List

2)In second way,I am starting weblgic though batch file and I am trying to call this batch file though build.gradle but I get this below error: Execution failed for task startWeblogic caused by Process ‘command ‘cmd’’ finished with non-zero exit value 1

this is the command I am using to call batch file:

task startWeblogic(type:Exec) {

commandLine “cmd”, “/c, startweblogic.bat”

}

Please help me with this.

Maybe the working dir is different compared to starting from the command line. Also, can you post the full stack trace (’-s’) as a GitHub Gist?

Thanks for replying… I have written a batch file “startweblogic.bat” to start weblogic server:

echo off SETLOCAL set DOMAIN_NAME=sqe_t3_local

set USERDOMAIN_HOME=C:\bea-10.3.6\user_projects\domains\domainlocal set WLS_USER=weblogic

set WLS_PW=weblogic1

set JAVA_OPTIONS=-Dweblogic.Stdout=“C:\bea-10.3.6\user_projects\domains\domainlocal\ stdout.txt” -Dweblogic.Stderr=“C:\bea-10.3.6\user_projects\domains\domainlocal\ stderr.txt”

set MEM_ARGS=-Xms40m -Xmx250m call “C:\bea-10.3.6\user_projects\domains\domainlocal\startWebLogic.cmd” echo “5 mins over” ENDLOCAL

now I am calling this batch file in my gradle build file and since I want to execute my test after my server is started, I am running this in a thread

task startWeblogic(type:Exec) {

println “--------------Start Weblogic------------------”

commandLine = [‘cmd’, ‘/C’, ‘start’, ‘startweblogic.bat’]

println “-------------- Weblogic server started ------------------”

}

task startWeblogicThread()<<{

def weblogicThread1 = Thread.start {

startWeblogic.execute()

}

sleep 120000

println “wake up and work”

}

startWeblogicThread.dependsOn copyEar

test.dependsOn startWeblogicThread

When I run this, I am getting the below error, though process go ahead and after 2min it tries to execute my test but my server is not started due to this error :frowning: Cannot start long running operation, as the task artifact state cache (D:\sqe-ivpn-bulkmodify.gradle\1.5\taskArtifacts) has not been locked.

Exception in thread “Thread-1” java.lang.IllegalStateException: Cannot start long running operation, as the task artifact state cache (D:\sqe-ivpn-bulkmodify.gradle\1.5\taskArtifacts) has not been locked.

at org.gradle.cache.internal.DefaultCacheAccess.checkThreadIsOwner(DefaultCacheAccess.java:192)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:175)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)

Your println’s are evaluated in the configuration phase, not in the execution phase where the task gets executed. Please use HTML code blocks to make your post more readable. In particular, it’s not clear to me where exactly your build script (snippet) ends.

I have written a batch file “startweblogic.bat” to start weblogic server:

echo off SETLOCAL set DOMAIN_NAME=domainlocal

set USERDOMAIN_HOME=C:\bea-10.3.6\user_projects\domains\domainlocall set SERVER_NAME=sqe_t3 set WLS_USER=weblogic

set WLS_PW=weblogic1

set JAVA_OPTIONS=-Dweblogic.Stdout=“C:\bea-10.3.6\user_projects\domains\domainlocal\ stdout.txt” -Dweblogic.Stderr=“C:\bea-10.3.6\user_projects\domains\domainlocal\ stderr.txt”

set MEM_ARGS=-Xms40m -Xmx250m call “C:\bea-10.3.6\user_projects\domains\domainlocal\startWebLogic.cmd” echo “5 mins over” ENDLOCAL

now I am calling this batch file in my gradle build file and since I want to execute my test after my server is started, I am running this in a thread

task startWeblogic(type:Exec) {

println “--------------Start Weblogic------------------”

commandLine = [‘cmd’, ‘/C’, ‘start’, ‘startweblogic.bat’]

println “-------------- Weblogic server started ------------------”

}

task startWeblogicThread()<<{

def weblogicThread1 = Thread.start {

startWeblogic.execute()

}

sleep 120000

println “wake up and work”

}

startWeblogicThread.dependsOn copyEar

test.dependsOn startWeblogicThread

When I run this, I am getting the below error, though process go ahead and after 2min it tries to execute my test but my server is not started due to this error :frowning:

Exception in thread “Thread-1” java.lang.IllegalStateException: Cannot start long running operation, as the task artifact state cache (D:\sqe-ivpn-bulkmodify.gradle\1.5\taskArtifacts) has not been locked.

at org.gradle.cache.internal.DefaultCacheAccess.checkThreadIsOwner(DefaultCacheAccess.java:192)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:175)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)

GRADLE BUILD file task startWeblogic(type:Exec) {

println “--------------Start Weblogic------------------”

commandLine = [‘cmd’, ‘/C’, ‘start’, ‘startweblogic.bat’]

println “-------------- Weblogic server started ------------------”

}

task startWeblogicThread()<<{

def weblogicThread1 = Thread.start {

startWeblogic.execute()

}

When I run this, I am getting the above error, though process go ahead and after 2min it tries to execute my test but my server is not started due to this error :frowning:

sleep 120000

println “wake up and work”

}

startWeblogicThread.dependsOn copyEar

test.dependsOn startWeblogicThread

When I run the above build file, I am getting the below error, though process go ahead and after 2min it tries to execute my test but my server is not started due to this error :frowning:

Exception in thread “Thread-1” java.lang.IllegalStateException: Cannot start long running operation, as the task artifact state cache (D:\.gradle\1.5\taskArtifacts) has not been locked.

sorry to write this in parts as it is not appearing properly.

GRADLE BUILD file

task startWeblogic(type:Exec) {

println “--------------Start Weblogic------------------”

commandLine = [‘cmd’, ‘/C’, ‘start’, ‘startweblogic.bat’]

println “-------------- Weblogic server started ------------------”

}

task startWeblogicThread()<

}

startWeblogicThread.dependsOn copyEar

test.dependsOn startWeblogicThread

When I run the above build file, I am getting the below error, though process go ahead and after 2min it tries to execute my test but my server is not started due to this error :frowning:

Exception in thread “Thread-1” java.lang.IllegalStateException: Cannot start long running operation, as the task artifact state cache (D:.gradle\1.5\taskArtifacts) has not been locked.

task startWeblogic(type:Exec) {

println “--------------Start Weblogic------------------”

commandLine = [‘cmd’, ‘/C’, ‘start’, ‘startweblogic.bat’]

println “-------------- Weblogic server started ------------------”

}

task startWeblogicThread()<<{

def weblogicThread1 = Thread.start {

startWeblogic.execute()

}

sleep 120000

println “wake up and work”

}

startWeblogicThread.dependsOn copyEar

test.dependsOn startWeblogicThread

now I am calling this batch file in my gradle build file and since I want to execute my test after my server is started, I am running this in a thread

task startWeblogic(type:Exec) {
        println "--------------Start Weblogic------------------"
        commandLine = ['cmd', '/C', 'start', 'startweblogic.bat']
        println "-------------- Weblogic server started ------------------"
    }
    task startWeblogicThread()<<{
        def weblogicThread1 = Thread.start {
            startWeblogic.execute()
        }
          sleep 120000
        println "wake up and work"
    }
  startWeblogicThread.dependsOn copyEar
    test.dependsOn startWeblogicThread

When I run this, I am getting the below error, though process go ahead and after 2min it tries to execute my test but my server is not started due to this error :frowning:

Exception in thread “Thread-1” java.lang.IllegalStateException: Cannot start long running operation, as the task artifact state cache (D:.gradle\1.5\taskArtifacts) has not been locked.

at org.gradle.cache.internal.DefaultCacheAccess.checkThreadIsOwner(DefaultCacheAccess.java:192)

at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:175)

Can you use another HTML code block (or a GitHub Gist) for the full stack trace?

Calling ‘execute()’ on a task is not supported. What exactly are you trying to achieve with this? Shouldn’t the batch file return quickly anyway?

Exception in thread "Thread-1" java.lang.IllegalStateException: Cannot start long running operation, as the task artifact state cache (D:\project\.gradle.5\taskArtifacts) has not been locked.
        at org.gradle.cache.internal.DefaultCacheAccess.checkThreadIsOwner(DefaultCacheAccess.java:192)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:175)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
        at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
        at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:275)
        at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:270)
        at org.gradle.api.internal.TaskInternal$execute.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
        at build_17r82cio3fkgch7ar27mgll0bh$_run_closure3_closure17_closure19.doCall(D:\sqe-ivpn-bulkmodify\sqe-automation\build.gradle:127)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at build_17r82cio3fkgch7ar27mgll0bh$_run_closure3_closure17_closure19.doCall(D:\sqe-ivpn-bulkmodify\sqe-automation\build.gradle)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
        at groovy.lang.Closure.call(Closure.java:412)
        at groovy.lang.Closure.call(Closure.java:406)
        at groovy.lang.Closure.run(Closure.java:490)
        at java.lang.Thread.run(Thread.java:662)
wake up and work

Batch file works and it starts the weblogic server but then the control does not go ahead and executes the test. how do I make that work? Please help

Basically what I am trying to achieve is that start weblogic server, execute the test case and then shutdown the server though build file as it has to be in automated fashion When I just execute this without thread, my server gets started but control does not go ahead after my server is in running state: Also it takes atleast 2 min to start the server.

task startWeblogic(type:Exec) {
        println "--------------Start Weblogic------------------"
        commandLine = ['cmd', '/C', 'start','/B', 'startweblogic.bat']
        println "-------------- Weblogic server started ------------------"
    }

Try to change the batch script to return control to Gradle. Or maybe you have to add another argument when invoking ‘cmd’. It’s hard for me to say because I’m not a Windows user.

Also, note that your println’s are printed in the configuration phase, way before the command gets executed. You’d have to do something like:

task startWeblogic(type: Exec) {
    commandLine = ['cmd', '/C', 'start','/B', 'startweblogic.bat']
    doFirst { println "--------------Start Weblogic------------------" }
    doLast { println "-------------- Weblogic server started ------------------" }
}

Ok Peter, I will try to do as you have suggested. Thanks a lot for so quick response to my queries.

I wonder why the ‘start’ would be necessary. I’d try something like ‘[“cmd”, “/C”, “startweblogic.bat”]’.

I get this error if i dont specify ‘start’ Process ‘command ‘cmd’’ finished with non-zero exit value 1