• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Attempting simplest possible GitHub repo

 
Ranch Hand
Posts: 91
1
  • Number of slices to send:
    Optional 'thank-you' note:
Hi CodeRanchers

I’m trying to rehabilitate my attempts at getting into a software apprenticeship-type position, and, though I have some tiny programs up on my bare-bones ‘website’, which I include in my CV etc., I’ve succumbed to the mantra that one must put stuff up on GitHub. So I made my first foray into git & GitHub, via NetBeans (don’t judge me!), a few days ago, setting up a repo for my latest tiny program  https://github.com/embyr333/NotAgain

Despite looking around quite a bit at other peoples repos, and for basic GitHub introductions, I feel I still don’t have a clue whether what I currently have on the site after pushing my NetBeans project includes irrelevant items or does not include necessary items, or both (probably the latter).

On my simple website (linked from my account profile), I offer the NotAgain program for anyone who wants to run it in a zipped folder containing three items: binary JARs for NotAgain and the external JNativeHook library (a ‘dependency’?) it uses, plus a text file “WordleSolutions” which it also needs (also called a dependency, or not?). I also offer my single source code file in a separate link (along with previous iterations, which form my pre-git versioning history). I plan to commit versions (if any) to git, and to push the changes to GitHub if I feel I’m producing something follows basic expectations for the site.

So maybe the simplest thing would be to just have NotAgain.java and WordleSolutions.txt present and add a link to the JNativeHook.jar in my README file? I get the impression that uploading the actual binaries for external libraries (dependencies) is not good form. Then, for moment forget about the option to generate a ‘release’...I assume this would require encoding the link to the dependency in a way that a build tool (e.g. Maven) would produce, but this seems to be a whole other level of complexity that seems inappropriate for my very small/simple programs(?)

Thanks to anyone who’s read this far, and further gratitude to anyone who may offer thoughts!
 
Elaine Byrne
Ranch Hand
Posts: 91
1
  • Number of slices to send:
    Optional 'thank-you' note:
Oops - it seemed I had to choose between ~4 sub-categories within Open Source, and I've probably chosen the wrong one (didn’t realise JForum was a ‘thing’ before clicking on that!    ), so admin/mods please feel free to move my previous post
 
Elaine Byrne
Ranch Hand
Posts: 91
1
  • Number of slices to send:
    Optional 'thank-you' note:
(Thanks for transferring!)
 
Saloon Keeper
Posts: 15608
366
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

Elaine Byrne wrote:I feel I still don’t have a clue whether what I currently have on the site after pushing my NetBeans project includes irrelevant items or does not include necessary items, or both (probably the latter).


Here's a simple guideline: You should commit everything that is needed to build or document your project, except stuff that can be gotten from other repositories. Don't commit more than that. In particular, binaries that result from your build should not be committed.

