zip a file with maven to a NO java application directory - node.js

I donĀ“t know if this is possible . This is what I want to do.
I have some jenkins pipelines that build a VUE.js application using node js.
using the "nmp run build" command. The result of this build, is the directory name "Static" and a index.html file. After that I zip those 2 into a file.zip which I upload to Artifactory, so later it can be downloaded unziped and put it into a docker file to build an image and later a container in azure (ACI).
I want to implement some versioning now of those zips which I already done with other apps but in Java with maven + POM + Maven+Metadata+Plugin + jenkins+ artifactory where I have 2 jobs. 1 job to build with maven and push to artifactory the file.war, and other job to choose the file.war from artifactory with "build with parameters" option.
I read something about using also maven for creating a zip file even though is not a java app here and do the same for node js.
So, Is it possible with maven to zip a directory and a file even thought they are not a java app and include job number to version this zip file and pushing into artifactory?, if not, which is the best approach to do the same as I did with Java and maven for versioning, but for VUE.js applications in a jenkins pipeline that push a zip along with build number into artifactory and then using the "build with parameters" option to choose the zip I want?
thank you!

You mentioned, that you are already using npm to build your Vue app. There are libraries for npm available for zipping. You could e.g. do something like this:
const fs = require('fs');
const archiver = require('archiver');
const archive = archiver('zip', {
zlib: { level: 9 }
});
const filename = "./output.zip";
const fileOutput = fs.createWriteStream(filename);
fileOutput.on('close', function() {
console.info('ZIP file created. ' + archive.pointer() + ' total Bytes.');
});
archive.pipe(fileOutput);
archive.directory('./input-directory', '/');
archive.on('error', function(error) {
throw error;
});
archive.finalize();
This assumes, that the output of your build process is stored in a dist folder on your file system and that you have access to the filesystem.
There are more examples of archiver in the official docs: https://github.com/archiverjs/node-archiver

You may build a zip file using the maven-assembly-plugin with an assembly descriptor.
The assembly descriptor goes in the project's src/assembly directory, named something like my-zip-format.xml. You'll need to customize the content to include the files needed but this is the idea.
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>my-zip</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>path/to/input/dir</directory>
<outputDirectory>name-of-output-dir</outputDirectory>
<directoryMode>0750</directoryMode>
<fileMode>0640</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
</fileSets>
</assembly>
Then, tell the POM to use the assembly:
....
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version><pluginVersionHere></version>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/my-zip-format.xml</descriptor>
</descriptors>
</configuration>
...
Documentation goes into a lot more detail, and there are plenty of SO questions/answers about assembly plugin nuances as well.

Related

Package and install a xxx.desktop file with javapackager

