quarkus-maven-plugin does not add implementation-entries to MANIFEST - java

I want to read the current artifact version of my maven-project inside my of a RESTful service. My code is written in JAX-RS (Quarkus).
I am using a the following pom.xml snippet:
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
I read the version with the following java snippet:
String vendor = getClass().getPackage().getImplementationVendor();
It seems to me that the quarkus-maven-plugin is ignoring that line since maven-jar-plugin is working perfectly fine (I used this in a different project):
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
I do not have a really profound knowledge of maven and quarkus yet.
Am I making a mistake setting up the quarkus-maven-plugin?
Is there a workaround which does not include reading directly from the pom.xml?
Thank you for helping me.
EDIT:
I will mark this thread as "answered" as soon as the following issue
is resolved (opend by #Guillaume Smet):
https://github.com/quarkusio/quarkus/issues/5023
EDIT:
Issue is resolved as of today.
https://github.com/quarkusio/quarkus/issues/5100

Adding addDefaultImplementationEntries won't help, we build the jar ourselves and we don't push any of this information to it.
I created https://github.com/quarkusio/quarkus/issues/5023 for this.
For the time being, you can either push the information to the manifest yourselves (we enhance it if you have an existing one) or inject the values we derive from the POM files in your REST resources with:
#ConfigProperty(name = "quarkus.application.name")
String name;
#ConfigProperty(name = "quarkus.application.version")
String version;

Related

PDFBox with Maven - java.lang.NoClassDefFoundError

When installing PDFBox with Maven, it places the libraries in the ~/.m2/repository directory.
My program complies fine with mvn package.
When I try to run it with
java -cp target/java-project-1.0-SNAPSHOT.jar com.example.sub.App
then I get
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDocument
Should I also be specifying the libraries in ~/.m2/repository as part of the classpath? This seems a bit too tedious to do it this way. What is the recommended way to specify the classpath of my PDFBox library while using the library location(s) of Maven?
I wasn't able to find a nice solution with leaving the JAR files in ~/.m2, so the answer below is a workaround based on some other answers. I will be including more clarification though for those who are new to both PDFBox and maven as I am.
1) Add the following to your pom.xml file. If you already have a <build> and <plugins> section, just add the <plugin> section below to that. Otherwise you may need to add the whole code below within the <project> element:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>**REPLACE THIS WITH THE FULL URI OF YOUR MAIN CLASS**</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2) Make sure that you replace the text in the <mainClass> element to match the situation. For example, if your main() method is located in an App class in App.js, and your package name is com.example.sub. Then the above element should read:
<mainClass>com.example.sub.App</mainClass>
3) To compile your app, run mvn package
Note: I have seen some references online using mvn clean compile assembly:single instead of mvn package. I am not sure what the purpose of this is when mvn package seems to run just fine for me.
This will take your project and all of your dependencies and create a single JAR file in the target directory called something like this:
java-project-1.0-SNAPSHOT-jar-with-dependencies.jar
4) To run the project you can do this:
java -cp target/java-project-1.0-SNAPSHOT-jar-with-dependencies.jar com.example.sub.App
Make sure that you modify the above line to it your situation. In other words you may need to change both the name of the jar file and the name of the URI for your main class.

Maven: Could not find or load main class

I have the following configuration for my maven build and I have double checked the class name as well as package name multiple times to ensure it's accuracy. But everytime I run:
java -jar <snapshot-with-dependencies>.jar I get Error: Could not find or load main class com.atlassian.JiraRestCaller.
The excerpt from my pom file is as below
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.atlassian.JiraRestCaller</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I also tried adding <sourceDirectory>src/main/java/com/atlassian/</sourceDirectory> but still get the same error
Solution1:
I spent a decent amount of time trying to solve this problem. I thought that I was somehow setting my classpath incorrectly but the problem was that I typed:
java -cp C:/java/MyClasses C:/java/MyClasses/utilities/myapp/Cool
instead of:
java -cp C:/java/MyClasses utilities/myapp/Cool
I thought the meaning of fully qualified meant to include the full path name instead of the full package name.
Solution2:
If you use Maven to build the JAR file, please make sure to specify the main class in the pom.xml file:
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>class name us.com.test.abc.MyMainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
This might help you if your case is specifically like mine: as a beginner I also ran into this problem when I tried to run a Java program.
I compiled it like this:
javac HelloWorld.java
And I tried to run also with the same extension:
java Helloworld.java
When I removed the .java and rewrote the command like java HelloWorld, the program ran perfectly. :)
So we had this today
[myproject]-[master] $ mvn
[MVNVM] Using maven: 3.5.2
Error: Could not find or load main class html
and we had an issue with Proxies.
Check your MAVEN_OPTS and make sure that if you are sending in a proxy to maven, that it exists and you can use it.
MAVEN_OPTS=-Dhttp.proxyHost=www-proxy.myproxyprovider.com -Dhttp.proxyPort=80 -Dhttps.proxyHost=www-proxy.myproxyprovider.com -Dhttps.proxyPort=80
or if it is set and you shouldnt have one, then get rid of it.
[myproject]-[master] $ mvn -version
[MVNVM] Using maven: 3.5.2
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T08:58:13+01:00)
Maven home: /Users/bamcgill/.mvnvm/apache-maven-3.5.2
I experienced the same error. I fixed it by upgrading from Maven 3.3.3 to Maven 3.6.3. I am not sure whether that fix is related to this question, because I did not debug my issue.

