Ant Script to find substring - ant

How to write ant script to get a substring from one property file and copy in another property file?
For Eg. I am getting oracle_12c in a property file but now I want to store oracle in one value and 12c in another value in a property file.Can anyone suggest how to write antscript for this.

Related

How to manage property files with Ant?

I have a program that takes values from a property file(host,port), the path of the property file is currently beign hard coded, but I want to be able to compile and place the property file in the same directory as my compiled classes(in bin/) and when I make a jar and run the program,it should take the values from there automatically, how do I do that?
You should be able to use a "copy" task to copy the property file in your bin directory, inside the same package directory as the java file that needs to read the properties. Then, jar the program, using the "jar" task.
In the java program, you should now be able to read the properties in this way:
Properties props = new Properties();
props.load(getClass().getResourceAsStream("my.properties"));
String host = props.get("hostname");
String port = props.get("port");

How to import a variable value from txt file in ant?

I am relatively new to Ant, I have written an ant build file that will open command prompt in windows 7 and pass an argument line.
So how would I pass a variable in this argument line whose value it will get from a txt file in a certain folder?
Try the loadfile task.
See documentation and this answer for examples

Passing property files in a loop to Ant script

I have a directory with a list of property files for different environment(DEV/STG/QA etc.,)
I want to call an Ant target in a loop with each of this file. How do I do this. I downloaded ant-contrib and tried using the foreach but I couldn't find any example where I can read property files one at a time and call the target. Any suggestions?
I have been looking at a lot of samples on this site and online, nothing seem to match my requirement.
As per apacche documentation : https://ant.apache.org/manual/Tasks/property.html
<property file="foo.properties"/>
reads a set of properties from a file called "foo.properties".
so, if you have my.var=25 , then ${my.var} will get you its value 25. For your requirement you can iterate through the files based on 'env' name & do required tasks.

How to get a filename without extension in ant

I know how to get the basename for a file with java's ANT build tool, but in this case I want to change the name of a file to include a build version number. Unfortunately the file's name gets set in another ant script (from the android system) which I am importing and I'm not able to set the property for that file or the imported script will complain that the property should not be set already. Thus, if i have a property holding MyApp-release.apk and I want to change the value to MyApp-release-1.10.apk how would I do this? I know I can put the 1.10 at the start of the filename with basename and that's probably what I will do, but I'd rather do it the other way.
Form http://ant.apache.org/manual/Tasks/basename.html:
Task to determine the basename of a specified file, optionally minus a
specified suffix.
<basename property="cmdname" file="D:/usr/local/foo.exe"
suffix=".exe"/>

Using ANT with multiple XSD and single XJB

I have a custom external XJB file that has the schema name within it as follows :
jxb:bindings schemaLocation="completeCheck.xsd" node="/xs:schema"
Just wondering, is there a way to substitute the schema name at runtime within the XJB file using ANT(using ANT XJC) OR have a xjb binding file written such that I do not have to hardcode the schema name in it. Basically, I am trying to see if I can use a single xjb file for multiple XSDs.
Currently, I have the same xjb file all over the place with a different hardcoded schema name referred all over the place in build.xml. Any pointers are highly appreciated. I am using JAXB 2.x
Make a template from your xjb file by replacing the value of your schemaLocation attribute with some sort of marker (e.g. !!!) and save it using some other name/extension. Define a macro with an attribute such as schema-name that will use ant's replace to change the marker in the template file with your schema name and save that as the binding file to be subsequently used by xjc.
Normally, in the latest versions of XJC, you can use schema component designator. More info here :
https://jaxb.java.net/nonav/2.2.1/docs/vendorCustomizations.html#scd and https://jaxb.java.net/guide/Using_SCD_for_customizations.html

Resources