How do you deploy a war at startup in apache-karaf - war

I have created a war file that I deploy in karaf by running the osgi:install command like
osgi:install -s file:/system/com/mywebapp/1.0.0/mywebapp-1.0.0.war
How can I configure karaf so that this happens when the karaf instance starts?
I've changed the org.apache.karaf.features.cfg file to start the war feature by default
featuresBoot=config,ssh,management,kar,war

Here is a sample features.xml for a war file-
<?xml version="1.0" encoding="UTF-8"?>
<features name="feature-set">
<feature name="my-feature" version="1.0.0"
xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
<feature>war</feature>
<bundle>mvn:com.foo/mywebapp/1.0.0/war</bundle>
</feature>
</features>
The important part is that the mvn url to the war file "mvn:com.foo/mywebapp/1.0.0/war". If you miss the suffix /war in the path the maven url looks for a jar file.

It's best to create your own features file and start your war from this features file, with it you are also able to set the startlevel and it's dependencies.
Another way of deploying is to place your war in the deploy folder.

Related

Build a single web deploy package from multiple web projects

I have a solution with A LOT of web projects (80+). I'm using WDP to deploy my projects to the environments, so I have a script that builds a web deploy package for each project and then each package is published.
Each package is deployed without deleting what is already there and each package can override duplicate files. It works but the deployment is quite slow.
I have a strong suspicion that having one package with all the file would be a lot faster, since from the looks of it a lot of the time is spent on the setup of the connection to the server and not much on the deployment itself (probably because many files are not updated)
Is there a way to build a single WDP from multiple web projects in visual studio solution or using MSBuild and a couple of scripts?
Thanks
Is there a way to build a single WDP from multiple web projects in visual studio solution or using MSBuild and a couple of scripts?
Since you have a script that builds a web deploy package for each project, you can try to deploy those project to the local folder, you can think of this an “intermediate publish folder”. From there you can construct a zip task to all packages to one zip file, then publish/copy this zip file to publish directly.
To accomplish this, you can create a .csproj file with following code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="Zip" AfterTargets="Build">
<CreateItem Include="YourLocalPublishFolder\*.*" >
<Output ItemName="ZipFiles" TaskParameter="Include"/>
</CreateItem>
<Zip ZipFileName="YourZipFile.zip" WorkingDirectory="YourPublishFolder" Files="#(ZipFiles)" />
With this .csproj file, all .zip are compressed into a package to the publish folder, do not need to publish each project to the publish folder.
Note: Need import the MSBuildTasks.targets to the .csproj file, which including Zip target.
Hope this helps.

Precompiling a site for deployment using .targets file for MSBuild

I have an ASP.NET web project (.Net 4.5, Visual Studio 2015).
The solution uses the XAML builds, not the newer web builds. Some of the builds deploy the application directly to the IIS server using a file copy.
We do not use the Publish action from Visual Studio to publish the project.
In the .csproj file of the ASP.NET project, the following import statement was added to add an additional .targets file:
<Import Project="CSADeploy.targets" Condition="Exists('CSADeploy.targets')" />
<Target Name="AdditionalTargets">
<!-- ... -->
</Target>
In this target file the files are copied.
Here is a short excerpt from the .targets file:
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
I would like the code that is deployed to the server to be precompiled for deployment either Deployment Only or Deployment with updateable UI is fine. I know there is a checkbox in the Publish action to precompile but I can't use that. I must use the existing XAML builds with the targets file and possibly instruction in the .csproj file.
I also know that I can use the Aspnet_compiler.exe tool on the server once the file are deployed. But I must do it before the file are copied because I do not have access to this server and I want to prevent adding a manual action to the build process.
How can I precompile the ASP.NET pages for deployment so that they are deployed correctly in my scenario?
You could create a .pubxml file for your project then check in to TFS, in the .pubxml file, set precompileBeforePublish to True.
<PropertyGroup>
......
<PrecompileBeforePublish>True</PrecompileBeforePublish>
</PropertyGroup>
In the xaml build definition, add these msbuild arguments:
/p:deployOnBuild=true /p:publishProfile=***.pubxml
Then in TFS xaml build, it will do precompile before deploy.

WebDeploy: Exclude a specific DLL from a deployment package

