Maven - how to build custom file structure including the output jar - maven

I am building app with following structure (where myApp is root):
myApp\bin\myApp.jar
myApp\runMyApp.bat
So I need to 'wrap' the ouput jar in two directories and add to the outer directory myApp a script file.
How do I best set POM to do this?
Bonus question: I like the idea of making exe from bat. Currently I use a tool for that. Can something like this be achieved with Maven? Is having exe better than just bat file? (I did it mainly to insert the custom icon).

First off the AppAssembler plugin can be used to create the .bat file for your .jar. It may not support the exact layout you are after, but it should be customizable to get something rather close.
Secondly, the assembly plugin can then slurp all that up and produce a .zip file that has the layout you want and contains all the files you are after.
Other things to look into are the NSIS which can create a .exe windows installer for your application.
Tools such as launch4j can help wrap your entire application up in an .exe though I personally cannot find a nice maven way plugin for it.

I have used the assembly plugin to create custom output directories and have found it very powerful. You can specify the archive format of the output folder like zip, etc and also relative paths to files that need to be included in the zip. Dependencies for your project are included in by adding in the below into your custom assembly xml file - this will add in all the dependent jars as specified in the pom.xml
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>compile</scope>
<useTransitiveDependencies>false</useTransitiveDependencies>
</dependencySet>
</dependencySets>
Here is the link to the create your custom assembly descriptor - http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

Related

Octopack: Additional files copied in a pre-build event

I am trying to get Octopack to include some additional dll's that are not part of my Visual Studio project.
Is there a way to get Octopack to use my csproj files (as normal) and then specify just the additional files I need, rather than using the section in the nuspec. (Because then I have to maintain a list of all project files in my nuspec)
I am currently copying some shared libraries to a folder "/providers" in a pre-build event. Is there a way to extend on this to copy them somewhere that Octopack will see and package them?
You don't need to maintain a list of all your project files in your nuspec file, you can do this:
<files>
<file src="MyProject.Website\**\*.*" target="" />
</files>
This will grab everything in your project (all files and sub directories). If that's too much for you, you can take advantage of exclusion rules:
<files>
<file src="MyProject.Website\**\*.*" target="" exclude="MyProject.Website\docs\admin.txt" />
</files>
Hope that helps.
The downside of the answer of grabbing everything inside your project directory via the nuspec is that this could include files you don't want (see the answer's subsequent exclusion example).
A probably better way to do this is to ensure in your project that you have your files defined as "Copy to bin" or "Copy as content" and then build via msbuild w/Octopack using an additional command line argument of /p:OctoPackEnforceAddingFiles=true which tells OctoPack to combine the csproj and the nuspec, so you don't have to call out ALL the possible paths with a wildcard, you can only include files in your nuspec that aren't picked up from the regular build process. This is supported as of version 2.1.3 of OctoPack.
You could also use regular Nuget.exe and MSBuild by just specifying your csproj file, and if a nuspec exists with specific paths it should join them together.
See these reference links for better examples.
https://getadigital.com/no/blogg/setting-up-your-project-and-teamcity-octopack-for-front-end-builds/
https://octopus.com/docs/packaging-applications/nuget-packages/using-octopack/octopack-to-include-buildevent-files

How to package a Jar for OSX?

