Ant Tomcat: Failed to create task or type "list" - linux

I am using Spring official docs to understand the Spring Basic Application and Environment set up on Linux using Ant.
Softwares and system configurations:
OS: Linux/Ubuntu
JRE: 1.8.0_51-b16
Ant Version: 1.9.3
IDE: Luna Service Release 1 (4.4.1)
Project directory structure:
Everything goes fine till end of Section 1.3 where I can start the tomcat server and execute ant, ant deploy successfully and I have the desired output as follows:
But when I am trying to execute ant list - the build fails.
Buildfile: /home/sandeep/MyDocs/workspace/springapp/build.xml
list:
BUILD FAILED
/home/sandeep/MyDocs/workspace/springapp/build.xml:113: Problem: failed to create task or type list
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
Here is the list target in my build.xml:
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>
What am I doing wrong here? Here is a link to my entire build.xml.

In the article you linked to, it shows how to add the <list> task:
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath refid="catalina-ant-classpath"/>
</taskdef>
Add the above line to your build.xml.

I think task list is unknown to ant. There is no task named list defined by ant. To start tomcat I did something like --
<exec executable="${tomcat.home}/bin/tomcat5.exe" >
<arg value="start"/>
<env key="JAVA_OPTS"
value="-Xint -Xdebug -Xrunjdwp:transport=dt_socket,address=${hotswap.port},server=y,suspend=n"/>
</exec>
</target>

Related

Publish of ASP.Net Core project fails with "DestinationFiles" refers to 1 item(s), and "SourceFiles" refers to 2 item(s)

Publish of ASP.Net Core project fails with next error:
"DestinationFiles" refers to 1 item(s), and "SourceFiles" refers to 2 item(s).
They must have the same number of items.
I get an error when I try to publish an ASP.Net Core website to Azure. It builds and runs fine locally. The output prints this:
Task "Copy"
Task Parameter:
SourceFiles=
C:\Users\Mikael\Source\Repos\GoMap-Web\src\Web\appsettings.json
CopyToPublishDirectory=PreserveNewest
RelativePath=appsettings.json
TargetPath=appsettings.json
C:\Users\Mikael\Source\Repos\GoMap-Web\src\Web\appsettings.json
CopyToPublishDirectory=PreserveNewest
RelativePath=appsettings.json
TargetPath=appsettings.json
Task Parameter:DestinationFiles=C:\Users\Mikael\Source\Repos\GoMap-Web\src\Web\obj\Release\netcoreapp1.0\PublishTemp\PublishOutput\appsettings.json
Task Parameter:OverwriteReadOnlyFiles=False
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(100,5): Error MSB3094: "DestinationFiles" refers to 1 item(s), and "SourceFiles" refers to 2 item(s). They must have the same number of items.
Output Item(s): FileWrites=C:\Users\Mikael\Source\Repos\GoMap-Web\src\Web\obj\Release\netcoreapp1.0\PublishTemp\PublishOutput\appsettings.json
Done executing task "Copy" -- FAILED.
Done building target "_CopyResolvedFilesToPublishPreserveNewest" in project "Web.csproj" -- FAILED.
Done building project "Web.csproj" -- FAILED.
The Microsoft.NET.Publish.targets file (the relevant part, i belive) look like this:
============================================================
CopyFilesToPublishDirectory
Copy all build outputs, satellites and other necessary files to the publish directory.
============================================================
-->
<Target Name="CopyFilesToPublishDirectory"
DependsOnTargets="_CopyResolvedFilesToPublishPreserveNewest;
_CopyResolvedFilesToPublishAlways" />
<!--
============================================================
_CopyResolvedFilesToPublishPreserveNewest
Copy _ResolvedFileToPublishPreserveNewest items to the publish directory.
============================================================
-->
<Target Name="_CopyResolvedFilesToPublishPreserveNewest"
DependsOnTargets="_ComputeResolvedFilesToPublishTypes"
Inputs="#(_ResolvedFileToPublishPreserveNewest)"
Outputs="#(_ResolvedFileToPublishPreserveNewest->'$(PublishDir)%(RelativePath)')">
<!--
Not using SkipUnchangedFiles="true" because the application may want to change
one of these files and not have an incremental build replace it.
-->
<Copy SourceFiles = "#(_ResolvedFileToPublishPreserveNewest)"
DestinationFiles="#(_ResolvedFileToPublishPreserveNewest -> '$(PublishDir)%(RelativePath)')"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForPublishFilesIfPossible)"
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForPublishFilesIfPossible)">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
</Target>
<!--
============================================================
_CopyResolvedFilesToPublishAlways
Copy _ResolvedFileToPublishAlways items to the publish directory.
============================================================
-->
<Target Name="_CopyResolvedFilesToPublishAlways"
DependsOnTargets="_ComputeResolvedFilesToPublishTypes">
<!--
Not using SkipUnchangedFiles="true" because the application may want to change
one of these files and not have an incremental build replace it.
-->
<Copy SourceFiles = "#(_ResolvedFileToPublishAlways)"
DestinationFiles="#(_ResolvedFileToPublishAlways -> '$(PublishDir)%(RelativePath)')"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForPublishFilesIfPossible)"
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForPublishFilesIfPossible)">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
</Target>
I have changed the DestinationFiles="#(_ResolvedFileToPublishPreserveNewest -> '$(PublishDir)%(RelativePath)')" according to another post here but I still get the same failure, and I don't know enough about it to find any clear errors, can anyone offer some insight? If this is affected by the bug mentioned in other posts that has no workaround, what alternative ways could I try to publish the app to azure that might work better?

