How do I deploy just the sources jar from a maven project? - java

We made a number of releases to our nexus repository without source jars attached. I would like to backfill the source jars for these releases.
What I tried to do was
checkout the tagged version that I wanted to upload sources for
update the pom with the attach-sources snippet
do a maven deploy
This failed with a 400 error code because the pom and artifact jar were already in the repository.
Is there any way to upload just the source jar?

you should be able to do this using maven deploy-file (this has the added benefit of generating the various file sums as well), details here (you would be using, among other things, "packaging=jar" and "classifier=source").

I think the simplest thing would be to just upload sources jar using 'curl'. You will not even need to make any changes for that.

Related

Deploy Ant project into Maven repository

I am new using Maven and I need to upload some libraries from an Ant project. To develop this task I have one folder that contains a lot of "pom.xml" files that refers to the jar that I would like to add to my project in Eclipse using Maven, and another xml file that is the Ant project itself.
All ideas are welcome. Thanks!
Unfortunately no good tools exists for Ant to Maven migration. You will need going step by step from module to module do so:
Enable maven nature on each project.
Resolve maven dependency by hand.
Deploy artifact into local or remote repository.
Pay your attention on version numbers of libraries. Make sure the md5 hash or sha2 hash of library in ant project and the library received in maven after adding dependency is exactly same. Otherwise you will definitely get some non traceable errors if not during testing but after deployment to prod.

How can I recursively download an artifact and all dependencies into a directory?

I don't have an internet connection at work, and I want to bring there a specific library.
So I want to be able to download at home an artifact along with all of its dependencies (recursively), in order to be able to take all of these jars and bring them to work.
I have read on this site about dependency:get, which is great but downloads the artifacts to the local Maven repo (~/.m2/repository). This means that after downloading, I need to look at pom files and manually copy all of the dependent JAR files to some directory, which I can then bring to work.
I would love to have a way to simply download the desired JAR and all of its dependencies into a specific folder.
Is there a way to acheive this?
Please note: this question is different than the mentioned duplicate, in that I'm asking how to do this without any project or pom.xml file. I'm looking for the simplest way to do this.
EDIT: I believe I found a possible solution (not the most elegant though..):
Rename the local repo (~\.m2\repository on my Windows machine) to repository.old. Create an empty directory repository at the same location instead.
Run
mvn dependency:get -Dartifact=<groupid>:<artifactid>:<version>
This doesn't require a pom.xml or a project.
The artifact and dependencies have been downloaded to your local previously-empty repository (~\.m2\repository).
Move the local repository to wherever, and rename repository.old back to repository.
(I think) you now have all the dependencies for your desired artifact.
dependency:get will load everything you need in .m2 then when you are offline you will be good. I don't think you need to do anything else.
Test it by disconnecting your machine for your network when you are at home.
Normally the dependencies are downloaded when maven is updating the indieces.
As you can see in this post: What is Eclipse doing when it says that it's updating indexes? you just need to enable eclipse or whatever ide youre using to download the sources as well.

How to include library jar in git project

We have a core set of java libraries, published as jar files, that are used in multiple client projects. Both the library projects and the client projects are on our git server (GitLab EE). Sometimes clients and third-parties (such as sub-contractors) have access to the project source code, but we don't want them to have access to the source for the core java libraries.
So what I need to know is how to set up some kind of dependency or similar in git so that we can automatically pull in the latest version of the library file? I've been looking at git submodule, but that looks like it will pull in, or at least give access to, the full source of the library projects. I've also started looking at Maven, but I'm unclear whether that also needs access to the whole repository. Is there another/better way to do it? Or will Maven actually do what I want? Or do I need to publish my jar files somewhere else, and if so how can I automate that process, as I don't want to have to manually copy the jar file somewhere every time it's updated (which is often)?
Maven and a binary repository like Nexus is the common way to do what you're asking. Nexus stores binary files like .jar's .dll's etc and Maven has the capability to publish and retrieve specific versions of these binaries and include them when building the project. As Ryan commented, Maven Central is a public binary repository that you could publish to if you wanted the whole world access to your .jars, but with Nexus you have fine grained access control over your binaries.
If you build your own projects with Maven, you can configure it to build, test, and publish right to your Nexus repository with a single command mvn deploy. Then clients just have to update their project to point to the new version and Maven will download it and use it on the classpath. It's all very seamless, and I would definitely recommend refactoring your build process to use Maven or a similar product.

