Jagan
Jagan

Reputation: 1

remove relative path of a jar and keep only jar name

I Have a property file which contains list of jars from different paths like this

/gwt/X/2.1.0/gwt-servlet.jar                                    
/gwt/X/2.1.0/gwt-user.jar
/gwt/X/2.1.0/gwt-dev.jar    
/gwt/X/2.1.0/gwt-soyc-vis.jar 
/log4j/X/1.2.15/log4j-1.2.15.jar
/GWT_LOG/X/3.0.3/gwt-log-3.0.3.jar
/GWT_MATH/X/2.1/gwt-math-2.1.jar
/GWT_MATH/X/2.1/gwt-math-server-2.1.jar 
/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-0.3.jar          
/GWT_Commons_Logging/X/0.3/GWT-commons-logging/gwt-commons-logging-service-0.3.jar

I have around 1000 jars like this in this list. I would like to remove relative paths before jar name and out put jar names in a new file some thing like this

gwt-servlet.jar             
gwt-user.jar
gwt-dev.jar 
gwt-soyc-vis.jar 
log4j-1.2.15.jar
gwt-log-3.0.3.jar
gwt-math-2.1.jar
gwt-math-server-2.1.jar 
gwt-commons-logging-0.3.jar     
gwt-commons-logging-service-0.3.jar

This is not a one time activity, so i would like to create a target or task in My build.xml for daily usage.

Upvotes: 0

Views: 338

Answers (2)

Brett Kail
Brett Kail

Reputation: 33936

 <replaceregexp file="file.txt" match="[^ ]*/" replace="" byline="true" flags="g"/>

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328556

Ant isn't well suited for tasks like this. It's probably much more simple to write a simple Ant Task in Java for that (or a small Java program; just create File objects and invoke getName() to get the last path element).

But if you have to: script and scriptdef are probably your friends (provided that your version of Ant is recent enough; the docs mention 1.6.3). You can call any Java method from these scripts. See the manual for examples.

Upvotes: 0

Related Questions