I've packaged an application with Maven's JavaPackager plugin targetting Linux.
Everything is working fine except that I don't find how to package and install a "xxxx.desktop" file for my application.
Without this file, 1/ the icon on the launcher is ugly, 2/ the application cannot be found with a Search.
Here is my plugin's config:
<plugin>
<groupId>io.github.fvarrui</groupId>
<artifactId>javapackager</artifactId>
<version>1.6.7</version>
<configuration>
<mainClass>com.zparkingb.zploger.GUI.Zploger</mainClass>
<generateInstaller>false</generateInstaller>
<administratorRequired>false</administratorRequired>
</configuration>
<executions>
<execution>
<!-- With JRE -->
<id>bundling-for-platform-complete</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<platform>linux</platform>
<name>${project.bundle_finalname}${package.buildnamesuffix}</name>
<outputDirectory>${project.build.directory}/FULL</outputDirectory>
<createTarball>true</createTarball>
<createZipball>false</createZipball>
<bundleJre>true</bundleJre>
<customizedJre>false</customizedJre>
<!--From settings.xml-->
<jrePath>${package.jrePath}</jrePath>
<jdkPath>${package.jdkPath}</jdkPath>
<!--Special for Linux-->
<linuxConfig>
<pngFile>assets/linux/Zploger.png</pngFile>
<generateAppImage>true</generateAppImage>
<generateDeb>false</generateDeb>
<generateRpm>false</generateRpm>
<wrapJar>true</wrapJar>
<categories>
<category>Utility</category>
</categories>
</linuxConfig>
</configuration>
</execution>
</executions>
</plugin>
So I'd need to end up with file:
~/.local/share/applications/com-zparkingb-zploger-GUI-Zploger.desktop
with a similar content:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=Zploger for Scores
Icon=/home/vboxuser/Desktop/ZplogerScores/Zploger.png
Or even having the icon placed somewhere in ~/.local/share/icons/xxx/xxx and having the ".desktop" file refering to it as Icon=Zploger
How could I achieve this ?
My solution is probably far from being ideal, but I am limited in that I am building a Linux solution from a Windows environment.
The solution is based on the following principle:
Have the application startup script checking for the presence of the icons and the .desktop file in ~/.local/share/applications/.
If it doesn't exist, copy these from the package.
So the solution must
Adapt the default startup script in order to do that extra check
Add in the packaging the desktop file and the icons.
In the end, the solution is comprised of the following 4 steps:
Add to the project folder the icons and the desktop file. I've put these in a bundledata/linux/assets folder. The folder name is free but cannot be assets\ because this one is reserved for JavaPackager and cannot one of the Maven resources folder because I want these files to packaged separately.
Provide an adapted startup.sh.vtl velocity template which goal is to add to the startup script instructions to copy the icons and a valid desktop file.
The icons are copied to ~/.local/share/icons/hicolor/.
And I provide "./16x16", "./24x24", ... "./1024x1024". And also "./scalable" with a SVG version of the application icon.
The desktop file is named my-main-class.desktop (in my case com-zparkingb-zploger-GUI-Zploger.desktop) and is copied into ~/.local/share/applications/
Have that script modifying the xxx.desktop to push the current script path.
Adapt the pom.xml.
In the io.github.fvarrui.javapackager plugin's config, add the following instruction:
<additionalResources>
<additionalResource>bundledata/linux/assets</additionalResource>
</additionalResources>

How to hide Tomcat version from error messages when using embedded servers in Java

I have a java application where i'm using embedded Tomcat servers,
which looks like this
Tomcat tomcat = new Tomcat()
I'm creating an embedded tomcat server here.
Problem statement
whenever there's an error it displays information on which tomcat version i'm using,
how to hide this in java?
i have a little idea that i need to override ServerInfo.properties, but how do i do this?
I'm not sure how we can do this in java, but if you are using any build scripts like ant / gradle for distribution purpose, we can write a task to override / harden the jar file, and replace the ServerInfo.properties file with the customized value whatever we need.
the code for ant build scripts would look like
<target name="override.tomcat">
<jar destfile="path/to/tomcat-embed-core-9.0.62.jar" update="true">
<fileset dir="src/"> <!-- folder where you keep the directory/file to raplace-->
<include name="org/apache/catalina/util/ServerInfo.properties"/> <!-- file to replace within directory path in side the jar-->
</fileset>
</jar>
</target>
and in gradle
task overRideTomcat(type: Jar) {
from(zipTree(file("path/to/tomcat-embed-core-9.0.62.jar"))) {
exclude '**/org/apache/catalina/util/ServerInfo.properties'
}
from('src/') {
include('/org/apache/catalina/util/ServerInfo.properties')
}
archiveName "tomcat-embed-core-9.0.62.jar"
}
make sure you have the modified ServerInfo.properties file under src directory in the same path as you have mentioned in the include statement.

Error while extracting zip file created from maven assembly plugin

