My jar is not running, I can tell it tries to run as the log4j file manage to create the log folder but then nothing happens and the log is in blank.
My problem is I have the jar file in a folder called bin and the libraries in a folder called lib
I'm triying this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${staging.dir}/bin</outputDirectory>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>com.Main</mainClass>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
and
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${staging.dir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I also tried with maven-assembly-plugin, but it packs everything on the jar and I really need to have the folders bin and lib
What do I need to setup to make it work correctly?
EDIT: META-INF file
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: me
Build-Jdk: 1.6.0_26
Main-Class: com.Main
Class-Path: ../lib/ojdbc6-11.2.0.jar ../lib/sqljdbc4-4.2.0.jar ../lib/
mysql-connector-java-5.1.17.jar ../lib/hibernate-core-3.6.5.Final.jar
../lib/antlr-2.7.6.jar ../lib/commons-collections-3.1.jar ../lib/dom
4j-1.6.1.jar ../lib/hibernate-commons-annotations-3.2.0.Final.jar ../
lib/hibernate-jpa-2.0-api-1.0.0.Final.jar ../lib/jta-1.1.jar ../lib/s
lf4j-api-1.6.1.jar ../lib/hibernate-entitymanager-3.6.5.Final.jar ../
lib/cglib-2.2.jar ../lib/asm-3.1.jar ../lib/javassist-3.12.0.GA.jar .
./lib/slf4j-log4j12-1.6.1.jar ../lib/log4j-1.2.16.jar ../lib/commons-
codec-1.5.jar ../lib/lablib-checkboxtree-3.3-20110114.141734-3.jar
SOLUTION
turns out the META-INF file is incorrect. The reason is that maven-archiver-plugin renames SNAPSHOT libraries with a timestamp as default behaviour
to override that use this, as instructed by the Maven Archiver doc:
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>com.Main</mainClass>
<classpathPrefix>../lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
other than that, I hope people find useful the maven code at the start because it does work, just beware the SNAPSHOTS in your projects
The above all seems OK. Here are some things/questions you may want to try/confirm/answer:
Are you running this from command line? I.e. using java -jar <your.jar> or are you starting it e.g. by double-clicking the file, etc.? If not, try running it from the command line to see what happens
Try using mvn exec:java to see if that starts your app (maven-)regularly. See http://mojo.codehaus.org/exec-maven-plugin/usage.html if you are not familiar with exec plugin
Can you use regular Java System.out.println instead of logging to confirm that it actually starts? Having a zero-size log might be a logging configuration issue
I see you have some DB libraries above. Can you put some println (or better logging, but only after you confirm your logging actually works) statements around basic initialization, to confirm that you are not just stalling there (provided that's what's happening - you don't mention any exceptions or other issues in specific)
A lot depends on the actual application code, but hope some of the above might help you pinpoint the issue.
As a side note, is your main class really com.Main? If yes, may I suggest to change that to something more appropriate - e.g. com.yourdomain.yourapp.Main or something along these lines. Not that this will change the above result, just a stylistic comment.
Related
Basically, I want to generate a jar file named <project.name>.jar in addition to default jar file(which in my case is something like <project.name> + <project.version>.jar). NOTICE : This <project.name>.jar is all the same to default jar but the name.
And this additional jar should have a manifest file like below which is the manifest file of default generated jar
anifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: XXX
Start-Class: com.XXXX.XXX.Application
Spring-Boot-Version: 1.3.1.RELEASE
Created-By: Apache Maven
Build-Jdk: 1.8.0_74
Main-Class: org.springframework.boot.loader.JarLauncher
I am adding additional block in my as follows
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
....
<execution>
<id>copy-jar</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<finalName>${project.name}</finalName>
</configuration>
</execution>
<execution>
</plugin>
But in my case, the manifest file generated in my addition jar don't have following impart fields:
Start-Class
Main-Class
...
So it couldn't be deployed.
I know the requirement sounds weird, but the question is clear, how to make maven generate a jar which having a correct and complete manifest file for deployment?
//The complete plugin part
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals><goal>test-jar</goal></goals>
</execution>
<execution>
<id>copy-jar</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<finalName>${project.artifactId}</finalName>
</configuration>
</execution>
<execution>
<id>dto-jar</id>
<goals><goal>jar</goal></goals>
<phase>package</phase>
<configuration>
<finalName>${project.artifactId}-dto</finalName>
<includes>
<include>**/dto/*</include>
<include>**/dto</include>
<include>**/exceptions/*</include>
<include>**/exceptions</include>
<include>**/utils/*</include>
<include>**/utils</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Concerning your maven-jar-plugin section:
You are having three executions: one for the test-jar goal, two for the jar goal
one of them re-using the default execution id (default-jar) to specify the finalName entry, but not specifying any manifest configuration. According to this configuration, your manifest file should also be empty then, not coherent with the description provided by your question then.
the additional jar goal execution has a further configuration with customizated option, nothing wrong here, except that you except to have a properly filled manifest file as part of it, while (again) there is no configuration for it.
A possible explanation would be that your pom also provides a pluginManagement section, with further configuration for the maven-jar-plugin, or a parent pom at its top which would then specify a further configuration for the same.
To double check this, you could run
mvn help:effective-pom -Doutput=eff-pom.xml
And check the content of the generated eff-pom.xml file. That would be the single source of truth for your case.
Looking at your manifest entry:
Spring-Boot-Version: 1.3.1.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
It makes quite clear that you are working on a Spring Boot project, normally having a Spring Boot parent pom which already configures the required manifest file. However, it makes use of a fat-jar (jar with dependencies or uber jar), not built via the maven-jar-plugin but via the maven-assembly-plugin.
As an example:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
</manifest>
<manifestEntries>
<Start-Class>org.springframework.boot.load.it.jar.EmbeddedJarStarter</Start-Class>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Hence you should not look at the Jar Plugin solution, but rather add a further Assembly Plugin execution for the same.
Just quick share of some other aspects of this problem. actually pom file should never be in charge of deployment business(even though It could, but very likely bring into more issues in the future). This part should be fully managed by bamboo deploy script. That is what I eventually did.
A mavenized version of an old project of mine creates two Jar files, one for command line and one for GUI use. As it currently stands, it deploys only the primary artifact to the local repository. The jars are created by having two executions for maven-jar-plugin, and both get created in the target directory. What happens is the GUI file overwrites the primary one, with the wrong name:
[INFO] Installing /Users/gmcgath/DevProjects/git/jhove/target/jhove-GUI-1.12.0-SNAPSHOT.jar to /Users/gmcgath/.m2/repository/edu/harvard/hul/ois/jhove/1.12.0-SNAPSHOT/jhove-1.12.0-SNAPSHOT.jar
I'm trying to use the build-helper plugin to get the GUI jar deployed to the repository, using the following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.artifactId}-GUI-${project.version}</file>
<type>jar</type>
<classifier>gui</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Maven runs to completion without any errors, but doesn't copy the jar properly. The log tells me it's trying to copy the GUI jar from the project-level directory instead of the target to the correct destination. The GUI file is still overwriting the primary jar.
[INFO] Installing /Users/gmcgath/DevProjects/git/jhove/jhove-GUI-1.12.0-SNAPSHOT to /Users/gmcgath/.m2/repository/edu/harvard/hul/ois/jhove/1.12.0-SNAPSHOT/jhove-1.12.0-SNAPSHOT-gui.jar
(The "harvard" part is historical. Keeping this open-source project was part of my severance package. :)
So I'm doing something basically wrong. How can I fix this? Should I be using the assembly plugin instead, even though it looks more complicated?
Update: Partially fixed. The file element in the artifact needs to be
<file>${project.build.directory}/${project.artifactId}-GUI-${project.version}.jar</file>
I'm still looking for the fix to get the primary artifact copied correctly.
OK, here's my fix. The first part, as indicated above, was to get the directory and extension right in the build-helper artifact. It should have been
<file>${project.build.directory}/${project.artifactId}-GUI-${project.version}.jar</file>
The other issue was in a part of the pom.xml that I didn't post. The two executions lacked a classifier element, and so looked like this:
<executions>
<execution>
<!-- console app - don't change id, will cause build problems -->
<id>default-jar</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<classifier>cmd</classifier>
<archive>
<manifest>
<mainClass>Jhove</mainClass>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>gui-app-jar</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<classifier>gui</classifier>
<archive>
<manifest>
<mainClass>JhoveView</mainClass>
</manifest>
</archive>
<finalName>${project.artifactId}-GUI-${project.version}</finalName>
</configuration>
</execution>
</executions>
Everything looks OK now.
Team,
Our project makes use of EJB, was 6.1 is our server, While deploying the code , am in need of stub files to be present in EAR (Maven Generated). Inorder to achieve this, am using was6 plug in our pom.xml
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>was6-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>ejbdeploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
For this we need to set the environment variables "WAS_HOME".
But we cannot set the wasHome in continuum build server and hence we are getting BUILD ERROR - "wasHome not defined"
Is that any other way to achieve this?
- Creating the stub files for all ejb class without using WAS 6 maven plugin in Maven.
WAS6_HOME environment variable is the default value used by was6-maven-plugin to know where Websphere is located,
but people often use the wasHome attribute to indicate this.
From here it's possible to use Maven properties in the pom or in the settings file and Maven profiles.
On the other hand, you can generate the EJB Stubs without the maven plugin, but you will always need to know where websphere is installed.
Regards
Inorder to achieve this we can set the parameter(ejbdeploy = true) in was6 server install configuration xml
and its worked.
Thanks for all the responses.
I have a multimodule Maven project with several dependencies. I want to build a fat executable JAR containing them as well as my own compiled classes. I found maven-assembly-plugin to be just what I needed except one nasty problem.
Some of my dependencies are local and distributed with project sources. I use system scope for them. It looks something like this:
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/forms_rt.jar</systemPath>
</dependency>
The problem is that for some reason these libraries aren't unpacked and bundled with the rest of dependencies in result JAR.
I know that usage of system scope is considered bad practice, and in fact I even can find some of them (though quite outdated) in Maven repositories, but anyway it puzzles me how it can be solved with maven-assembly-plugin.
Just in case my plugin configuration looks like this:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>repoll.server.Repoll</mainClass>
</manifest>
</archive>
<finalName>${project.build.finalName}-full</finalName>
<appendAssemblyId>false</appendAssemblyId>
<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>
As I understood I have to write custom descriptor, which e.g. includes and unpacks all JARs from ${project.basedir}/lib directory, but after several unsuccessful attempts I still don't know how to do so.
I've managed to find solution here. It's described in this question.
In short, the whole problem was in usage of system scope. It turned out, that such dependencies are filtered out by default, which I found out by running mvn package with debug output enabled (-X/--debug).
When local repository is defined for these JARs, distributed with project, they are unpacked by maven-assembly-plugin as exepected.
Sometimes, my Talend Open Studio components have resources but not Java sources (they are purely metadata components). I need to disable the generation of JAR files in such a case.
I configured the maven-jar-plugin this way:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<forceCreation>false</forceCreation>
<skipIfEmpty>true</skipIfEmpty>
<useDefaultManifestFile>false</useDefaultManifestFile>
</configuration>
</plugin>
but I still get the ${project.name}.jar file with pom.properties, pom.cml, the manifest and an empty file App.class containing only "class {}"
While I can disable the includes of all maven stuff using this:
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
I still get a JAR with the manifest file inside it
Are there some configuration parameters I misconfigured?
Most efficient way to disable the creation of jars is to configure the maven-jar-plugin like this:
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
It will place the default jar creation in the none phase, it will never be run.
I found the solution by myself, even if it's only a workaround. I delete the JAR using a delete antrun task if /src/main/java directory doesn't exist:
<!-- remove the empty JAR if not needed -->
<if>
<not><available file="${basedir}/src/main/java" type="dir" /></not>
<then>
<delete file="${project.build.directory}/${project.name}-${project.version}.jar"/>
</then>
</if>
this task requires antcontrib to work properly and, ofc, it doesn't work if you plan to do releases with maven (but it's ok for metadata-only components, like Talend Open Studio plugins)
You can instruct maven-jar-plugin to not generate META-INF/maven/*/pom. files, as explained in Maven Archiver Reference.
Also, you can use its skipIfEmpty option.
Following code combines both these (just to have them copy-paste ready):
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
...
This works fine, but when you do mvn install, it fails due to missing project artifact.
Similar problem will probably be with mvn deploy and with release, but I didn't check these.
However, if you can live with antrun's delete, the property skipIfEmpty will probably work well for you, and is a bit more elegant. At least it does not introduce a new execution and its dependencies etc.