如何将war文件远程部署到远程glassfish?

时间:2013-11-20 22:04:42

标签: java glassfish gradle cargo

我尝试将我的java web项目的war文件远程部署到远程Glassfish 3.1.2 我为Gradle使用Cargo插件,但我总是得到以下错误

:backend:cargoDeployRemote FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':backend:cargoDeployRemote'.
> org.codehaus.cargo.util.CargoException: Cannot locate the JSR-88 deployer class org.glassfish.deployapi.SunDeploymentFactory
Make sure the target server's librarires are in CARGO's classpath.
More information on: http://cargo.codehaus.org/JSR88

我的来源是

apply plugin: 'cargo'

def deployed = false

buildscript {
    repositories {
        mavenCentral()
        }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6.1',

    }
}

repositories {
    flatDir { dirs 'lib' }
}

dependencies {
    def cargoVersion = '1.3.3'
    cargo   "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
            "org.codehaus.cargo:cargo-ant:$cargoVersion",
            "org.codehaus.cargo:cargo-core-container-glassfish:$cargoVersion"
}

cargo {
    containerId = 'glassfish3x'
    port = 5448 // it's ok port, I'm sure

    deployable {
        context = '/'
    }

    remote {
        hostname = 'working_host_name'
        username = 'working_uname'
        password = 'working_pswd'
    }
}

您是否有任何建议如何解决或以正确的方式做? 提前致谢

---更新 在将部署客户端移动到货物类路径之后,在玩了几个小时的错误之后我又得到了另一个错误。现在看起来像

dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6.1'
    }
....
dependencies {
    def cargoVersion = '1.3.3'
    cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
            "org.codehaus.cargo:cargo-ant:$cargoVersion",
    "org.glassfish.main.deployment:deployment-client:3.1.2",
} 

现在我得到以下

:backend:cargoDeployRemote FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':backend:cargoDeployRemote'.
> java.lang.IllegalStateException: error submitting remote command

* Try:
Run with --info or --debug option to get more log output. 

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':backend:cargoDeployRemote'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:283)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:214)
    at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:276)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
    at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
    at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:46)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.Main.main(Main.java:37)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: : java.lang.IllegalStateException: error submitting remote command
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
    at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:71)
    at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(BasicAntBuilder.java:86)
    at org.gradle.api.internal.project.DefaultAntBuilder.super$3$invokeMethod(DefaultAntBuilder.groovy)
    at org.gradle.api.internal.project.DefaultAntBuilder.invokeMethod(DefaultAntBuilder.groovy:37)
    at org.gradle.api.plugins.cargo.RemoteContainerTask.runAction(RemoteContainerTask.groovy:53)
    at org.gradle.api.plugins.cargo.AbstractContainerTask$_start_closure1.doCall(AbstractContainerTask.groovy:49)
    at org.gradle.api.plugins.cargo.AbstractContainerTask$_start_closure1.doCall(AbstractContainerTask.groovy)
    at org.gradle.api.plugins.cargo.util.LoggingHandler.withAntLoggingListener(LoggingHandler.groovy:38)
    at org.gradle.api.plugins.cargo.util.LoggingHandler$withAntLoggingListener.call(Unknown Source)
    at org.gradle.api.plugins.cargo.AbstractContainerTask.start(AbstractContainerTask.groovy:48)
    at org.gradle.util.JavaMethod.invoke(JavaMethod.java:62)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:527)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:510)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 50 more
Caused by: java.lang.IllegalStateException: error submitting remote command
    at org.glassfish.deployapi.SunDeploymentManager.getTargets(SunDeploymentManager.java:171)
    at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.deploy(AbstractJsr88Deployer.java:121)
    at org.codehaus.cargo.ant.CargoTask.executeActions(CargoTask.java:630)
    at org.codehaus.cargo.ant.CargoTask.execute(CargoTask.java:535)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    ... 68 more
Caused by: java.lang.RuntimeException: error submitting remote command
    at org.glassfish.deployment.client.AbstractDeploymentFacility.listReferencedTargets(AbstractDeploymentFacility.java:735)
    at org.glassfish.deployment.client.AbstractDeploymentFacility.listTargets(AbstractDeploymentFacility.java:693)
    at org.glassfish.deployapi.SunDeploymentManager.getTargets(SunDeploymentManager.java:169)
    ... 73 more
Caused by: java.lang.RuntimeException: org.glassfish.api.admin.AuthenticationException: Authentication failed for user: admin
(Usually, this means invalid user name and/or password)
    at org.glassfish.deployment.client.RemoteDeploymentFacility$RemoteCommandRunner.run(RemoteDeploymentFacility.java:121)
    at org.glassfish.deployment.client.AbstractDeploymentFacility.listReferencedTargets(AbstractDeploymentFacility.java:704)
    ... 75 more
Caused by: org.glassfish.api.admin.AuthenticationException: Authentication failed for user: admin
(Usually, this means invalid user name and/or password)
    at com.sun.enterprise.admin.remote.RemoteAdminCommand.checkConnect(RemoteAdminCommand.java:905)
    at com.sun.enterprise.admin.remote.RemoteAdminCommand.doHttpCommand(RemoteAdminCommand.java:662)
    at com.sun.enterprise.admin.remote.RemoteAdminCommand.doHttpCommand(RemoteAdminCommand.java:543)
    at com.sun.enterprise.admin.remote.RemoteAdminCommand.fetchCommandModel(RemoteAdminCommand.java:1091)
    at com.sun.enterprise.admin.remote.RemoteAdminCommand.getCommandModel(RemoteAdminCommand.java:321)
    at com.sun.enterprise.admin.cli.remote.RemoteCommand.prepare(RemoteCommand.java:297)

BUILD FAILED

Total time: 8.548 secs
    at com.sun.enterprise.admin.cli.CLICommand.execute(CLICommand.java:242)
    at com.sun.enterprise.admin.cli.remote.RemoteCommand.executeAndReturnOutput(RemoteCommand.java:389)
    at org.glassfish.deployment.client.RemoteDeploymentFacility$RemoteCommandRunner.run(RemoteDeploymentFacility.java:117)
    ... 76 more

1 个答案:

答案 0 :(得分:2)

对我有帮助的是添加依赖项。

modules {
        module("org.glassfish.external:asm-all") {
            replacedBy("asm:asm-all")
        }
    }
    cargo 'asm:asm-all:3.3.1'
    cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
          "org.codehaus.cargo:cargo-ant:$cargoVersion",
    'org.glassfish.main.deployment:deployment-client:4.1'

我还必须设置密码来修复auth异常。我在管理页面上的glassfish中设置了密码。

cargo {
    containerId = 'glassfish4x'
    port = 8080

    deployable {
        context = '/myApp'
    }

    remote {
        hostname = 'localhost'
        username = 'admin'
        password = 'adminadmin'
    }
}

cargoDeployRemote.dependsOn war
cargoRedeployRemote.dependsOn war