Of course, it's not as cut and dry as that, but that's the basic principle. Here are some caveats:

  • Dependencies in general should not be committed. However, if it's difficult to get a specific version of a dependency (or you don't trust the dependency to be publicly available consistently) then you can commit it to your repository.
  • IDE-specific project files are usually separated into general project configuration and user-specific configuration files. Commit general project configuration. Don't commit user-specific configuration.
  • Don't commit environment-specific configuration files, especially not if they contain sensitive data such as passwords, private keys or tokens.

  • On my simple website (linked from my account profile), I offer the NotAgain program for anyone who wants to run it in a zipped folder containing three items: binary JARs for NotAgain and the external JNativeHook library (a ‘dependency’?)


    GitHub offers the possibility to add releases to your repository. These are separate from your source code commits. That way you have a centralized place for people to download different versions of the build result of your application, which might be just a zip with binaries or it might be an installer or whatever else you want.

    it uses, plus a text file “WordleSolutions” which it also needs (also called a dependency, or not?)


    This is called a "resource". Any static file that your application needs at runtime that is not compiled code (such as images, scripts, configuration, data) is typically called an application resource. Resources should be committed to your repository.

    and to push the changes to GitHub if I feel I’m producing something follows basic expectations for the site.


    The point of Git is not only that your source code is versioned, but also that it is stored in a decentralized manner, so that when your development system goes up in flames, you still have a backup of the source code. Nobody expects a GitHub repo to be perfectly curated. Development is messy.

    A Git mantra that you might have heard before is "commit early, commit often". Well, that also applies to pushing commits. Use development branches to push whatever you want, and then you can always curate your commit history later when you merge to a release branch.

    So maybe the simplest thing would be to just have NotAgain.java and WordleSolutions.txt present and add a link to the JNativeHook.jar in my README file? I get the impression that uploading the actual binaries for external libraries (dependencies) is not good form. Then, for moment forget about the option to generate a ‘release’...I assume this would require encoding the link to the dependency in a way that a build tool (e.g. Maven) would produce, but this seems to be a whole other level of complexity that seems inappropriate for my very small/simple programs(?)


    Honestly, I think a Maven POM IS the easiest way you can set up a repository. That way anybody who clones your repo has everything they need to build and run it, and for small projects Maven POMs can also be really simple.
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Thanks Stephan. I'll change to a stripped-down set for immediate use as I mentioned, then try the Maven overlay via NetBeans to get the pom file and switch to that if it works out.
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    (I’ve now made a provisional ‘simplified’ repo of the type I was wondering about above, at https://github.com/embyr333/embyr333-NotAgain_simple_GH_repo))
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    (Sorry, don’t want to seem to be bumping the thread, but just wanted to update that I now have just a single repo for NotAgain, https://github.com/embyr333/NotAgain, with the ‘simplified’ 3-item content in case anyone else visits and finds dead/altered links. Have a bit better feel for the process now, after experimenting further. Thanks for help   )
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15608
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    A few comments:

  • Readme files should just be called README.md. That way, GitHub will display it immediately without you having to explicitly click on it in the file browser.
  • Projects on GitHub should contain a build definition. I assume you're still working on this, but I expect most Java projects to contain a Maven POM.
  • Java classes should be in a named package, never the default package.
  • Use conventional names for your classes.
  • You might want to reorganize your directory structure if you're going to turn your project into a Maven project.

  • For example, if your NotAgain class is actually named com.example.fiveletters.FiveLetterWordsApplication, your project should have the following directory structure:

     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Aha, I didn’t realise that about the README – I probably would have wondered at some point why it didn’t appear by default as it had in a previous versions (when I did indeed have the name  as just “README”!) (I changed later to avoid the possibility of confusing myself with the README file generated by NetBeans in the dist directory after doing a build, but in retrospect that was unnecessary, so I will gladly revert the name.)

    Re build definition: I do have a note in the README about intending to try to use Maven to generate a POM, so I will bite the bullet on that next (new to this aspect).

    Re lack of package structure: yes, I realise this is not standard, and actually have a note in the comments at the top of the java file about another reason why I might want to do that. To be honest, since my projects have been so small it’s always seemed like overkill to use packages, with all the extra clicking involved in opening subdirectories, but I will probably add that also.

    I’ll bear your example in mind when I try the Maven project setup (I don’t yet have a feeling for the extra levels of directory organisation needed, but will read up.)

    Thanks again – really appreciate this advice!
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15608
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:

    Elaine Byrne wrote:since my projects have been so small it’s always seemed like overkill to use packages, with all the extra clicking involved in opening subdirectories, but I will probably add that also.


    It sure may feel that way, but it's good to get into the habit. There are some subtle difficulties that may arise when you use the default package, so it's better to always put your classes in a named package.

    For inspiration, you might use the URLs of your projects on GitHub. For instance, the base package of your application could be com.github.embyr333.notagain.

    I don’t yet have a feeling for the extra levels of directory organisation needed, but will read up.


    Maven uses "convention over configuration". The more your project conforms to Maven's expectations, the less you have to configure in the project descriptor. You can use whatever directory structure you like, but then you'd have to spend a lot of time configuring Maven so it builds your project correctly.

    Using the directory structure I proposed above (but instead of com.example.fiveletters I'll be assuming com.github.embyr333.notagain as your application package from now on), your Maven POM could be as simple as this:

    There's a lot more you should configure (such as the Java version you're using and the versions of the Maven plugins you're using to build the project), but the POM above is a good illustration of how simple Maven can be.

    If you use Maven's default directory layout, it expects your application's source code to be in the src/main/java folder. The src/main/resources folder is used for files that your application needs as runtime, but don't need to be compiled.

    I put the WordleSolutions.txt file in the same package as the main application class, because in general you want resources to be in the same package as the class that uses them. That way they can easily be loaded from your application like this:
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Thanks!
     
    Saloon Keeper
    Posts: 27851
    196
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    Just the executive summary of Stephan's detailed wisdom:

    If I, living on the other side of the planet, can download a copy of your project (via either git clone or as a ZIP) and built a working copy, then you've included everything you need to. If you can delete files and/or directories from the git archive and I can still build it, then you've included an optimal set.

    Incidentally, in Maven projects, you should omit (.gitignore) the target directory entirely. Everything under that directory is supposed to be a product of the Maven build, including the target directory itself.

    Also, properly speaking, while /src/main/resources is the standard location for general Java projects such as JARs, for webapps, the proper place for webapp resources is /src/main/webapp. The /src/main/resources directory technically defines resources that copy to the classpath, and for JARs, the classpath is the root of the JAR. In webapps, however. the classpath is under /WEB-INF/classes and /WEB-INF/lib and a WAR's resources include extra-classpath resources such as web page templates, CSS, Javascript files and so forth.

    Now, regardless, the actual files and directories found in both /src/main/resources and /src/main/webapp are going to be copied to the root of the target archive when Maven does a build, but it's better, semantically speaking (and in case of future changes) to use /src/main/webapp for WARs. You may also see unexpected effects if you are building at a finer grained Maven goal level, such as "war:war".
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Thanks, Tim!
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15608
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    Elaine, I opened a pull request that converts your project to a Maven project.

    You are free to commit changes to the pull request before you merge it, but if you don't intend to merge it, let me know so I can remove my fork.
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Thanks Stephan! I think I've merged it. (I meant to make an associated change to the README, but I'll have to do that later.) To get it back into my IDE (NetBeans) I think I would do Team > Remote > Pull (or Pull from Upstream)? (I tried initially to make a clone into a new project folder, but that didn't work.) (On a related note, I did try making a Maven test project, but the build process did not complete, so I'm also not sure if there's something amiss with my set generally)
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15608
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    Yes, pull from upstream should work (as long as you don't have uncommitted changes).

    The very minimal POM I showed you earlier in this topic uses a very old Java version by default, which is likely the problem. The POM I added to your project initially used Java 17, but when I noticed that you had mentioned Java 8 somewhere in your README, I downgraded the Java version in the POM. I also set the plugins that Maven uses by default to a fixed version, which is good practice.

    NetBeans should automatically recognize your project as a Maven project. When you build it, NetBeans will call Maven internally. Ensure that you have NetBeans configured to use a recent version of Maven.
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Netbeans Teels > Plugins > Maven > Installed tab shows
    Version: 4.30.1
    Source: NetBeans IDE 8.1 (Build 201510222201)

    but looking on the Maven site suggests 3.8.6 is the latest version?, so I’m uncertain.

    (Then doing a Check for Updates bring up a “Unable to connect to the Plugin Portal because of Connection reset” warning)

    Maybe I’ll just go ahead with the pull and see what happens
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15608
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    You're using a really old version of NetBeans. It might be time to upgrade to version 14.

    Normally I'd recommend you download the latest version of Maven (which currently is version 3.8.6) and configure that in NetBeans, but NetBeans 14 comes bundled with Maven 3.8.5, which is recent enough.
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Ah, thanks. I know this sounds cowardly, but I think I’ll have to delay doing that until I’m in a better situation – I’m operating in isolation, with an unreliable laptop, and I can’t afford the risk of having to something going wrong. But I really appreciate you having pointed me in the right direction for future explorations!
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 15608
    366
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    Note that you can easily run two different NetBeans versions side-by-side. When downloading NetBeans, just select the ZIP option instead of the Installer option.

    Here is a shortcut: https://www.apache.org/dyn/closer.cgi/netbeans/netbeans/14/netbeans-14-bin.zip

    After extracting the ZIP in some installation location and open the etc/netbeans.conf file in a text editor. Uncomment the netbeans_jdkhome line and set the location of your JDK. For instance, for me it looks like this:

    That reminds me, if you're not already on Java 17 or higher, this might also be a good opportunity to download a new version of Java.

    Another shortcut: http://jdk.java.net/18/

    Finally, to run NetBeans you just run one of the executables in the bin/ folder. After NetBeans opens, I usually just pin the window to my taskbar.

    Installing and running NetBeans this way should not interfere with your existing installation, so if you don't like NetBeans 14 you can just go back to using the old version.
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Number of slices to send:
      Optional 'thank-you' note:
    Thanks!
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic
    vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
    http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |