Maven clean package produces two jars - maven

I packaged my java application using mvn clean package. This produced two jars in my target directory - one is myapp-0.1.2-SNAPSHOT.jar and the other is myapp-0.1.2-SNAPSHOT-sources.jar.
Can someone explain the difference between these two?
If I want to deploy my application to a server which one should I use?

myapp-0.1.2-SNAPSHOT-sources.jar contains all your source code along with your project, during development it is easier to debug when the sources are attached. It is most likely generated by the maven-source-plugin. You will likely find it configured in your pom.xml. When deploying, use the other jar: myapp-0.1.2-SNAPSHOT.jar

Related

Setup maven pom to work with dependencies across environments

I have a Java projects a-1.0.jar with ojdbc.jar dependency and b.jar that depends on a-1.0.jar and ojdbc.jar. I am trying to make it work on my machine, new user machine and a Bamboo server.
Desired behavior:
On local machine git clone <git_url>, mvn clean install, java -jar b.jar project should run. Bamboo should checkout and run project.
On Bamboo: a plan can check out a project and run it. Build should track version of b.jar built and a.jar used.
So far I saw these options:
<systemPath>${project.basedir}/lib/a-1.0.jar</systemPath>: maven warns that it will fail to resolve dependencies
A Perl script to run mvn install for each dependent jar before building the project
(1) defeats the purpose of DevOps automation
(2) makes it unclear which version of a jar was used
(3) installs the jar, but java -jar b.jar fails a.jar is missing
I can overcome this with another Perl script that adds the dependent jars to a classpath
These are basic tasks and as a build tool Maven should be able to do it.
How to tell Maven to three goals below?
(1) For each unknown import - get a jar from lib folder
(2) Make a set of dependent jars. That is don't import ojdbc twice
(3) Pack a self sufficient jar that runs, not fails with "stuff is missing"
Seems like you need to create an executable jar - and for this, you can use various approaches.
One of them is, add maven-shade-plugin which puts all dependencies into single jar, while taking care of potential resource collisions.
Try non-maven-jar-maven plugin. It adds jars that are not in the maven central.

maven build from different repos from one pom.xml

Is it possible to build(and not download) a dependency in same pom.xml?
Another team builds/maintains a code in git repo A. I have to use that as a library in my code.
When I build my code using maven, I want this to be checked out and built and then the jar be included as a dependency.
I understand this can be achieved using Jenkins jobs.
And in dev stage, I can install an already built jar in m2 repo and use the jar as dependency.
However, I would want to confirm if its possible to solve this scenario outside Jenkins. That is, I as a developer, can I configure the build of repo A during build my code?
I hope I am able to explain the scenario.
Thanks.

How to build a standalone AWS SDK .jar that includes all the dependencies

We are trying to build a standalone .jar (.zip file) that includes all the dependencies based on aws-sdk-java-1.11.86 using maven command line.
The pom file for AWS is quite complex and we are concern changing it or writing or own since it might not be compatible with newer version of AWS.
Does somebody knows how to do it?
The command is:
mvn package
The actual maven target is "aws-java-sdk-bundle".

How to stop maven deploying test jar files

Maven has a useful facility to create jar files for tests that can be depended on by other projects. We use the "easy way" from this page. This all works fine, and produces files of the name foo-1.0.0-tests.jar.
By default, these test jar files are installed and deployed. The question is how to have them be installed, but NOT deployed?
(There is no need or desire to publish these files to maven central, but they are needed when running tests locally. Thus install is correct, and deploy is not.)
The maven deploy plugin appears to have has no suitable options. The build-helper-plugin has the ability to attach file to deploy, but not to remove them.
Any suggestions to get these jar files installed, but not deployed?

Why after compiling/building my AWS sdk jar is only 3kb?

I was previously on 1.6.x and mvn clean install builds wit no issues; end up with a 10mb jar and able to run all my code.
Now I want to upgrade to 1.10.x for the new lambda/apig/ddb support, I changed the version from 1.6.x to 1.10.x.
But after I build with mvn clean install, I see the jar is only 3kb, why is that? Has something changed with the way the AWS sdk works? At least from I've seen, one new way is you can be pick specific services rather than the whole sdk.
Edit:
The 3kb jar has the following:
pom.properties:
version=1.10.66
groupId=com.amazonaws
artifactId=aws-java-sdk
pom.xml, which lists all the aws sdk services
Have you uncompresssed the jar file and looked up what is in that folder? Based on the information in your question, I guess you have just got your own source files there but not the dependencies. If any, maven dependencies are usually located at META-INF\maven in jar. BTW, do you use maven plugins? For example, maven-jar-plugin only outputs your source code in jar while maven-assembly-plugin also outputs maven dependencies.

Resources