Cant Run Java FX Executable Jar or Native Bundle

I have created a java fx application on Netbeans 7.3.1 with fxml,hibernate. It works fine when run in Netbeans and when run the jar file from dist folder. Database operations are just fine. But I want export the app to another system in a portable form. So i created the native bundle using the tools Wix and Inno 5. But the produced app doesnt work in my own syntem or another system. Shows Exception while runnig application. I checked several times by changing the db ip address as localhost, 127.0.0.1 and my my physical ip. but no working.
My java version is Java 7 update 40 (jdk1.7.0_40)
This is the link for the screenshot showing error : http://i.imgur.com/popokhh.jpg
my build.xml contains
<target name="-post-jfx-deploy">
<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
nativeBundles="all"
outdir="${basedir}/${dist.dir}" outfile="${application.title}">
<fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
<fx:resources>
<fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>
</fx:resources>
<fx:info title="${application.title}" vendor="${application.vendor}"/>
</fx:deploy>
</target>
And my hibernate cfg file contains
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sample?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="entity/Sample.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Is there any extra configuration for the application to work independently??
I got it fixed...
All i need to do was include the lib folder in the build... My bad.

MSBuild error executing target WebDirectoryCreate

I'm trying to use the WebDirectoryCreate task from the MSBuildCommunityTasks to create my virtual directory with MSBuild but it throws an Index was out of range error.
Here's the relevant part of my build script:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
...other build targets working ok...
<Target Name="Deploy">
<RemoveDir Directories="$(DeploymentFolder)$(VerRevision)" ContinueOnError="true" />
<ItemGroup>
<DeploymentFiles Include="$(PublishOutputFolder)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(DeploymentFiles)" DestinationFolder="$(DeploymentFolder)$(VerRevision)\%(RecursiveDir)" />
<WebDirectoryDelete VirtualDirectoryName="$(VirtualDirectory)$(VerRevision)" ContinueOnError="true" />
<WebDirectoryCreate VirtualDirectoryName="$(VirtualDirectory)$(VerRevision)" VirtualDirectoryPhysicalPath="$(DeploymentFolder)$(VerRevision)" />
</Target>
And here's the corresponding output:
Deleting virtual directory 'MyApp283' on 'localhost:80'.
MSBUILD : warning : The system cannot find the path specified. (Exception from HRESULT: 0x80070003) [D:\build\MyApp\Build.xml]
The previous error was converted to a warning because the task was called with ContinueOnError=true.
Build continuing because "ContinueOnError" on the task "WebDirectoryDelete" is set to "true".
Creating virtual directory named MyApp283 on localhost:
D:\build\MyApp\Build.xml(50,5): error : Index was out of range. Must be non-negative and less than the size of the collection.
D:\build\MyApp\Build.xml(50,5): error : Parameter name: index
Done Building Project "D:\build\MyApp\Build.xml" (default targets) -- FAILED.
Build FAILED.
I have checked the import is correct by adding the virtual directory manually and running the build. In this case the WebDirectoryDelete task corrcetly deletes the virtual directory but WebDirectoryCreate throws the same error.
I'm executing the build using MSBuild from a simple batch file. All tasks before this one execute just fine. OS is Windows Server 2008 R2 Enterprise Edition SP1.
Can anyone give me any clues? SO and Google threw up one single link with no answer.

SONAR - Measure Code Coverage using Cobertura

