Setting spring profile using Ant - java

Is it possible to set the spring profile using Ant? I tried googling it and found that a property named spring.profiles.active has to be set but couldn't find out how to set it using Ant <sysproperty> tag as I am new to both Ant and Spring.

You could use ANT_OPTS to set the system property and launch it from the commandline like this:
ANT_OPTS="-Dspring.profiles.active=myProfile" ant myTarget
Another option is to set it per JUnit test:
<junit fork="no">
<sysproperty key="spring.profiles.active" value="myProfile"/>
</junit>
Example using TestNG
<testng>
<jvmarg value="-Dspring.profiles.active=myProfile" />
...
</testng>

Related

How to run same Maven profile with different parameters

Work currently uses ANT and need to migrate to MAVEN. As stated above , I need to run same profile but with different parameters each time.
Present Ant Code Example :
<target name = SomeTarget>
<var name = "PROP" value="123">
<antcall target = "OutTarget1">
<var name = "PROP" value="145">
<antcall target = "OutTarget1">
</target>
<target name ="OutTarget1">
<!-- some java code -->
<!-- run .SQL files -->
<!-- some java code on that again -->
<\target>
Doesn't seem like even with maven antrun plugin antcall is supported.
Work requires I create all targets as profiles in pom.xml. Now I can simply repeat the "OutTarget1" code in execution part of a profile for each time there is a new property. But that makes it quite hard to debug. And there's a ton of a t targets calling other targets.
If it was just one antcall , I add the parameter in launch configuration. I have no idea how to achieve this when it's same parameter but different values each time.
P.S. Added what OutTarget does. It's basically the same process but with diff values each time.
I don't think what you're trying to do is a good approach, but if it's urgent...have you considered using different settings-[X].xml, with the same profile defined differently and launch maven pointing to them?

Migrate an ant script to Maven3

I'm migrating a maven 1 project to maven 3. The job is almost done actually with a missing task, What I need is to get all dependency names from pom file and write them to a configuration file as one string, the job is done like below in the maven.xml, check the last 5 lines where it writes the names to a file called wrapper.conf.
How can I achive this with Maven3? Is there a maven plugin I can use for this or I need to use ant script within my pom.xml?
<goal name="service">
<mkdir dir="${maven.build.dir}/grid" />
<ant:copy todir="${maven.build.dir}/grid">
<fileset dir="resources/javaservicewrapper" />
</ant:copy>
<j:forEach var="lib" items="${pom.artifacts}">
<j:set var="dep" value="${lib.dependency}"/>
<j:if test="${dep.getProperty('service.bundle')=='true'}">
<ant:copy failonerror="true" todir="${maven.build.dir}/grid/lib">
<fileset dir="${maven.repo.local}/${dep.groupId}/jars">
<include name="${dep.artifactId}-${dep.version}.${dep.type}"/>
<j:set var="SERVCP" value="../lib/${dep.artifactId}-${dep.version}.${dep.type}:${SERVCP}" />
</fileset>
</ant:copy>
</j:if>
</j:forEach>
<attainGoal name="jar" />
<ant:copy file="target/${maven.final.name}.jar" tofile="${maven.build.dir}/grid/lib/grid.jar" />
<j:set var="SERVCP" value="${SERVCP}../lib/gridcache.jar" />
<ant:copy todir="${maven.build.dir}/gridcache/conf" file="resources/javaservicewrapper/conf/wrapper.conf" overwrite="true">
<filterset begintoken="#" endtoken="#">
<filter token="service.classpath" value="${SERVCP}"/>
</filterset>
</ant:copy>
</goal>
EDIT : The solution using build-classpath worked well but I had other problems specific to using Javaservicewrapper. So best solution I found was creating whole the script/config file by appassembler-maven-plugin and let maven-assembly plugin to copy it to the conf folder
If you have the need to create a JSW (wrapper.conf) the simplest solution would be to use the appassembler-maven-plugin which can create such files.
Have a look at the build-classpath goal of the Maven Depency Plugin. You can fast check the result on the command line:
mvn dependency:build-classpath
You can change the path to the dependeny files using the 'prefix' (mdep.prefix) property
mvn -Dmdep.prefix=myLibFolder dependency:build-classpath
You will find much more configuration parameters in the documentation, e.g. the outputFile parameter ;-)

Set target or property to a sub project with Ant/Eclipse on Android

I need to switch to Ant, I managed to compile and install the Android apk file but I didn't manage to transmit the property or a specific target to the referenced library.
My code on the build.xml in the referenced library :
<echo message="Property value is '${foo.dist}'" />
<target name="AfficherVersionAnt">
<echo message="Version d'Ant utilisée : ${ant.version}"/>
</target>
The same code is functional when I put it in the starting package.
<property name="foo.dist" value="true"/>
(and for the target, if I launch with the target)
My ant configuration was generated with :
"C:\Program Files (x86)\Android\android-sdk\tools\android" update project -p "D:\project"
And I don't see where I could set a link
Can someone help me ? I would need global variables or something like this
In eclipse you can define your own variables for ant
Go to external tools configuration > your profile > environnement, and define new environnement variable.

