Gradle Goodness: Running Java Applications from External Dependency
With Gradle we can execute Java applications using the JavaExec task or the javaexec() method. If we want to run Java code from an external dependency we must first pull in the dependency with the Java application code. The best way to do this is to create a new dependency configuration. When we configure a task with type JavaExec we can set the classpath to the external dependency. Notice we cannot use the buildscript{} script block to set the classpath. A JavaExec task will fork a new Java process so any classpath settings via buildscript{} are ignored.
In the following example build script we want to execute the Java class org.apache.cxf.tools.wsdlto.WSDLToJava from Apache CXF to generate Java classes from a given WSDL. We define a new dependency configuration with the name cxf and use it to assign the CXF dependencies to it. We use the classpath property of the JavaExec task to assign the configuration dependency.
00.// File: build.gradle01. 02.// Base plugin for task rule clean<task>03.apply plugin: 'base'04. 05.repositories.mavenCentral()06. 07.// New configuration for CXF dependencies.08.configurations { cxf }09. 10.ext {11.// CXF version.12.cxfVersion = '2.6.2'13. 14.// Artifacts for CXF dependency.15.cxfArtifacts = [16.'cxf-tools-wsdlto-frontend-jaxws', 17.'cxf-tools-wsdlto-databinding-jaxb', 18.'cxf-tools-common', 19.'cxf-tools-wsdlto-core'20.]21.}22. 23.dependencies {24.// Assign CXF dependencies to configuration.25.cxfArtifacts.each { artifact ->26.cxf "org.apache.cxf:$artifact:$cxfVersion"27.}28.}29. 30.// Custom task to generate Java classes31.// from WSDL.32.task wsdl2java(type: JavaExec) {33.ext {34.wsdlFile = 'src/wsdl/service-contract.wsdl'35.outputDir = file("$buildDir/generated/cxf")36.}37. 38.inputs.file file(wsdlFile)39.outputs.dir outputDir40. 41.// Main Java class to invoke.42.main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'43. 44.// Set classpath to dependencies assigned45.// to the cxf configuration.46.classpath = configurations.cxf47. 48.// Arguments to be passed to WSDLToJava.49.args '-d', outputDir50.args '-client'51.args '-verbose'52.args '-validate'53.args wsdlFile54.}Code written with Gradle 1.2
Gradle Goodness: Running Java Applications from External Dependency的更多相关文章
- Gradle Goodness: Set Java Compiler Encoding--转载
原文地址:http://java.dzone.com/articles/gradle-goodness-set-java If we want to set an explicit encoding ...
- Gradle Goodness: Set Java Compiler Encoding
If we want to set an explicit encoding for the Java compiler in Gradle we can use the options.encodi ...
- Android Studio Gradle Build Running 特别慢的问题探讨
本文的本本win7 64bit 6G android studio2.1 在运行程序的时候Gradle Build Running 特别慢,一个helloworld都快2min了 1.开启gradle ...
- End-to-End Tracing of Ajax/Java Applications Using DTrace
End-to-End Tracing of Ajax/Java Applications Using DTrace By Amit Hurvitz, July 2007 Aja ...
- android studio 一直卡在Gradle:Build Running的解决办法
转:android studio 一直卡在Gradle:Build Running的解决办法 在使用AS开发安卓应用程序的时候经常会遇到Gradle build running一直在运行甚至卡死的 ...
- 转:android studio 一直卡在Gradle:Build Running的解决办法
在使用AS开发安卓应用程序的时候经常会遇到Gradle build running一直在运行甚至卡死的情况,解决方法如下: 方法1: 1.在C:\User\<用户名>\.gradle 目录 ...
- Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects
Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...
- 解决Android Studio Gradle Build Running慢的问题
Android Studio方便好用,但是Android Studio Gradle Build Running很慢 解决方法: C:\Users\你的用户名\.gradle 目录下新建一个文件名为 ...
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
随机推荐
- Intellij IDEA 各种乱码解决方案 posted @ 2017-06-23 15:31:06
一次解决所有问题,只需做配置文件的修改即可 解决方案: 在 IntelliJ IDEA 2016.1\bin\idea64.exe.vmoptions Intell ...
- vc++返回模块路径
#include "stdafx.h"#include <Windows.h>#include <string.h>const int MAXPATHLEN ...
- Spring课程 Spring入门篇 5-7 advisors
1 简析 1.1 advisor简析(这个不太明白,后续再看吧) 2 代码演练 2.1 环绕通知的综合应用(代码和视频对不上,慕课网讲的本身有问题) 1 简析 1.1 advisor简析( ...
- poi导出excel,以字符串格式输出数字
装载自 http://blog.csdn.net/z69183787/article/details/48133809 解决了我数字前面有0被省略问题 做过很多次导出excel了.都碰到一个问题,内容 ...
- Mybatis学习随笔
学习Mybatis路径(适合有java基础和mysql基础的小伙伴) 1.把项目搭建起来,跑一跑感受一下 2.测试基本映射 3.测试高级映射 4.测试动态sql 5.学习懒加载与缓存 6.与sprin ...
- CSS3动画功能
1.transition功能 transition属性的使用方法:transition:property duration timing-function; 其中property表示对哪个属性进行平滑 ...
- <Android 应用 之路> MPAndroidChart~LineChart
简介 MPAndroidChart是PhilJay大神给Android开发者带来的福利.MPAndroidChart是一个功能强大并且使用灵活的图表开源库,支持Android和IOS两种,这里我们暂时 ...
- 【Python】区分List 和String
区分String和list String can't mutate 每次变更实质上开辟新的资源 List 可变更 警惕指针
- Android Studio设置代码风格
进入settings,然后搜索CodeStyle选择Java进入如下界面 scheme选择project
- windows c++ 修改用户的文件夹操作权限
一般Windows下的系统文件(夹)只让受限帐户读取而不让写入和修改.如果要开启写操作权限就需要手动修改文件(夹)的用户帐户安全权限(这操作当然要在管理员帐户下执行).以下用程序封装了一下该操作: # ...