I start studying ANT today in order to make Java compiling easier.
I wrote simple ANT script which only use javac command.
What I am trying is compile from .....\head_first\src\com\masatosan\constant.java (source)
to the destination directory:
.....\head_first\WEB-INF\classes\com\masatosan\conf
So the result would look like:
.....\head_first\WEB-INF\classes\com\masatosan\conf\constant.class
But I can't figure out why the actual result adds "/com/masatosan/conf" directories to the destination folder, so it looks like:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes\com\masatosan\conf\com\masatosan\constant.class
Could anyone tell me how can I fix this?
ANT
<project name="CompileMasatosan"
basedir="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan">
<description>
masatosan compiler
</description>
<property name="confSrc"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\src\com\masatosan\conf" />
<property name="confDest"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes\com\masatosan\conf" />
<target name="compileConfSrc">
<javac srcdir="${confSrc}" destdir="${confDest}" />
</target>
</project>
UPDATE
I didn't know complier creates directories based on the package name.
The package name of constant.java was com.masatosan.conf so that complier creates "/com/masatosan/conf/"
You're trying to tell ANT to change the package because you want Constant.class to be under the com.masatosan.conf package rather than the com.masatosan package. The Ant compilation process will create the appropriate package subdirectories, which is why you see com\masatosan created under the dest.
I don't think you can tell ANT to change the package of a source file, which is what you're trying to do by injecting an extra conf dir. You can either create a conf dir and have a conf\com\masatosan\constants.class or put it under classes\com\masatosan\constants.class, but you can't do com\masatosan\conf\constants.class since that changes the package of constants.class to com.masatosan.conf
Or simply change the package of constants.class to com\masatosan\conf and change your ant file to to:
<property name="confDest"
location="C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes" />
Its because of the package name. You have a Java file in package com.masatosan. You can fix this two way either move class to default package or set ${confDest} value to \head_first\WEB-INF\classes\ only.
This is because the compiler is creating the package directory stucture under the destination directory you specify. The constant class is in the com.masatosan package, so under classes\com\masatosan\conf, the compiler creates a further two directories for the package, com\masatosan, and places the compiled class (constant.class) in there.
Your destination directory should simply be C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\head_first\WEB-INF\classes. The com and masatosan directories will be created for you.
Related
Problem:
We have a Websphere EAR project. Under it are two web modules. These two web modules make use of the same shared session context. This in enabled by setting in it the ibm-application-ext.xml file of the ear project.
I know how to create an ant build script to create an .ear file. The thing is, I do not know how to include ibm-application-ext.xml in the ant script to have it included in the .ear file . How do I do that?
If the application.xml file is included through the ff. syntax below, how to I include ibm-application-ext.xml.
<ear destfile="somearfile.ear" appxml="conf/application.xml">
If it's stored in conf/application.xml, then something like this:
<ear destfile="somearfile.ear" appxml="conf/application.xml">
<zipfileset dir="conf" includes="ibm-application-ext.xml" prefix="META-INF"/>
</ear>
...or just:
<jar destfile="somearfile.ear">
<zipfileset dir="conf" includes="*.xml" prefix="META-INF"/>
</jar>
How does one get the full physical path of the .sln file when scripting in MSBuild?
I'm trying to force nuget to download packages using:
<Target Name="BeforeCompileConfiguration">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "$(SolutionRoot)\KK\MyProject.sln"" />
</Target>
KK is the name of the folder that the .sln file is under. I'd like to replace
$(SolutionRoot)\KK\MyProject.sln
with a single $() build property.
$(SolutionPath)
should do your job!
By the way it's equivalent to:
$(SolutionDir)$(SolutionFileName)
I am running into the following error when trying to run ant:
Problem: failed to create task or type runtarget
I am building on a mac 10.8.3.
Prior research has suggested that I add ant-contrib-0.3.jar to my ANT_HOME installation directory, which I have done (that had actually gotten rid of another 'failed to create task or type' error)
I used ant-contrib-0.3.jar because research suggested that this jar is mapped to the line:
< taskdef resource="net/sf/antcontrib/antcontrib.properties" />
which is in the build.xml file I am using.
The project builds on windows machines ( I even got it to build using https://code.google.com/p/winant/ ) but am trying to get it built on a mac. I am thus not looking to change the build.xml file.
An example of the run target line is:
<target name="setPASProps" depends="" description="setup the properties">
<property name="systemname" value="PAS"/>
<runtarget target="setSystemProps"/>
</target>
Here is some info from running ant -diagnostics
-------------------------------------------
ANT PROPERTIES
-------------------------------------------
ant.version: Apache Ant(TM) version 1.8.2 compiled on June 20 2012
ant.java.version: 1.7
Is this the Apache Harmony VM? no
Is this the Kaffe VM? no
Is this gij/gcj? no
ant.core.lib: /usr/share/ant/lib/ant.jar
ant.home: /usr/share/ant
-------------------------------------------
ANT_HOME/lib jar listing
-------------------------------------------
ant.home: /usr/share/ant
ant-antlr.jar (5756 bytes)
ant-contrib-0.3.jar (17708 bytes)
ant-jmf.jar (6745 bytes)
ant-junit.jar (102350 bytes)
ant-junit4.jar (7126 bytes)
ant-launcher.jar (12321 bytes)
ant-swing.jar (7563 bytes)
ant-testutil.jar (15198 bytes)
ant.jar (1937098 bytes)
Thanks !
It would be helpful if you posted your build.xml too.
You usually get this error if Ant sees a task, but there's a problem with the definition.
Here's my recommendation:
In your project create a directory antlib/ant-contrib.
Download this zip file. Ant-contrib is a wee bit strange is that there is a separate jar for C compiling and for all of the other Ant tasks. The latest version is 1.0b3. When you unzip this zip file, you will see ant-contrib-1.0b3.jar inside this folder.
Put that ant-contrib-1.0b3.jar inside the antlib/ant-contrib folder.
Now, in your build.xml, use the following <taskdef/>:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/antlib/ant-contrib"/>
</classpath>
</taskdef>
Make sure this is not inside a target. You want this to be executed before any targets are executed.
I like doing the definition this way because the Ant Contrib jar file becomes part of my project, and anyone who needs to run my project will not have to manually install the Ant Contrib jar before they can use my project.
Take a look at your build.xml and see where that <Runtarget> task is being used. I've never used it, and the documentation for this task is so clear and helpful. Actually, I'm not even sure if it works. If you are still having problems, you try to see if you can remove the defined <target/> that contains this task, and see if that gets rid of the issue.
Removed ant-contrib-0.3.jar and added ant-contrib-1.0b3.jar and ant-contrib.jar to my ANT_HOME directory since these are the jars installed with https://code.google.com/p/winant/ (and it was working on windows machines).
This did the trick.
I got this error when I included guava-11.0-rc1.jar which contains the package com.google.common.* . But when I try to package it, it gives me the error:
Error preverifying class com.google.common.collect.Ordering MyApp line 0
BlackBerry Packaging Problem
Can anybody tell me what can be done to solve this? Thanks in advance.
Make sure the classes in that library are Java-ME compatible. Remember CLDC is a subset of Java SE and the equivalent desktop compilation level would be 1.2
If they were compatible, then to solve the preverification error you must first preverify your jar. You might be wondering what preverification is. There's a good explanation in this answer.
Preverification is usually done (or should be done) by the Eclipse plugin, but some versions do not. If this is your case, you should do it manually. In your JDE folder, there is a tool called preverify. You could find it in a path that typically looks like this in a Windows machine:
(1) C:\Program files\Research In Motion\BlackBerry JDE <vers>\bin\
You'll also need a library called net_rim_api.jar located in a path like this:
(2) C:\Program files\Research In Motion\BlackBerry JDE <vers>\lib\net_rim_api.jar`
This is all you need to launch the command. Open command line and change dir to the bin folder (1). Then type :
preverify -classpath <classpath for lib> -d <output directory> <file to preverify>
Where:
<classpath for lib> is the path in (2)
<output directory> is the directory where the preverified jar will be saved.
<file to preverify> is the absolute path to the file you want to preverify (guava-11.0-rc1.jar in your case)
If everything went well, now you'll have a new jar in <output directory> which is slightly bigger than the input jar file. This is the one you should include in your project. The preverify tool does not change your original jar.
I'm trying to use Nant to compile an ASP.NET MVC app, so far my build script just runs ms build and runs some other tasks, however I want my compiled files to be put in a "build" directory, how can I tell msbuild where to put the compiled files?
Looking here:
http://msdn.microsoft.com/en-us/library/ms164311.aspx
it specifies that you can set msbuild to override the output dir setting in your project file, like so:
/properties:OutputDir=bin\Debug
Is this what you want?
you can put this in your project file (or in an imported project file if you want reuse), it will override both the path for the executable/dll and the path where the .obj files etc go.
<PropertyGroup>
<OutputPath>c:\bin</OutputPath>
<BaseIntermediateOutputPath>c:\temp\$(AssemblyName)</BaseIntermediateOutputPath>
</PropertyGroup>
If you are using the <msbuild> task from NAntContrib, then you can set the OutputDir property like this:
<msbuild project="path-to-sln-or-csproj-or-msbuild" target="Build">
<properties>
<property name="OutputDir" value="build-outdir-dir" />
</properties>
</msbuild>