How to add extraClasses option to Ant script when calling java2wsdl?

I'd like to pass extraClasses parameter when I generate java2wsdl. Here is my Ant task:
<target name="rews.all" depends="xews.aar">
<echo message="${axis2.classpath}" />
<delete file="${build.dir}/wsdl/XEWS.wsdl" />
<taskdef name="java2wsdl"
classname="org.apache.ws.java2wsdl.Java2WSDLTask"
classpathref="axis2.classpath">
</taskdef>
<java2wsdl className="com.dd.xews.XEWS"
outputLocation="${build.dir}/wsdl/"
targetNamespace="http://xews.dd.com/"
schemaTargetNamespace="http://xews.dd.com">
<classpath>
<pathelement path="${axis2.classpath}"/>
<pathelement location="${build.dir}/classes"/>
<pathelement location="${vendor.dir}/AWS/lib/aws-java-sdk-1.2.1.jar"/>
</classpath>
</java2wsdl>
<copy todir="${build.dir}/" file="${build.dir}/wsdl/XEWS.wsdl"/>
</target>
Tried everything but no luck.
Does anyone know the syntax? How do I add extraClasses here?
Test1 (failed)
This failed with error java2wsdl doesn't support the "extraClasses" attribute:
<java2wsdl className ="com.dd.xews.XEWS"
outputLocation ="${build.dir}/wsdl/"
targetNamespace ="http://xews.dd.com/"
schemaTargetNamespace ="http://xews.dd.com"
extraClasses ="com.dd.xews.XEWS.Emailer.java">
</java2wsdl>
How to find out which attributes java2wsdl Ant task does support?
My Axis2 version is 1.5.4.
Here's a link to the source code of Ant task: Java2WSDLTask.
#setExtraClasses accepts String parameter, and then tries to split it using comma delimiter. So try passing something like
<extraClasses>com.test.Class1,com.test.Class2</extraClasses>
EDIT
This will not work in older versions of Axis2 (to be more precise -- versions prior 1.6.0). It's because of 'extraClasses' attribute was specified as an array-type, which is obviously not supported as Ant task attribute. You can find all the details in this JIRA issue: AXIS2-4634: Ant task Java2WSDLTask does not allow the use of extraClasses
The easiest way to make it work is to upgrade Axis2 JARs to a newer 1.6.x version. If you are stuck with Axis2 version for some project-specific reasons (I don't see there should be any), you could take the source code of Java2WSDLTask from the newer version (see link to GrepCode above), and make a copy of this task in your project (you'll have to use different class name, or package), then use it as an Ant task just like you are using it currently. Except for it will be possible to use 'extraClasses' attribute.
Axis2 1.4 and up support the "-xc" attribute. Here's how I did it:
<java classname="org.apache.ws.java2wsdl.Java2WSDL" fork="true">
....
<arg value="-xc"/>
<arg value="com.example.mypackage.MyClass"/>
<arg value="-xc"/>
<arg value="com.example.anotherpackage.MyOtherClass"/>
....
</java>

Java Ant - how to pass a ProGuard task arguments and use them inside a configuration file?

I have this in my build.xml:
<target depends="build-jar" name="proguard">
<taskdef resource="proguard/ant/task.properties" classpath="tools/proguard4.6/lib/proguard.jar" />
<proguard configuration="ant/proguard.conf" />
</target>
It works fine.
Inside the configuration file (i.e "ant/proguard.conf") I'm trying to access properties defined in this build.xml file but I'm always getting this kind of error:
Value of system property 'jar.final_name' is undefined in '<jar.final_name>' in line 1 of file '.......\ant\proguard.conf'
The error is clear. Question is how I do what I'm trying to?
If I'd do it the "Embedded ProGuard configuration options" way I could use these properties like any other property in build.xml, but I'm trying to keep the files separate.
How do I do that then?
By default, Ant doesn't provide a way to set java system properties for its tasks. You can only specify -D options in the ANT_OPTS system variable when starting Ant itself.
I'll consider supporting the use of Ant properties in referenced ProGuard configurations (being the developer of ProGuard).
For the time being, an acceptable solution might be to specify input and output jars in Ant's XML-style:
<proguard configuration="ant/proguard.conf">
<injar name="${injar}" />
<outjar name="${outjar}" />
<libraryjar name="${java.home}/lib/rt.jar" />
</proguard>
This part of the configuration is more closely tied to the Ant script anyway.

Categories