Hosting executable .jar files in BitBucket repo or automate packaging executable .jar files from git into local folder

huangapple go评论81阅读模式
英文:

Hosting executable .jar files in BitBucket repo or automate packaging executable .jar files from git into local folder

问题

我正在尝试在Java中创建一个启动器应用程序,可以调用可执行的.jar文件。其中一种简单的方法是将可执行的.jar文件托管在云实例中,启动器应用程序将从云实例下载.jar文件到用户的本地文件夹中。然而困境在于缺乏能够托管jar文件的云服务或服务器。

作为一种变通方法,我想我可以将jar文件托管在BitBucket中,启动器应用程序将从那里下载可执行文件。尽管如此,我认为这有点不常规,因为它主要用于版本化源代码(如果我说错了,请纠正我)。而且,我不确定是否可能通过FTP调用或从那里下载文件(也许可以通过BitBucket API实现?)。

另一个选项是,启动器应用程序可以从git存储库创建可执行的jar文件,将打包的可执行的jar文件下载到用户的文件夹中,并从那里调用。如果这种做法可行,我将非常感谢任何关于这个选项的指引。

谢谢!

英文:

I am trying to create a launcher application in Java that can invoke executable .jar files. An easy way for this is to host the executable .jar files in a cloud instance and the launcher application would just download the .jar files from there into the user's local folder. The dilemma is the absence of the cloud service or a server that can host the jar files.

As a workaround, I thought I can just host the jar files in BitBucket and that is where the launcher application will download the executable files from. Though, I think this is a little unconventional since it is mostly used to version source codes (please correct me if I am wrong). Also, I am not sure if it would be possible to invoke FTP or download files from there (perhaps through BitBucket API, maybe?).

Another option is that it could be possible to make the launcher app to create executable jar files from the git repo and download the package executable jar files into the user's folder and invoke from there. If this is possible, I would appreciate any leads towards this option.

Thanks!

答案1

得分: 1

是的,您可以将二进制文件推送到GitHub(从Bitbucket获取原始内容很困难,您的请求需要进行身份验证等操作)。

以下是如何执行的步骤:点击此处查看详细步骤

为防止内容被删除,我也将内容复制在这里:

逐步创建GitHub项目的Maven仓库

  1. 在一个单独的文件夹中克隆您的项目
    (注意:将ORGANIZATION和PROJECT替换为实际的组织和项目名称)
git clone git clone git@github.com:ORGANIZATION/PROJECT.git my-repository
  1. 进入该文件夹
cd my-repository
  1. 创建一个新分支(此处命名为repository)
git branch repository
  1. 切换到该分支
git checkout repository
  1. 删除所有文件
rm -rf file1 file2 file3 .. etc
  1. 将您的jar文件安装到该目录中
    (注意:将YOUR_GROUP、YOUR_ARTIFACT、YOUR_VERSION和YOUR_JAR_FILE替换为实际值)
mvn install:install-file -DgroupId=YOUR_GROUP -DartifactId=YOUR_ARTIFACT -Dversion=YOUR_VERSION -Dfile=YOUR_JAR_FILE -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=. -DcreateChecksum=true

请确保YOUR_JAR_FILE指向一个现有的jar文件,这就是为什么最好在不同的文件夹中创建存储库分支的原因,这样您可以在/your/project/path/target/artifact-x.y.z.jar中引用现有的jar。

  1. 添加所有生成的文件,提交并推送更改
git add -A . && git commit -m "released version X.Y.Z"
git push origin repository
  1. 从其他项目中引用您的jar
您刚刚创建的存储库URL是:https://raw.github.com/YOUR_ORGANIZATION/YOUR_ARTIFACT/repository/

第二个选项也是一个不错的方法,因为用户将始终获取到更新的内容,但这会增加构建时间,这取决于您的用例。

英文:

yes you can push your binaries to github (getting raw content is difficult from bitbuket your request need to have authentication and stuff).

here is how to for that

copying here as well in case get's removed.

> How to create a maven repository for your github project step by step
Clone your project in a separate folder
(note: replace ORGANIZATION and PROJECT)

> git clone git clone git@github.com:ORGANIZATION/PROJECT.git my-repository

> cd into it
> cd my-repository

> Create a new branch (here named repository)
> git branch repository

> Switch to that branch
> git checkout repository

> Remove all files
> rm -rf file1 file2 file3 .. etc

> Install your jar in that directory
> (note: replace YOUR_GROUP, YOUR_ARTIFACT, YOUR_VERSION and YOUR_JAR_FILE)

> mvn install:install-file -DgroupId=YOUR_GROUP -DartifactId=YOUR_ARTIFACT -Dversion=YOUR_VERSION -Dfile=YOUR_JAR_FILE -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=. -DcreateChecksum=true
YOUR_JAR_FILE should point to an existent jar file, this is why it's best to create your repository branch in a different folder, so you can reference the existing jar in /your/project/path/target/artifact-x.y.z.jar

> Add all generated files, commit and push
> git add -A . && git commit -m "released version X.Y.Z"

> git push origin repository

> Reference your jar from a different project
> The repository url you just created is > https://raw.github.com/YOUR_ORGANIZATION/YOUR_ARTIFACT/repository/

2nd option is also a good approach as you user will get always the updated content but that will add building time into it, depends on your use case.

答案2

得分: 1

一般来说,将构建生成物存储在 Git 存储库中并不是一个好主意。通常构建生成物体积较大,压缩效果较差(尤其是已经压缩过的 JAR 文件),而且不需要进行版本控制。这恰恰是你不希望出现在 Git 存储库中的行为。

虽然确实可以这样做,但你可能会发现 Bitbucket 不太适合用于托管这种目的的 Git 存储库,然后你将不得不寻找替代解决方案。最好是将这些资产托管在云存储桶中,甚至是在静态服务器上,并通过 HTTPS 下载。如果这不可行,你需要考虑为什么,然后寻求解决方法。

如果这些 JAR 文件是你已经在 Bitbucket 上托管的软件发布的构建生成物,那么对于这一目的,使用 Bitbucket 的标准发布资产功能可能是可以的。你只需避免使用 Git 存储库,因为相比静态资源,Git 存储库的服务成本要高得多。

你也不应该使用 FTP,因为(a)它比 HTTPS 更慢,(b)由于人们没有遵守规范,无法始终使用 TLS。如果你在未加密的连接上下载数据并执行该数据,你的软件将存在可利用的安全漏洞,而无法进行完整性检查。

英文:

In general, it's not a good idea to store build products in a Git repository. Generally build products are large, tend to compress poorly (especially JAR files, which are already compressed), and don't need to be versioned. This is exactly the behavior you don't want from your Git repository.

While you can indeed do this, you're likely going to find that Bitbucket is not going to want to host your Git repository for this purpose, and then you'll have to find an alternative solution. You'd be better off hosting these assets in a cloud storage bucket or even on a static server and downloading using HTTPS. If this isn't achievable, you need to consider why that is, and look into solving it.

If these JAR files are build products for a release of software you're already hosting on Bitbucket, then it's probably fine to use the standard release asset functionality of Bitbucket for that purpose. You just don't want to use a Git repository, which is significantly more expensive to serve than static assets.

You also don't want to use FTP because (a) it's slower than HTTPS and (b) due to people not complying with the spec, it's impossible to use TLS with it consistently. Your software will have an exploitable security bug if you download data over an unencrypted connection without integrity checking and then execute that data.

huangapple
  • 本文由 发表于 2020年3月16日 19:19:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/60705006.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定