Import and use a Maven managed Java library (CitySDK)

I am trying to build a web application based on the project library CitySDK, but i don't know how to import it properly into my own project.
I have created a Maven Web Application and added the CitySDK library as a Dependency, and then Selected the Project, right-clicked and Selected Build with Dependencies. No errors appeared, and in the image below you can see it appeared as a dependency.
However, whenever i try to use some of the classes specific to it, in my own Web Application(called TourismApplication's TestClass.java), the compiler displays an error, that the package is unknown. Could anyone suggest ideas as to what i have missed? I have followed a few Maven tutorials, but without any effects.
The dependencies are as follows:
Ok I did some digging and I think I figured out your problem. Their POM file is incorrect based on the structure of project.
First off, I'll paraphrase what I think the steps you took to get it built in your project were, to ensure I followed the same steps to get it working. These are the steps I took:
Cloned/downloaded the sources from the link you placed in the OP
Built the project into a jar file by running the command they said to use: mvn clean package assembly:single
Installed the artifact in your local Maven repo using mvn install
Added a dependency in your project POM
I tried the same thing you did, using the library in a test source file, to no avail. I looked at the .jar file that was built using their instructions and didn't find any .class files archived into it... it was essentially empty.
Turns out, their src folder structure follows Maven standards, but their POM file indicates the sources are down a different chain of directories. If you examine the build log closely, you see "[INFO] No sources to compile"
The POM.xml file they provide specifies the source directory as
<sourceDirectory>src/citysdk/tourism/client</sourceDirectory>
However, the actual files are at
src\main\java\citysdk\tourism\client
After changing the line in the POM file from the above to (similarly for tests):
<sourceDirectory>src/main/java/citysdk/tourism/client</sourceDirectory>
<testSourceDirectory>src/test/java/citysdk/tourism/client/tests</testSourceDirectory>
rebuilt, and installed, it worked when I tried to use it in my project. Hope this helps.
FYI, I used IntelliJ as my IDE, but it should work the same with Eclipse.

How to deploy jar in eclipse maven remote repository?

i am working with others developers on eclipse project. The project is hosted on SVN. I wonder how I can add JAR file to the dependencies.
Thank you.
Could you be more specific...
What do you want to do? Add some jar files to your SVN repository?
This is strange...cause you have to share on SVN just the project not compiled, to be able to evolve the code line wit your team...but not the jar files...they could be published on a remote repository like Artifactory or Nexus but no under SVN, for me, it does not make sense.
Not on SVN...but maybe, simply, i don't understand your question...
Try see this -----> Java jar files into a repository (CVS, SVN..)
First, what do you mean I wonder how I can add JAR file to the dependencies.?
Do you mean that you need to add a jar to the compile classpath in Eclipse? Do you mean there's a jar that you need to access whether locally built or from some open source project somewhere on the web?
Is this a jar that Project "A" builds and Project "B" needs?
You can simply check the jar into Subversion. That way, when someone checks out the project, they have the jar. This is a common way to handle this issue, and it's known as the wrong way.
The right way is to use Ivy or Maven, and then use a third party Jar repository like Nexus or Artifactory to host your locally built jars that your projects need. Then, use m2eclipse or IvyDE to connect your repo to your Eclipse project.
Doing things the right way is a bit more difficult, and you and your developers will have to learn Maven or Ivy and how it works. In the end, it makes your development faster and easier. Plus, knowing something like this can help your future career.

Categories