I am working on an ant build script. How do i set the two property value with the same name:
<property name="java.src.dir" location="src" />
<property name="java.src.dir" location="src/java" />
In my application some of the directories are src/java and some are src. I need to make it flexible enough to work on both.
Related
My NetBeans project creates my.jar file in /dist/ directory. Trying to edit build.xml to copy this file to another location using ssh. But how to know what is target file name property?
<property name="username" value="aaa"/>
<property name="password" value="bbb"/>
<property name="ip" value="10.1.100.55"/>
<property name="dir" value="/opt/aaa/"/>
<scp file="${dist.jar.dir}${??target??}" todir="${username}:${password}#${ip}:${dir}" trust="true" />
Your Netbeans project has a nbproject/project.properties file, which gets included in build.xml (indirectly) and contains lots of useful variables - including the one that contains a file path to the built jar file. It should be called dist.jar.
<scp file="${dist.jar}" todir="${username}:${password}#${ip}:${dir}" trust="true" />
Check the actual properties file for more variable names, such as dist.dir, src.dir, etc.
I am developing a spring-shell database migration tool.
At the moment i try to use liquibase with the groovy-dsl extension.
My build.gradle includes the extension jar, also i declared liquibase in the spring-shell-plugin.xml
spring-shell-plugin.xml
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase" depends-on="postgresService">
<property name="dataSource" ref="psqlDataSource"/>
<property name="changeLog" value="com.example.db.DbChangelog_master"/>
<property name="defaultSchema" value="${postgres.schema}"/>
</bean>
But everytime i start the application liquibase throws the following error
Caused by: liquibase.exception.UnknownChangelogFormatException: Cannot find parser that supports com.example.db.DbChangelog_master
at liquibase.parser.ChangeLogParserFactory.getParser(ChangeLogParserFactory.java:70)
at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:226)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:192)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:434)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 13 more
The documentation is a bit rare, also the jar is included in the classpath.
Does the groovy scripts need to be in src/main/resources? Currently they are in a seperate package in src/main/groovy
I think that your property
<property name="changeLog" value="com.example.db.DbChangelog_master"/>
is incorrect. This should be the path to your changelog file. If that file is a groovy file, it might be
<property name="changeLog" value="DbChangelog_master.groovy"/>
if that file is available on the classpath.
I am trying to generate apk on command line using ant. I am able to use ant clean but for ant debug and ant release command I am getting following error.
BUILD FAILED
C:\Android\sdk\tools\ant\build.xml:649: The following error occurred while executing this line:
C:\Android\sdk\tools\ant\build.xml:694: Execute failed: java.io.IOException: Cannot run program "C:\Workspace\SampleApp\${aapt}": CreateProcess error=2, Th
e system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
a13CommandLauncher.java:58)...
On line build.xml:694 proguardFile="${out.absolute.dir}/proguard.txt"> line is present. I am using Eclipse Juno and build target is 22 (Lollipop).
Any help is appreciated.
I had the same error after updating the android SDK to the latest build tools.
The tools\ant\build.xml script does not contain any references for the tools.
This can be solved, by adding the tools to the build.xml and point to the correct path. For me this was build-tools\22.0.1
Please compare and update the tool section in build.xml
<!-- tools location -->
<property name="android.tools.dir" location="${sdk.dir}/tools" />
<property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
<property name="android.buildtools.dir" location="${sdk.dir}/build-tools/22.0.1" />
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
<property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
<property name="lint" location="${android.tools.dir}/lint${bat}" />
<property name="zipalign" location="${android.buildtools.dir}/zipalign${exe}" />
<property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
<property name="aapt" location="${android.buildtools.dir}/aapt${exe}" />
<property name="dx" location="${android.buildtools.dir}/dx${bat}" />
<property name="renderscript" location="${android.buildtools.dir}/llvm-rs-cc${exe}"/>
<property name="lint" location="${android.tools.dir}/lint${bat}" />
Thank you Alex for the tip!
This bit Cannot run program "C:\Workspace\SampleApp\${aapt}"suggests that the variable ${aapt} has not been translated by the compiler.
Check that ${aapt} has been defined earlier in your build script. Try printing out value of ${aapt} (e.g. <echo>aapt variable: ${aapt}</echo>) immediately before the line that triggers the error, to check that the build has correctly compiled the variable.
Just update android sdk tool to 24.3.3
make sure the proguard.config point to an existing proguard file in your project.properties
proguard.config=proguard-project.txt
I am building an Android app in Eclipse and have two similar apps based on the same code base, a 'London' one and a 'UK' one. To build each app, I just re-name the main package and change a static int in the Application class. The app uses the value of this int to display the right UI, restrict user behaviour, etc.
I have two icon files, one for each app:
res/drawable-hdpi/icon_london.png
res/drawable-hdpi/icon_uk.png
Is there any way to conditionally use the correct icon file for the Application and Activities depending upon some sort of project configuration setting? Otherwise, the project maintenance is increased as I would have to change my manifest each time the code base changes, e.g.
<application
android:icon="#drawable/icon_london"
...
>
<activity
android:name="com.company.MainActivity"
android:logo="#drawable/icon_london"
>
</activity>
...and so on, for all the activities.
I had a similar issue, and ended up in building my custon Ant script to build the apps. You can run macros or Regular Expressions to assign one resource or another.
EDIT:
First, add build.xml to the project:
Open up a command prompt and navigate to the directory of your project:
android update project --path
Then, you can override the existing build.xml, for something like the following.
NOTE: This Ant script is just an example, I have not tested it:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Example" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"/>
<!-- IMPORT ANT?S BUILD.XML -->
<import file="${sdk.dir}/tools/ant/build.xml" />
<property name="app.icon" value="${icon}" />
<property name="icon.file" location="res/drawable/icon.png" />
<target name="test-release">
<antcall target="test-pre-release" />
<antcall target="release" />
</target>
<target name="test-pre-release">
<copy file="${app.icon}" tofile="${icon.file}" overwrite="true"/>
</target>
</project>
Then, to build this project with a custom icon, open up the command prompt and go to the project directory:
CALL ant -f build.xml test-release -Dicon=path/to/your/icon.png
As said, this is a very basic example. To build a good script, you'll have to learn a bit of Ant syntax, but it's not difficult.
This is a "simple" problem and I am seeking both a how-to and/or a you're-dumb-don't-do-that. I am open to both.
I am building a war file and want the structure to be:
WEB-INF/
properties/
<my properties files>
classes/
...
spring/
<my spring files>
Is that dumb? I know that I can access the properties files though the property-placeholder but I'd rather not nest the properties in the classes section - it doesn't make sense to me.
So the Spring file looks like this:
<context:property-placeholder location="classpath:properties/*.properties" />
if I want to access them in the classes area. I thought that
<context:property-placeholder location="properties/*.properties" />
would let me just put the directory under WEB-INF directly...am I wrong (ps I think I am :) ).
Any advice?
This should work
<context:property-placeholder location="WEB-INF/properties/*.properties" />
WEB-INF is not the root of the of the web-app, so you need to add WEB-INF to the path.
spring-context-3.1.xsd
<xsd:attribute name="location" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The location of the properties file to resolve placeholders against, as a Spring
resource location: a URL, a "classpath:" pseudo URL, or a relative file path.
Multiple locations may be specified, separated by commas. If neither location nor properties-ref is
specified, placeholders will be resolved against system properties.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
You can't do it the way you want since the classpath for the Classloader will be the /classes directory and any jars in the /lib directory. This is the standard configuration for a war file.
Wars and ears have specific configurations which you have to follow for the files to be valid. If you think about it, it would make it difficult to have different vendors provide web containers that could deploy the same war file if there was no standard format. There is a pretty informative page here.
To achieve something similar to what you want, you can simply have directories of /classes/properties and /classes/spring and look them up appropriately from your classpath ("classpath:properties/myfile.properties).
I am not sure what you want to achieve. Here the method I use to inject the properties from a basic properties file to a bean:
In the spring files (XML bean definitions), I add the reference to my property file (myfile.properties):
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:myfile.properties" />
</bean>
and then I add my references to the properties (db.url is the URL address for my database connection, I kept only the bean properties referenced in my property file).
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- results in a setDriverClassName(String) call -->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"><value>${db.url}</value></property>
<property name="username"><value>${db.login}</value></property>
<property name="password"><value>${db.password}</value></property>
</bean>
By default, if the property is not defined in the property file, Spring uses the System Properties (this behaviour can be changed).