How can i get STS to resolve thy path to the web.xml i defined in a maven profile?

I have a maven project that has different environments for development and production. There are some parts in the web.xml that need to be removed for production. Until today, there was a antrunner based xml task that did exactly that. Now i want to remove the scripting-part and introduce 2 versions of the web.xml. Basically, i would extend the path "WEB-INF/web.xml" to "WEB-INF/dev/web.xml". This was configured in both profiles:
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<webxml.path>${project.basedir}/src/main/webapp/WEB-INF/dev/WEB.xml</webxml.path>
</properties>
</profile>
Same for the other profile, just with a different path.
Later, I will use the maven-war-plugin to make sure maven finds the file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
<webXml>${webxml.path}</webXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
And everything works fine, but just as long as I build from the commandline.
I told the Spring Tool Suite 3.7 to update with the dev profile,sadly it somehow refuses to resolve that path.
When I use the "create Descriptor-Stub" from the context menu, it even creates a file called ${webxml.path} with default web.xml content.
The provided error message is:
web.xml is missing and failOnMissingWebXml is set to true
I dont want to disable that check (failOnMissingWebXml) if possible.
Is there any way to get STS to be a bit more eager on resolving variables?
Update:
While writing this, I found out, that it is possible to use the maven-resources plugin to copy the file manually to the respective path when building from the IDE. It would be great to get m2e to respect the attribute from the war-plugin. Or is this simply not possible? Is the buildprocess not executed by maven itself, even though i explicitly specified the external version?

WAR bundles SNAPSHOT JARs with timestamps

I have this multi module project setup which uses Webstart and I need to bundle the WAR with SNAPSHOT JARs. When the JARs are bundled into the WAR, they are appended with a timestamp instead of the actual name. This is causing issues during their download.
Expected - ABC-1.0-SNAPSHOT.jar
Actual - ABC-1.0-20141002.211448-2.jar
Env:
OS: Unix
Maven: 3.2.1
JDK: 1.7
I have already tried useUniqueVersions=false by defining a maven-war-plugin and setting this in the manifest configuration.
My webstart config:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<version>1.0-beta-6</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>jnlp-download-servlet</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectoryName>.</outputDirectoryName>
<excludeTransitive>true</excludeTransitive>
<commonJarResources>
<jarResource>
...
</jarResource>
</commonJarResources>
<jnlpFiles>
<jnlpFile>
<templateFilename>JNLP-INF/APPLICATION_TEMPLATE.JNLP</templateFilename>
<outputFilename>client.jnlp</outputFilename>
<jarResources>
<jarResource>
...
</jarResource>
</jarResources>
</jnlpFile>
</jnlpFiles>
<sign>
...
</sign>
<outputJarVersions>false</outputJarVersions>
</configuration>
Appreciate any inputs.
UPDATE
Adding details about the WAR plugin I added
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
The behavior continues. I read that maven 3 uses a unique snapshot system. But I am trying to work my way around it.
Also tried the following without any luck
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
</configuration>
</plugin>
The creators of the maven-webstart-plugin have accidentally inverted the meaning of the flag useUniqueVersions. When set to true it produces jars of the form -SNAPSHOT.jar and when set to false (the default) it produces jars of the form --.jar
I found that setting the useUniqueVersions flag to true in the maven pom configuration produced my desired results.
I needed it like this because when deployed with the datestamp version of the snapshots when trying to launch it I was getting a "Resource not found" error when it tried to get the snapshot jar it was trying to launch. Presumably this means that the servlet code itself is not set up to handle the different naming on disk, despite the fact that the specific datestamp version number does end up in the jnlp itself.

Eclipse. Error(s) found in manifest configuration. how to fix it?

I just taken the project - I checkout this and I want to resolve all problems
one of the problems which I cannot to resolve
Error(s) found in manifest configuration (org.apache.felix:maven-bundle-plugin:2.3.7:bundle:default-bundle:package)
it refers to this row of pom.xml:
<plugin>
code around this row:
<build>
<plugins>
<plugin>
<groupId>com.squeakysand.jsp</groupId>
<artifactId>jsptld-maven-plugin</artifactId>
<configuration>
<shortName>ctc</shortName>
<processTagFiles>true</processTagFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>//this row
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>
META-INF/${project.artifactId}-${project.version}.tld=${project.build.outputDirectory}/META-INF/${project.artifactId}-${project.version}.tld,
{maven-resources}
</Include-Resource>
<Sling-Bundle-Resources>
/META-INF/tags
</Sling-Bundle-Resources>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
Please, help me resolve this problem.
Old question but for future Google results.
The issue is an old version of maven-bundle-plugin, specifically 2.3.7. Updating the pom.xml to use the latest (currently 2.5.0) fixed the issue.
Open the maven console (see the chapter "Enabling the Maven Console" here: http://www.theserverside.com/news/1363817/Introduction-to-m2eclipse).
Project right click->Maven->Update Project
You will see the real manifest problem in error messages in m2e console. Then you can fix them.
This error also occurs if the files referenced in the Include-Resource tag are not found by Eclipse. E.g. if the files are generated during the build process and Eclipse cannot execute one of the build steps (because of a missing m2e connector for instance). In this case check the build process and install required m2e connectors if available.

Categories