How to create single jar file from github tree?
Asked Answered
D

2

4

For example, the Java API for pubnub is at https://github.com/pubnub/pubnub-api/tree/master/java

I want to create a single jar file from all the java files in the subfolders.

What is the most straight-forward way to do that?

Dare answered 28/11, 2011 at 18:56 Comment(4)
A jar is just a zip file, so you can download it straight from Github as a zip. Just sayin'.Whitaker
But the jar have to contain .class files, not .java , isn't it?Dare
You're right, so you have to download it, build it and put it into a jar.Whitaker
There is no build script provided, maybe because it is easy, one have to compile all .java files in the all subfolders. I thought that maybe there is some way to do that, which I do not know. It is an interesting idea to make a tool that, given a github url produces the jar file which you can use directly.Dare
J
2

Since Pubnub provided no build file, you need to create a new java project in your favourite IDE and then import the downloaded java code. Next, you can compile and package the project into jar file using the IDE.

Note: it is also possible to create a build script yourself but it is more complicated.

Jaenicke answered 28/11, 2011 at 19:5 Comment(0)
D
0

Since you want a single jar file, then the easiest way to do this is to follow the next few steps:

  1. Create a Maven project in, say NetBeans. I typically make the same name as it is on the public repository. In this case I recommend "pubnum".

  2. Pull the source from a GIT repository into the project you've created in the step #1. This part is tricky because the source in the GIT repository may not follow Maven conventions... If it does not, you must restructure it. Read about Maven directory structure.

  3. Make sure the Maven shade plugin is installed, and you are ready to roll. Just execute maven shade:shade and, if everything goes well, you'll get the jar file.

Dipnoan answered 28/11, 2011 at 19:28 Comment(1)
Now there is a pom.xml : github.com/pubnub/pubnub-api/blob/master/java/pom.xml How can it be used to build the .jar file?Dare

© 2022 - 2024 — McMap. All rights reserved.