Maven rpm plugin tries to run installation script on build - java

I am trying to create an RPM package to install a piece of software however whenever I try to build it using the rpm plugin it will run the install script while building which will fail since my machine is not the intended target (nor should it be)
The setup is this
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.2</version>
<extensions>true</extensions>
<configuration>
<group>Applications/Software</group>
<mappings>
<mapping>
<directory>/tmp/${project.artifactId}</directory>
<filemode>755</filemode>
<username>user</username>
<groupname>group</groupname>
<sources>
<source>
<location>src/main/resources/</location>
</source>
</sources>
</mapping>
</mappings>
<requires>
<require>unzip</require>
</requires>
<preinstallScriptlet>
<scriptFile>src/main/scripts/preinstall.sh</scriptFile>
<fileEncoding>utf-8</fileEncoding>
</preinstallScriptlet>
<installScriptlet>
<scriptFile>src/main/scripts/install.sh</scriptFile>
<fileEncoding>utf-8</fileEncoding>
</installScriptlet>
</configuration>
</plugin>
I have also configured the pom packaging to be rpm and I am running "mvn clean package" to generate the rpm.
This is just a builder project meaning that all it is meant to do is to package all files within src/main/resources in the rpm together with scriptlets which will execute when that rpm is run on some target machine.
Am I missing something?
I am building the rpm on an Ubuntu 14.04 machine with rpmbuild installed

I just read the RPM documentation and found out that this is totally correct. The install scriptlet is called when the RPM is build, what you probably need is a preinstall or postinstall scriptlet. The installation itself (copying the files) is done by RPM.
Reference: http://www.rpm.org/max-rpm/s1-rpm-inside-scripts.html

Related

Apache Felix 6.0.1: BundleException on init

With Apache Felix 6.0.1 I'm getting the following error when initializing the OSGi framework:
ERROR: Error parsing system bundle statement.
org.osgi.framework.BundleException: Exported package names cannot be zero length.
at org.apache.felix.framework.util.manifestparser.ManifestParser.normalizeExportClauses(ManifestParser.java:865)
at org.apache.felix.framework.util.manifestparser.ManifestParser.<init>(ManifestParser.java:217)
at org.apache.felix.framework.ExtensionManager$ExtensionManagerRevision.update(ExtensionManager.java:977)
at org.apache.felix.framework.ExtensionManager$ExtensionManagerRevision.access$000(ExtensionManager.java:885)
at org.apache.felix.framework.ExtensionManager.updateRevision(ExtensionManager.java:378)
at org.apache.felix.framework.Felix.init(Felix.java:744)
at org.apache.felix.framework.Felix.init(Felix.java:637)
I didn't get this error with Apache Felix 5.x
And I couldn't find any JAR which has an empty package names declaration except my executable JAR, which is not an OSGi bundle at all.
Why do I get this error?
Update
The issue seems to be with the bundle goal of the Maven Bundle Plugin v4.1.0
In one startup JAR with bundle packaging I have:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<versions>
<module.b.osgi.version.clean>${project.version}</module.b.osgi.version.clean>
</versions>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>cleanVersions</goal>
</goals>
</execution>
</executions>
</plugin>
In a properties file with resource filtering set to true I have:
org.osgi.framework.system.packages.extra=${module-b.packages}
module-b.packages=${module-a.packages}, \
org.mymodule.b;version="${module.b.osgi.version.clean}", \
${foo-${foo.specification.version}}
In the generated target/classes directory I have as expected:
org.osgi.framework.system.packages.extra=${module-b.packages}
module-b.packages=${module-a.packages}, \
org.mymodule.b;version="0.14.0.SNAPSHOT", \
${foo-${foo.specification.version}}
But in the JAR it then suddenly looks like this:
org.osgi.framework.system.packages.extra=${module-b.packages}
module-b.packages=${module-a.packages}, \
org.mymodule.b;version="0.14.0.SNAPSHOT", \
Somehow ${foo-${foo.specification.version}} got stripped to empty string!
Update 2
As this happens in the startup code, my current work-around is to change the packaging type back to jar. The OSGi clean version still gets substituted, but the Manifest file doesn't contain any OSGi entries anymore.
I think it is a regression bug in the Maven Bundle Plugin.
I've filed an issue here: https://issues.apache.org/jira/browse/FELIX-5980

