How to unjar the public jar .classes (commons-cli-1.0.jar) into our project customized jar (xxxx.jar)

My ant build.xml having the follwing targets.

<javac srcdir="${src.java.dir}"

destdir="${build.java.dir}"

source=“1.5”

debug=“true”

deprecation=“true”>

<jar jarfile="${bin.jar}"

basedir="${build.java.dir}"

manifest="${build.java.dir}/META-INF/MANIFEST.MF">

<replace

file="${manifest.jar.mf}"

token="@version"

value="${dist.version}"

/>

<replace

file="${manifest.jar.mf}"

token="@sourcetag"

value="${dist.tag}"

/>

Now i am trying to covert my ant build.xml to gradle.build file.

apply plugin: ‘eclipse’ apply plugin: ‘idea’ apply plugin: ‘java’

project.group = distName

jar.enabled = true

sourceCompatibility=1.6

repositories {

mavenCentral()

// mavenRepo url: “https://repository.jboss.org/nexus/

//mavenRepo url: “http://www.dcm4che.org/maven2/

}

buildscript {

// cobertura - See https://github.com/valkolovos/gradle_cobertura/wiki

// gradle_cobertura/1.2 or 1.0

def githubBase = ‘https://github.com/valkolovos/gradle_cobertura/raw/master/repo

apply from: “${githubBase}/gradle_cobertura/gradle_cobertura/1.2/coberturainit.gradle” }

sourceSets {

main {

java {

srcDir ‘src/java’

} //

resources { //

}

}

test {

java {

srcDir ‘test/java’

}

} }

defaultTasks ‘all’

task all (dependsOn: [‘clean’, ‘test’, ‘jar’]) << { }

clean {

delete “./bin”, buildDir }

// build jar file; publish to dist directory jar {

archiveName = “${distName}.jar”

destinationDir = file("./bin")

manifest {

attributes ‘Implementation-Title’: distName,

‘Implementation-Version’: distTag,

‘Version’ : distVersion,

‘Implementation-Vendor’ : ‘Perceptive Informatics Inc.’

}

//ant.unzip(dest: build.metaClass.class, src: ‘commons-logging-api.jar’)

}

test {

//tuning the included/excluded tests

include “com/perceptive/cacher/cli/manual”

include “com/perceptive/cacher/model”

//makes the standard streams (err and out) visible at console when running tests

testLogging.showStandardStreams = true

//tweaking memory settings for the forked vm that runs tests

// jvmArgs ‘-Xms128m’, ‘-Xmx512m’, ‘-XX:MaxPermSize=128m’

//listening to test execution events

beforeTest { descriptor ->

logger.lifecycle(“Running test: $descriptor”)

}

onOutput { descriptor, event ->

logger.lifecycle(“Test: $descriptor - standard out/err: ${event.message}” )

} }

dependencies{

compile group: ‘commons-httpclient’, name: ‘commons-httpclient’, version: ‘3.1’

compile group: ‘commons-io’, name: ‘commons-io’, version: ‘2.0.1’

compile ‘commons-cli:commons-cli:1.0’

compile group: ‘javax.mail’, name: ‘mail’, version: ‘1.4.4’

//compile group: ‘commons-logging’, name: ‘commons-logging-api’, version: ‘1.0.4’

//compile group: ‘commons-logging’, name: ‘commons-logging’, version: ‘1.0.4’

//compile group: ‘commons-codec’, name: ‘commons-codec’, version: ‘1.3’

//compile group: ‘unsigned_activation’, name: ‘unsigned_activation’, version: ‘1.0.2’

//compile group: ‘unsigned_mail’, name: ‘unsigned_mail’, version: ‘1.0’

testCompile group: ‘org.mockito’, name: ‘mockito-all’, version: ‘1.8.0’

compile fileTree(dir: ‘lib’, include: ‘*.jar’)

compile fileTree(dir: ‘lib/ext’, include: ‘*.jar’)

testCompile group: ‘junit’, name: ‘junit’, version: ‘4.+’ }

i am able to get the xxxx.jar file but unble to get the xxxx.jar file with the unjar .classes . my question is how to do unjar the some of the source jar’s and place .class files into our xxxx.jar. how to unjar the public jar .classes into our project customized jar (xxxx.jar).

from ant build.xml i am getting the xxxx.jar with the .classes files of the libraries jar.

Could you please suggest me the solution.

Thanks, KRSNA

In the future please try to minimise the amount of code you copy into the forum, and enclose code snippets in <code/> tags. Your post is almost unreadable.

The Jar task is a subtype of Copy, and the various methods for including files in a copy are documented in the User Guide.

Something like this should work:

jar {
     from {
        zipTree('path/to/file')
    }
}