My firm is trying to find a way to put some type of version file or versioning on a EAR and or WAR using Maven.
What we need is as we do the Maven Build is to take a version number out of a file and somehow put it into a EAR or WAR or have some better way..
I would like to hear form others on how you do this.
We are using Maven, Git, Bamboo and more. so if somehow Git can put a version or commit number into a file that then Maven can use it would be great
You have at least to options:
Customize the manifest entries.
The war plugin allows you to add some information into the manifest file. Some examples are on the usage page: https://maven.apache.org/plugins/maven-war-plugin/examples/war-manifest-guide.html (note: today its ${project.version} and not ${pom.version}.
The ear plugin has options to specify a manifest file or set some environment settings: https://maven.apache.org/plugins/maven-ear-plugin/examples/specifying-env-entries-for-the-generated-application-xml.html
Add the values to a property file and use filters to replace the placeholders.
Create a simple text or property file in src/main/resources, something like application.properties:
app.version=${project.version}
app.description=${project.description}
and then enable resource filtering: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html for this file.
You can also access environment variables: ${env.variable_name} and using the build number from bamboo (passed as a parameter to the build).
Plugins like the http://www.mojohaus.org/buildnumber-maven-plugin/ allow you to also add the SVN revision number or Git Sha1 Commit Hash.
If you are using the release plugin maven adds some information by its own into the maven folder of the released jar or war (inside the meta-inf folder).
Related
I am creating a maven project, in which I've two jar's for say x and y for now,which contains some helper classes for my project. I want to added these x and y jars to my project's pom.xml as dependency. As these two jar files are not available in maven repository. So I try to use these jar in my pom.xml with in repository tag.How to achieve this. I've searched in google and found one project , which is similar to my project.
when I build this it able to build application, I saw the jar file it created.But I couldn't create the same with new project. If I copy the entire pom.xml I'm able to build.What is dependency-reduced-pox.xml and how it will create. and in moven-local folder how it creates another pom.xml, which command is used to create these auto generated xml files Can any one help me to do this. Here are the screen shots of my maven project I got it .
here are other screen shot.
There are 3 ways:
A) Install your JARs to your local Maven repository and then use them in your project with provided groupId, artifactId and version: How to add local jar files to a Maven project? (this is quick & easy & pretty clean until you remove your local repository and delete your JARs accidentally).
B) Install Nexus or Artifactory (will will be then your remote Maven repository), set it up in your settings.xml, add those JARs to remove Maven repository and download them from there (this is much less error-prone, but in longer run it's worth it).
C) not recommended: Other response (btw. currently with most upvotes) from previously suggested resource: How to add local jar files to a Maven project? which contains systemPath tag. You shouldn't use it, because it will cause lots of headaches in the future (for example if you want to package your application to WAR), it's not the correct way, but it's possible.
I have a maven project and the snapshot number in the version tags change frequently. I manually make the change in the path to jar field of build>edit configurations each time. Is there anyway i can directly access this from the pom file?
I have a project where I want to add an external JAR file. The desired external JAR file has a nifty Github page with source, but no pre-compiled JAR file.
These are the steps I've completed so far:
1. I have downloaded the source in a zip. (its Twinkle from SwingFx.ch in case you're interested)
2. I have extracted the zip file to my workspace.
3. I have created a new project with the same name as the extracted folder from the zip file. (project loads the source successfully)
4. I select the export option from the File menu and selected the 'JAR file' option and clicked next.
Note: I had to add an external library to the above Twinkle project for it to build successfully (in case that makes a difference to the settings).
On the JAR File Specification page there are multiple check-box options available(see below):
Export generated class file and resources
Export all output folder for checked projects
Export Java source files and resources
Export refactorings for checked projects
Compress the contents of the JAR file
Add directory entries
I am not sure which are supposed to be selected and if it makes a difference in the behaviour of the project I will add the (soon-to-be) exported JAR file to. I tested it by exporting with the default settings. This worked ok.. However, I now do not know if I should have chosen different settings in case of any reasons I am not aware of. I am not sure if there are specific settings I should choose when I intend for the JAR file to, specifically, be added as an external JAR file to another project.
Please enlighten me!
This is a traditional Java library that uses Maven. It should be fairly easy to build using Maven, which should be better and quicker to build this, if you already have Maven and git installed.
Let's consider that you did not download the source file as a zip, but take the github approach, where you'd use git to download the source code.
If you don't have git, download its latest version and install it.
If you don't have Maven, download its latest version and install it.
Once Maven and git are installed, make sure the Maven and git binaries are configured in your environment PATH variable. If not set, you would, on the Windows platform and for Maven binaries, set it this way (using the default installation path):
set PATH=%PATH%;C:\Program Files (x86)\Apache\maven-3.1.1\bin
Create and change directory in a work directory of your choice, that we'll refer to %work_directory% from now on.
Run the following:
cd %work_directory%
git clone https://github.com/spreiter301/Core.git
git clone https://github.com/spreiter301/Twinkle.git
cd Core
mvn clean install
cd ../Twinkle
mvn package
6. Retrieve the twinkle-1.0.0.jar file in the newly created '%work_directory%/Twinkle/target' folder.
In this case, it was necessary to retrieve the Core library because it is a dependency of the Twinkle project. Normally, this is not necessary because dependencies are automatically retrieved from a maven repository. But in that case, that dependency is not available on any Maven repository. Hence we manually retrieved the dependency from github, compiled it and installed it in your local cached repository. Then we could package the Twinkle project into the JAR file.
This should do it. If you want a 5 minutes tutorial on Maven, there is a tutorial for this here. I highly recommend it, you will encounter this often in the Java world. Maven is the standard build tool for Java, just like 'make' is for C, 'rake' for Ruby, 'sbt' for Scala, etc..! Good luck with the rest.
I need to use a xyz.jar wich was generated with ant. Hence, the transitive dependencies are missing. So I had the idea, to modify the xyz.jar to add the internal META-INF/maven/groupId/artifactId/pom.xml and pom.properties files.
When I deployed it to Artifactory, it ignored them and generated it's own pom.xml without dependencies.
What has one to do, Artifactory deploys the pom.xml lying about in the same folder as the xyz.jar file?
Lost way too much time on this allready...
Chances are that Artifactory skips the deployment of the internal POM because it cannot read the POM's physical size from the archive (done for historical reasons); You can verify this by looking at the log for a warning message along the lines of:
"Found pom.xml file with size -1 inside the zip. Ignoring"
If you've already gone to the lengths of creating a customized POM file, you can paste it's contents in the POM content editor of the artifact deployer or deploy it independently; though the first option will give you the benefit of auto detecting the deployment coordinates for the JAR file.
It might be a better idea to add it's dependencies to your pom instead of rigging a third-party library to use maven.
That being said, make sure your pom.xml is valid XML (most modern IDEs can validate xml for you) and make sure your properties file includes version, group id, and artifact id.
Artifactory has changed the way that it handles POM generation in different versions, so, depending on your version, you may have some sort of generate pom option that you have to turn off on deploy. I think they have a deploy time pom editor or something like that in the newer versions.
modify the ant that create an xyz.jar to produce runnable jar - the jar should have all its deppendencies packaged inside.(create a lib directory in your xyz project and put all the jars xyz deppends on inside this directory, then export your project to jar with all the libraries packaged inside)
good step-by-step example how to create an ant script can be found here.
good luck!
I have a module that is used by creating a custom class loader. The class loader should therefore be created with the path to the module and also all dependencies.
I'm looking for a way to make it productive to work with this mechanism in both dev and production environments.
I thought the build can generate two files listing all dependency paths. A 'dev' file and 'production' file (then in the code I'd choose the right file based on some system property):
dev: dependencies should be paths to thirdparty jars in the local maven repository or 'target\classes' for other modules (which will allow to compile with the IDE and not need a full build for each change)
production: all jars should be copied to a 'lib' folder and the dependencies should list them (without full path). Alternatively, create an uber jar, and then the (?)
So I'm looking for pointers to plugins & pom snippets to help me with this.
Some hints:
For the dev part, the Maven Dependency Plugin and its dependency:build-classpath can help (and supports writing the output to a file). Another option would be to use the Maven AntRun plugin, it has access to the Maven runtime classpath, it should be easy to write the property to a file.
For the prod part, I assume you'll use the Maven Assembly Plugin or the Shade Plugin or another equivalent and I wonder if you couldn't generate a classpath entry in the MANIFEST.MF and rely on it.