UI code goes missing when deploying to Heroku

I have a Spring-MVC app that uses AngularJS for the front-end and Java in the backend. The java code is in src/main/java and the UI code is in src/main/resources/static. I'm building a fat jar using Maven.
Running locally = everything works.
I can also run the jar from the command line and everything works.
When I deploy to Heroku, the app returns a 404 on / ... it seems like it can't find the UI code anywhere.
I have an identical app with a different (less fancy) AngularJS UI, and it deploys to Heroku without any issues. The only real difference is the UI code exists at the parent src/main/resources/static while my custom app uses gulp - and gulp builds the ui code src/main/resources/static/dist. My Maven POM moves that /dist to target/classes/static when I run the package job, and that's working fine... After mvn clean package I can run my app through IntelliJ or at the command line using java -jar target/blah.jar. But when I push it to Heroku I get an application error, and the Heroku log cites a 404 on path="/".
Note my starting point for these projects was the Stormpath examples for spring-boot-web-angular. The stock example deploys fine with same Procfile, so the only difference is the /dist that my custom UI code has - but Maven should be taking care of that.
My Procfile contains:
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/*.jar
Pom excerpt that copies the UI code to the right spot in target/:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/static/dist</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I've been googling for days and reached out to Heroku support, but they said they can't help.
I can't tell if the Maven piece isn't getting picked up when I git push heroku master (after packing locally), or if I'm missing a config option or something in my Procfile.
Would very much appreciate a pointer in the right direction.

tell grails maven plugin to use servlet 2.5 instead of 3.0

I might have a stupid and really obvious question:
I basically have a grails 2.3.8 project, build using maven 3.2, with the grails maven plugin 2.4.3
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<!-- Whether for Fork a JVM to run Grails commands -->
<fork>true</fork>
<grailsVersion>${grails.version}</grailsVersion>
</configuration>
<extensions>true</extensions>
</plugin>
when I do a
mvn clean install
I keep getting the following exception:
java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
at java.lang.Class.privateGetDeclaredMethods(Class.java:2484)
at java.lang.Class.getDeclaredMethods(Class.java:1827)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
my BuildConfig specifies grails to utilize, servlet 2.5
grails.servlet.version = "2.5"
and all my test's are working fine, if I run them from grails directly using:
grails test-app :integration
but fail with the given exception, if I run them from the command line
mvn clean install
my dependency report lists the correct servlet version:
javax.servlet:servlet-api:jar:2.5:provided
anybody has an idea how to solve this?
thanks

Reloading JSPs edited in Eclipse, run with tomcat7-maven-plugin

How can I get a Tomcat instance started with tomcat7-maven-plugin on the command line to reload JSPs when I edit and save them in Eclipse? It's of note that I don't want to start Tomcat via Eclipse, as I depend on some Maven plugin executions that m2e doesn't know how to map.
I start Tomcat thusly, on the command line:
mvn clean package -U tomcat7:run-war-only
Here is the configuration of the Tomcat plugin:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<systemProperties>
<spring.profiles.active>local</spring.profiles.active>
</systemProperties>
<path>/</path>
<port>8080</port>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
When I change and save a JSP in the source of the project, it'd be lovely if Tomcat could reload that without having to go through a full clean/compile/test/package/start cycle.
This can be done by adding a tomcat server plugin to your eclipse and then deploying your war in tomcat through eclipse and not from command line.
If you do that, when you make any changes in JSP or Java, eclipse auto refreshes your war with out you manually triggering it.
Try
mvn clean package -U tomcat7:run
As run-war-only run a packaged war so won't see your code changes.
if you want debug in your ide use
mvnDebug clean package -U tomcat7:run
Then attach a debugger to port 8000
HTH

How to control VM arguments for maven-jetty-plugin?

How to set VM arguments for Jetty run from maven-jetty-plugin?
For example, I need to pass -Xmx arguments to Jetty run by the mvn jetty:run command.
The enviroment variable MAVEN_OPTS is the answer. The string content of MAVEN_OPTS is passed to JVM (java.exe).
Linux: in shell type export MAVEN_OPTS=....
Windows: in shell (cmd.exe) type set MAVEN_OPTS=...
For example: on Windows set MAVEN_OPTS="-Xmx1024m" sets the heap size of the Maven process to 1024mb.
Update (01.04.2013): Pass it directly to Jetty.
Matthew Farwell (please upvote his answer to give him credit) comes with the solution of using a forked JVM process to run Jetty which is a new feature of the Jetty plugin. This is a better solution as the former runs inside same JVM process as Maven (thus shares memory).
With more recent versions of the maven-jetty-plugin, you can use mvn:run-forked. The option jvmArgs will allow you to set -Xmx etc.
For more information, see: jetty:run-forked : Running an unassembled webapp in a separate jvm.
I think the original issue was Starting Jetty in separate JVM.
It seems like your current approach is correct - when running jetty through maven, jetty is a thread inside the maven process. So increasing maven's heap will increase jetty's heap.
How are you setting MAVEN_OPTS?
One example I found looks like this: MAVEN_OPTS='-Xmx256m -Xms10m' mvn clean jetty:run
Note that MAVEN_OPTS is an environment variable here, and not passed to the JVM (who wouldn't know what to do with it).
To specify vm arguments via the command line (as originally asked) you can do the following:
mvn clean install -DargLine="-Xmx1524m"
The <jvmArgs> param mentioned here : Maven jetty plugin
didn't work for me .
Maven version : Apache Maven 3.0.3
Jetty Maven plugin version : jetty-maven-plugin:8.1.10.v20130312
This worked :
MAVEN_OPTS='-Xmx4096m -Xms4096m'
export MAVEN_OPTS
mvn jetty:run &
On Linux/Unix
export MAVEN_OPTS="-Xmx256m" && mvn clean install jetty:run
will do the trick
The plugin allows you to specify jvmArgs like this:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<jvmArgs>-Xmx1024</jvmArgs>
<scanIntervalSeconds>10</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webAppConfig>
<jettyEnvXml>jetty-env.xml</jettyEnvXml>
</webAppConfig>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run-exploded</goal>
</goals>
</execution>
</executions>
</plugin>
As referenced in Configuring Apache Maven, discussing the MAVEN_OPTS environment variable referenced in other answers, you can also control project configuration with files in the .mvn directory.
For VM arguments in particular, you can add a .mvn/jvm.config file containing the associated parameters:
Starting with Maven 3.3.1+ you can define JVM configuration via ${maven.projectBasedir}/.mvn/jvm.config file which means you can define the options for your build on a per project base. This file will become part of your project and will be checked in along with your project. So no need anymore for MAVEN_OPTS, .mavenrc files.
you can use to pass -Xmx argument like;
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version></version>
<configuration>
<jvmArgs>-Xmx -Xms -XX:PermSize= -XX:MaxPermSize= -XX:+HeapDumpOnOutOfMemoryError</jvmArgs>
<scanIntervalSeconds>1</scanIntervalSeconds>
<stopKey>stop-jetty</stopKey>
<stopPort>9999</stopPort>
<systemProperties>
<systemProperty>
<name>jetty.port</name>
<value>9090</value>
</systemProperty>
<systemProperty>
<name>spring.profiles.active</name>
<value></value>
</systemProperty>
</systemProperties>
<webApp>
<contextPath>/</contextPath>
</webApp>
</configuration>
</plugin>
There is no way using the commandline. But you could copy the mvn.cmd / mvn.sh to mvnhp.cmd and change the line
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
To
%MAVEN_JAVA_EXE% -Xmx1024m %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%

Categories

Resources