I am using sonar to measure code quality. One thing that I do not know is the steps to measure code coverage using Cobertura.
I followed the steps from http://cobertura.sourceforge.net/anttaskreference.html and was able to generate xml files. How do I get these xml files into SONAR?
Is there an easier way to use Cobertura in SONAR?
I am running the code coverage (Cobertura) in a different server than my SONAR server. Both servers are running under LINUX.
Thanks for the help!
You configure the Sonar task to upload unit test and cobertura reports generated by other parts of your build logic.
This is in contrast to Maven which has a standard build life-cycle that Sonar is able to leverage.
Unit test and code coverage
The following logic runs the unit tests with cobertura instrumented classes. An XML coverage report is generated by cobertura at the end:
<target name="instrument-classes" depends="compile-tests">
<taskdef resource="tasks.properties" classpathref="test.path"/>
<cobertura-instrument todir="${instrumented.classes.dir}" datafile="${build.dir}/cobertura.ser">
<fileset dir="${classes.dir}"/>
</cobertura-instrument>
</target>
<target name="junit" depends="instrument-classes">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="test.path"/>
<pathelement path="${instrumented.classes.dir}"/>
<pathelement path="${test.classes.dir}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${test.reports.dir}">
<fileset dir="${test.src.dir}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="test" depends="junit">
<cobertura-report format="xml" datafile="${build.dir}/cobertura.ser" destdir="${cobertura.reports.dir}"/>
</target>
Invoking Sonar
I normally use a very simple Sonar target:
<target name="sonar" depends="test">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="sonar.path"/>
<sonar:sonar key="${sonar.project.key}" version="${sonar.project.version}" xmlns:sonar="antlib:org.sonar.ant"/>
</target>
And use a properties file to control all aspects of Sonar's behaviour:
sonar.project.key=org.demo:demo
sonar.project.version=1.0-SNAPSHOT
sonar.projectName=Demo project
sonar.host.url=http://myserver:9000
sonar.jdbc.url=jdbc:mysql://myserver:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sources=${src.dir}
sonar.tests=${test.src.dir}
sonar.binaries=${classes.dir}
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=${test.reports.dir}
sonar.java.coveragePlugin=cobertura
sonar.cobertura.reportsPath=${cobertura.reports.dir}/coverage.xml
Demonstrates how Sonar can be configured to pick up the unit test reports created by junit and the code coverage report generated by cobertura.
The build does not have to run on the same server as Sonar. In that case one must provide the remote Sonar URL and JDBC credentials.
You would have to add these properties to Sonar's pom.xml:
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
<sonar.phase>generate-sources</sonar.phase>
<sonar.surefire.reportsPath>target/reports/test/</sonar.surefire.reportsPath>
<sonar.cobertura.reportPath>../project/target/reports/coverage/coverage.xml</sonar.cobertura.reportPath>
</properties>
(with paths appropriate to your environment)
And run:
mvn sonar:sonar
Check the user list for more details.
if you're using Maven, then you do not have anything special to specify in your POM file. Just run "mvn clean sonar:sonar" and Sonar will automatically compile your code, run your tests with Cobertura (which is the default coverage engine in Sonar) and push all the results in the DB.
Same if you're using Ant [1] or the simple java runner [2] instead of Maven.
I do insist on the fact that you do not have to manually run Cobertura (with an Ant task for instance) previously to running Sonar.
[1] http://docs.codehaus.org/display/SONAR/Analyzing+with+Sonar+Ant+Task
[2] http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner
Fabrice,
SonarSource

cruise control .net : xcopy not working for copying files to remote server

I am trying to copy a folder to a remote machine using xcopy. This command is executed via cruise control task. I can run xcopy source destOnRemoteMachine successfully if i am running it from command prompt. But if i am executing it from cruise control .net, it is always complaining about "Invalid drive specification" error.
I tried :
> <exec
> executable="c:\Windows\System32\xcopy.exe">
> <baseDirectory>$(BASE)\Project</baseDirectory>
> <buildArgs>.\*.* RemoteMachine\Project /Y</buildArgs>
> <buildTimeoutSeconds>10</buildTimeoutSeconds>
> <successExitCodes>-1,0,1</successExitCodes>
> </exec>
and :
<exec executable="c:\Windows\System32\cmd.exe">
<baseDirectory>$(BASE)\Project</baseDirectory>
<buildArgs>/C xcopy $(BASE)\Project\*.* RemoteMachine /y</buildArgs>
<buildTimeoutSeconds>30</buildTimeoutSeconds>
<successExitCodes>-1,0,1</successExitCodes>
</exec>
Any Suggestions?
thanks for your answer. Putting xcopy in batch was also not helpful, the problem was something else. here is problem:
It was problem with the account on which Cruise Control .net service was running. It was running as local service. Thus was not able to see the network path. I changed CCNet Service to run on a domain account which have permission to read/ write on remote machine. This solved my problem.
Thanks.
Create a batch file using xcopy source destOnRemoteMachine command and execute that bat file using <exec> command in cruise control .net
In my case I was running CC as a user account, after having used NET USE to persistently map a drive letter to a network share on another domain. Although it worked in a desktop session, CC could still not get to the share as part of the build. Executing NET USE as part of the build (without a drive mapping) allowed the copy to succeed.
<exec program="net" verbose="true">
<arg value="use" />
<arg value="\\server\share" />
<arg value="password" />
<arg value="/user:domain\username" />
</exec>

Resources