How do I tell Web Deploy to exclude a particular DLL file from a web deployment package?
This answer https://stackoverflow.com/a/27404527 offers the advice to exclude the DB2 database driver IBM.Data.DB2.dll from the bin folder of a web application. Otherwise you get an BadImageFormatException in IIS because Visual Studio package the wrong version of the DLL with the web app. I just ran into this issue and tried to follow the advice.
Unfortunately I could not convice Web Deploy to omit this particular DLL. I read this blog post
http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx
and added this
<ItemGroup>
<ExcludeFromPackageFiles Include="$(OutputPath)IBM.Data.DB2.dll">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
but without success. I can still find the DB driver unter _PublishedWebsites\MyWebApp\bin\IBM.Data.DB2.dll in the Binaries folder.
I tried to address my issue again after some time and now it works. Here is the solution. I put it in a file called projectname.wpp.targets alongside the project definition file projectname.csproj.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFiles Include="bin\IBM.Data.DB2.dll">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
</Project>

deploying javafx 1.3 application with swing.filechooser

I have a Java application and I integrated JavaFX 1.3 on it. I have spent more than three days trying to deploy it as a Web Start Application and it is impossible.
I have a jar running with the console (javafx -jar MatchTestCaseGenerator-2.0-jar-with-dependencies.jar) but when I try to execute the jnlp I have the following error:
java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
at java.lang.System.getProperty(System.java:667)
at sun.awt.shell.ShellFolderManager.get(ShellFolderManager.java:57)
at sun.awt.shell.ShellFolder.get(ShellFolder.java:227)
at javax.swing.filechooser.FileSystemView.getDefaultDirectory(FileSystemView.java:404)
at javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:552)
at javax.swing.JFileChooser.<init>(JFileChooser.java:334)
at javax.swing.JFileChooser.<init>(JFileChooser.java:286) ...
I have the jar file signed and verified and my JNLP file is like that:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="file:/Users/ana/Projects/Java/workspace/Match Test Case Generator 2.0/target" href="MatchTestCaseGenerator.jnlp">
<information>
<title>Match Test Case Generator</title>
<vendor>KV </vendor>
<homepage href=""/>
<description>some_description</description>
<offline-allowed/>
<shortcut>
<desktop/>
</shortcut>
</information>
<resources>
<j2se version="1.6+"/>
<extension name="JavaFX Runtime" href="http://dl.javafx.com/1.3/javafx-rt.jnlp"/>
<jar href="MatchTestCaseGenerator-2.0-jar-with-dependencies.jar" main="true"/>
</resources>
<application-desc main-class="com.sun.javafx.runtime.main.Main" progress-class="com.javafx.progressbar.ProgressManager">
<argument>MainJavaFXScript=com.knowledgevalues.mtcg.javafx.MainFx</argument>
</application-desc>
</jnlp>
Am I missing something? should I introduces a policy file in the jar?? I'm totally lost
Thank you very much in advance for any help.
Try to add next section to your jnlp file:
<security>
<all-permissions/>
</security>
The final solution was to remove all the folders that included javafx classes except the Main class.
With that, it worked without problems!!

Building a ASP.NET solution from command-line?

How can I build an ASP.NET web application from the command line?
Try this in a .bat file, replace v4.0.30319 with the appropriate version:
CD C:\Windows\Microsoft.NET\Framework\v4.0.30319
msbuild "C:\inetpub\wwwroot\MyWebSite.sln"
Take a look at the devenv.exe /Build switch, you give it a solution file to build, e.g.
devenv.exe "C:\Documents and Settings\someuser\MySolution.sln" /build DEBUG
If you have more complex build requirements then look into MSBuild.
This is a round about way to do it, but you can use the MSBuild task as part of an msbuild project:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Solutions Include="*.sln" />
</ItemGroup>
<Target Name="Build" >
<MSBuild BuildInParallel="true" Projects="#(Solutions)" RebaseOutputs="true" />
</Target>
built with msbuildprojectname.proj from the command line.
This may seem like overkill, but you can then add extra stuff into the project (like restarting websites, zipping files, Virtual machine control even!, code coverage) that can help you setup and test the project.
As dumb as I might look, I have used "aspnet_compiler.exe" for compiling/deploying projects
http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/2ca80dfd-b7d7-4e09-98ff-891b1570f4db
To build a solution directly,
msbuild mysolution.sln
You'll find MSBuild in the Microsoft.NET folder in your Windows directory.
You may also want to pre-compile your Web site. Instructions for that are on MSDN here. If you use the Web Deployment project node (detailed at the bottom) then the deployment will happen automatically when you run msbuild on the solution file.

Resources