I'm using maven assembly plugin to create a zip packaging resources from another maven module in the same project.
Parent_project
|_module1
|_resources
|_templates
|_abc.xml
|_module2
|_resources
|_build-config.xml
Below is my build-config.xml file.
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bundle</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/../module1/src/main/resources/templates</directory>
<includes>
<include>*.xml</include>
</includes>
<outputDirectory>/testdir</outputDirectory>
</fileSet>
</fileSets>
</assembly>
I'm able to copy the resources to a sub-directory named testdir inside the zip file's root. (I can observe this by viewing the zip file without extracting it.) But if i try to extract the zip, it gives me the below error.
There was an error while extracting the sample.zip. "sample/testdir/abc.xml": Not a directory.
I'm using Ubuntu 18 with maven assembly plugin version -1.1.2
Can someone please point me the issue here?
I tried for a while and observed below. Extracting through UI option causes the error. If i were to use the unzip ./myzip.zip -d . command, the extraction success.
But i found a workaround for this as below.
Create an empty directory first.
<fileSet> <!-- Create empty directory -->
<outputDirectory>./templates</outputDirectory>
<excludes>
<exclude>**/*</exclude>
</excludes>
</fileSet>
Copy resources to the directory.
<fileSet>
<directory>${basedir}/test</directory>
<includes>
<include>*.xml</include>
</includes>
<outputDirectory>./templates</outputDirectory>
</fileSet>
This method fixes the issue while extracting the zip. Cheers!

log4j2 confguration file location when using jetty maven plugin

My application uses log4j2 and we have two of them one for production and another for development environment. I am using maven to run the application using mvn clean jetty:run. My plugin configuration in pom.xml looks like this:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20171121</version>
<configuration>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>${log4j-dev.location}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
But my app still uses the log4j2.xml present in the WEB-INF/classes directory instead of the one in the log4j-dev.location path. Any ideas?
I found the solution for this problem. In the webdefault.xml file, I had to add the following code:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2-custom.xml</param-value>
</context-param>
Hope it helps somebody who spent a whole day looking everywhere like me :)

Deploying an eclipse maven project in a remote linux server's tomcat

I'm looking a way to deploy a maven project developed using eclipse in a remote linux server's tomcat. I know you can export it as a .war file and dump it in CATALINA_HOME/webapps folder of the remote server. But for that you have to first export it to .war file and then copy the .war file in to remote server through SFTP or SCP. I'm looking for a way to do it with few clicks using eclipse or/and configuring some maven settings(in pom.xml or settings.xml). Does any one know how to do this? Any help is really appreciated.
The tool you are loooking for is called Tomcat Maven Plugin
What it basically does is it uses the API of Tomcat manager application, which you have to make sure is deployed on the Tomcat instance you are using. By default Tomcat manager should be available in the following location:
http://ip_of_your_linux_server:8080/manager/html
If it is not, please install it using the following command:
sudo apt-get install tomcat6-admin
You can configure the location of your Tomcat instance as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://www.mydomain.com:1234/mymanager</url>
</configuration>
</plugin>
and then run maven mvn tomcat:deploy goal. (Either from command line of from Eclipse using m2Eclipse plugin.)
Please refer to configuration and deployment pages of the plugin for more verbose information.
The most flexible solution with adapters for many different containers like Tomcat, Jetty, Glassfish, etc. is probably Maven Cargo plugin. You can find an extensive list of examples on their homepage, so no need to paste that here again.
To remotely deploy an application you'll need to configure the tomcat deployer app on the tomcat instance. Be warned, the configuration of admin users has undergone some subtle changes between tomcat 6 and 7.
Once this is working the Maven cargo plugin can deploy war files as follows:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>tomcat-deploy</id>
<phase>package</phase>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.uri>${tomcat.manager.url}</cargo.remote.uri>
<cargo.remote.username>${tomcat.manager.user}</cargo.remote.username>
<cargo.remote.password>${tomcat.manager.pass}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
<properties>
<context>${project.artifactId}</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Additional notes
The Cargo plugin supports several different containers, problem is the doco is difficult to interpret.
I haven't used the Maven plugin. It's very new

Resources