I know JarBundler is nolonger developed and doesn't work with 1.7 (link) and from the same site I found AppBundler which does produce proper .app files from jars.
I found here that the contents of these jar-apps are the same, so I did as the person suggested and only replaced the jar file inside Contents/Java (or Contents/Resources/Java in the old Jar Bundler), and it works. I could keep using AppBundler, but I'd prefer not needing an extra dependency/plugin for Ant.
Anyways, when I automate it with Ant - the .app doesn't open. I narrowed it down to this:
A .app produced from AppBundler
If I copy and paste it somewhere else, it launches
If I copy and paste it with Ant, it doesn't launch
I even tried things like clearing my application state cache, without luck. Again, the weird thing is if I copy the "source app" myself, the copy launches. If I copy the source app with Ant (and I'm doing nothing else) it doesn't.
Here's my Ant snippet (.app are just folders AFAIK) (dist.macapp is the name of the .app):
<copy todir="${dist.dir}" >
<fileset dir="${resources.dir}">
<include name="${dist.macapp}/**" />
</fileset>
</copy>
I guess I have two questions:
Why isn't this working (I think I provided enough what have I tried :P )
Is there a better way to do this (Java Web Start is out of the question, maybe something I'll look into later)
A .app file on Mac is just a standardized folder layout. You could always bundle it yourself with a script. Simply replacing the jar file isn't quite enough.
Make something like this
Contents/
Java/yourjar.jar
info.plist /* specific to your application! maybe make a template then find and replace strings */
MacOS/JavaApplicationStub
Copy the executable /System/Library/Frameworks/JavaVM.framework/Resources/MacOS/JavaApplicationStub into the MacOS folder (this is not app specific and could be done once).
I am not sure of the format for the info.plist specific to Java.

Creating and populating subfolders Joomla manifest XML

I've become fairly confused when I'm trying to create a subfolder and populate it with things in my plugin manifest XML.
If I want to create a subfolder and at the same time add files to it, how would that be done? Read comments in the code draft (all names are of course more distinct than used here).
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="2.5.0" group="group" method="upgrade">
<name>Handelsbanken Finans Delbetalning</name>
<!-- The following elements are optional and free of formatting conttraints -->
<creationDate>July 2013</creationDate>
<author>Emil Carlsson</author>
<authorUrl>http://valid.url</authorUrl>
<copyright>Copyright (C) 2013</copyright>
<version status="BETA">0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>Plugin description.</description>
<update> <!-- Runs on update; New in 1.6 -->
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<!-- Site Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /site/ in the package -->
<files folder="site">
<filename>plgName.xml</filename>
<filename>plgName.php</filename>
<folder>helpers</folder>
</files>
</extension>
This gives me nothing really. I can't find the folder I shouldhave been created from what I gathered from the documentation. It also doesn't specifies how I populate these folder :(. I am assuming that it is possible to more or less just package all files I want and then it will create the subfolders where I want/need them. But that it is a question of how to write the manifest file. If anyone have a good tutorial about this I would be very thankful :). I've googled until my fingers are almost at the Point of bleeding :(. I guess I could put all the files in the same folder, but I want to have some sort of structure to visualize for other developers what's part of the core of the plugin and what's not part of the plugin core.
Problem is solved. In my not installation script I linked in the files for what I thought only was used by the configuration XML (a field to configurate the plugin). In this file I had the node "files" as well, in this node I'd not linked in the helpers directory. When this was done all the subdirectories was added as well. So in short - Don't forget to link in the folder in all places where you have a files-node.

Continuous Integration with Jenkins: Binary Output need to be copied to a shared directory

Our .NET app with 8-10 projects and created a Jenkins job to build it.
We also have a batch job called in Jenkins to create the set up files for our app using INNO Setup. The issue we need to address is copy the Setup files to a shared location. Could you please suggest a better way to accomplish it.
In general, you will probably want to use a publishing plugin. There are different plugins depending on where (and how) you want to put the file. Here's a quick list to get you started:
Publish Over FTP Plugin - use if you want to send the output to an FTP location
Publish Over SSH Plugin - use if you want to use SSH to publish your artifacts.
Publish Over CIFS Plugin - use this if you are wanting to put stuff in a Windows (CIFS , SMB) share
A larger list can be found in the Artifact Uploader Plugins list.
In a .NET environment you should have a look at Nant (http://nant.sourceforge.net/).
Use a Nant script as a post-build action with a default.build like this :
<?xml version="1.0" encoding="UTF-8" ?>
<project name="MyProject" default="network-copy" basedir=".">
<target name="network-copy">
<copy file="target\setup.exe"
todir="\\server\share$\directory"></copy>
</target>
</project>

Project file with just files and no built output

How can I make a project file (VS 2008) that just has some data files in and has no built output?
I can make an empty project and add my data files to it (which get copied to the output folder
), but it produces an EmptyProject.dll after I do a build. I want just my data files in the output directory and not some empty DLL or EXE.
I want the data files to be the only thing in this project as the project will be shared in a couple of solutions.
Our application is C#. All of our normal code projects are C#.
The data files are schemas (XSD). I want these schemas to be in the output folder, but I don't want them included with an existing project. I would like a project named "Schemas" that has nothing in except the XSD files and does nothing except copy the XSD files to the output folder. I would like this in a project file so that the same schemas project can be referenced in multiple solutions.
I don't know of a way to suppress the creation of the .dll file. BUT... here's an easy workaround. In the project properties, Build Events tab, write a Post-build event command line that will delete the file. Something like:
del path\filename.dll
Expanding on Scott's answer:
Create a new project of type Empty project
In Properties->Application, change Output type to Class Library
In Properties->Build->Advanced, change Debug Info to None
In Properties->Build Events, set the Post-build event command line to del $(TargetPath)
That way, the project creates only a DLL, which gets deleted. At the same time, the "copy to output directory" settings on your data files is respected.
Possibly another way is editing the csproj file by replacing this:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
with this:
<Target Name="Build" />
<Target Name="Rebuild" />
Then builds don't create anything. It worked for me.
Same general idea should work for any xxproj file. Just replace the <Import Project...> tags with the <Target...> tags.
I'd be interested in knowing if this causes any issues or doesn't work for anyone.
What do you need a project for if you're not building it?
You can use solution folders to "store" files...
Why not just disable building this project for all configurations (use the Configuration Manager) - that way it won't build.
Great stuff. Expanding on Scott > Daniel's answer:
Safe to remove all References and Properties (AssemblyInfo.cs)
If it is a node/grunt/gulp project then you can invoke it in your Build Events > *Post-build event command line * eg: gulp build or gulp clean
Perhaps you can add removal or obj and bin output folders to your node/grunt/gulp clean scripts mitigating the need for del $(TargetPath)

Resources