0

I am attempting to make a little tweak in the source of a GitHub java project and to rebuild it back into resulting .jar file to run.

  1. On the project's URL, README says Download the source and build with gradle.
  2. Downloaded using Clone or download button, extracted
  3. Installed Eclipse 2019-12, then > File > Import > Gradle > Existing Gradle Project..., which gave me

this

  1. Opened the .java file in the editor to make any tweaks

Now I need some help understanding how can I test and rebuild so I end up with '.jar' file to run? (The GitHub project's already built original .jar files are here)

Would appreciate to learn what further steps to take towards that.

spcsLrg
  • 340
  • 2
  • 11
  • I'm not used to Gradle, but a command like `gradle compile` or `gradle imker_jars` should do the trick, I think (names come from the _build.gradle_ file). [This link](https://www.vogella.com/tutorials/EclipseGradle/article.html#updating-the-gradle-tooling) shows how you can call these tasks from Eclipse IDE. By the way, it seems that the source files have not been properly imported (I can say that from the look of the icons in the explorer). I don't know the cause, but you can fix the symptoms by right-clicking on the `src` folder > `Build Path` > `Use as Source Folder` – Emmanuel Chebbi Jan 13 '20 at 10:32
  • 1. I did `Use as Source Folder`, it made `src` like [this](https://imgur.com/i48792R) 2. Then on the `Gradle Tasks` tab, right-click `Run Gradle Tasks` 3. `Console` Tab shows [this](https://imgur.com/Hvci23p) Not good right? Am I doing it properly though? Thank you very much. – spcsLrg Jan 13 '20 at 11:55
  • The project seems old, I guess it was working with Gradle 3 and is not compatible with latest Gradle releases; you'll likely have to update the _build.gradle_ file. Here, one of the issues is that Gradle is not able to find the source code (`Task :compileJava NO-SOURCE`). You can [try this solution](https://stackoverflow.com/questions/26634000/gradle-skipping-task-compilejava-as-it-has-no-source-files) (found it by typing "gradle compile no source" on Google). – Emmanuel Chebbi Jan 13 '20 at 12:17
  • So I added `sourceSets` snippet from that link with `srcDirs`. Then did Gradle Tasks > right-click project > Run Default Gradle Tasks. Console now shows `FAILURE: Build failed with an exception. * Where: Build file '\build.gradle' line: 26 * What went wrong: Execution failed for task ':compile'. > Compile failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED` plus few warnings (those safe to ignore I guess?). Do you think it's a lost cause at this point? :( – spcsLrg Jan 13 '20 at 19:07
  • Causes are never lost, they just require more or less work! I think that you have some errors in your _build.gradle_. You should try what is advised by the error message (running the build with `--stacktrace` or `--info`) so that Gradle gives your more details about what's wrong and then either you are able to fix the issue by yourself or you can search a solution on the internet. If the _build.gradle_ file is not well written I would also expect the Eclipse editor to show an error marker; if it does it may help you. – Emmanuel Chebbi Jan 14 '20 at 09:30
  • Thanks a ton for the very kind encouragement & continued interest! I'm still at it (and will update my progress here). Though I must say I hadn't realized when I began that *actual programming* (it probably will be just a tweak of a conditional) would be the least of my worries and so much effort and time would be spent on simply setting up the infrastructure for it! :D – spcsLrg Jan 14 '20 at 14:13
  • I just gave it a try and noticed that you can specify the version of Gradle to use when importing a project (click on `Next >` after selecting the project). I selected Gradle 3.0 and managed to build the project and generate the JARs without any error. Since you just want to make a minor change that may be the easiest solution. – Emmanuel Chebbi Jan 14 '20 at 16:58
  • Wow. OK may be I am missing something supremely obvious somewhere. Here's what I did: **1)** File > Import > Existing Gradle Project > select dir > next > override > specific gradle version 3.5 > next > finish **2)** *Project Explorer* > right-click /src > Build Path > Use As Source Folder **3)** *Gradle Tasks* Tab > right-click project > Run Default Gradle Tasks (progress bar for 2 secs) **4** *Gradle Executions* Tab shows [this](https://i.imgur.com/tanJH19.jpg). **6** I check the project directories and the only `.jar` there is '\imker\libs\jcommander-1.48.jar'. – spcsLrg Jan 14 '20 at 19:42
  • Correction to prev comment: Tried with Gradle 3.0 – spcsLrg Jan 14 '20 at 19:52
  • The other JARs should be generated in the `distrib/` folder. Gradle prints its logs to the _Console_ view; you should take a look at the error message to understand why the build fails. Are you on Windows? I noticed that the `Commons.java` file contains non UTF-8 characters so you may face encoding-related issues (Windows uses CP-1252 by default). – Emmanuel Chebbi Jan 15 '20 at 08:36
  • When you successfully generated the JARs, was your procedure similar to the one I described in the previous comment? (I am on Windows but I also tried the same in freshly installed Ubuntu 19 on a different computer on Eclipse latest and I still don't get the JARs — besides some other new errors, so may be it's my process which is at fault?). Thank you very much. – spcsLrg Jan 18 '20 at 15:08
  • I didn't had to state that `src/`was a source folder as Eclipse IDE managed to find out itself, but otherwise I did the same steps. What are your new errors? Aren't the error messages helpful? – Emmanuel Chebbi Jan 19 '20 at 11:24
  • Sorry about not providing the error messages. So now I just did it without making `/src` as source folder and here are the errors: [This is what comes up](https://i.imgur.com/gugzK9q.jpg) in *Gradle Executions* tab. And [these are the errors](https://i.imgur.com/bBJhwsV.png) when I right-click the red *compile* then *show failures* (you might have to zoom in as it's a long image). Thank you very much. – spcsLrg Jan 19 '20 at 20:59
  • Well, that stacktrace is big but does not really help. It basically advises to "look at the compiler's output log for details". Could you check the _Console_ view? That's where Gradle prints its log and where you'll find a clearer error message. If the view is closed, you can open it from `Window > Show View > Console` – Emmanuel Chebbi Jan 20 '20 at 10:41
  • [This is what I get](https://i.imgur.com/JzwArCr.png) in the Console. One question though: When you managed to generate the JARs, were they 2 different JARs (as per the original build)? I ask this because on this very page — ref [comment link](https://stackoverflow.com/questions/59714494/need-some-help-importing-rebuilding-a-github-java-project#comment105760274_59738303) — I managed to run gradle without Eclipse IDE thanks to a user's tip, but it only generates one tiny JAR which does not run or appear right. Thank you very much for your patience and help, much appreciated. – spcsLrg Jan 20 '20 at 11:50
  • Okay, so [as I suspected](https://stackoverflow.com/questions/59714494/need-some-help-importing-rebuilding-a-github-java-project?noredirect=1#comment105642193_59714494) it seems to be an encoding issue (notice the _unmappable character for encoding_ messages). Don't know how Gradle handles this, but manually converting the `Commons.java` file to UTF-8 should solve the issue. My build generated two JARs (`imker-cli.jar` and `imker-gui.jar`) of 231 and 169 Ko. – Emmanuel Chebbi Jan 20 '20 at 12:02
  • Finally I got both JARs! `Commons.java` was already UTF-8. So I searched and did two things in this order: Create a [Windows environment variable](http://whatiscomingtomyhead.wordpress.com/2012/01/02/get-rid-of-unmappable-character-for-encoding-cp1252-once-and-for-all/) `JAVA_TOOL_OPTIONS` value `-Dfile.encoding=UTF8` ... which still left with two more errors ... those were solved by converting `Commons.java` to `UTF-8 NOBOM` [from here](https://stackoverflow.com/questions/45697794/error-illegal-character-ufeff-in-java/45698146) . Thank you very much! – spcsLrg Jan 20 '20 at 18:18
  • Glad you found a solution! Could you post it as an answer and accept it so that your question is tagged as closed? – Emmanuel Chebbi Jan 21 '20 at 09:23

2 Answers2

0

Can you try using gradle wrapper (https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper), this may resolve the build issues.

Suraj Muraleedharan
  • 1,154
  • 2
  • 16
  • 30
  • The page says `Generating the Wrapper files requires an installed version of the Gradle runtime on your machine`, so should I install Gradle Wrapper along side Eclipse IDE or is Eclipse IDE's gradle can be used? Thank you very much. – spcsLrg Jan 14 '20 at 19:47
  • 1
    Well, it is considered as a best practice to start the server, run tests via command line instead of an IDE. You need to have gradle installed in your machine, https://docs.gradle.org/current/userguide/installation.html#installation Once it is there, you just need to add the wrapper to the build.gradle task wrapper(type: Wrapper) { gradleVersion = '3.0' } and then run `gradle wrapper` task. This will generate required files. Then `gradle compile` or `gradle jar` task may work. – Suraj Muraleedharan Jan 15 '20 at 01:27
  • Here's what I did: (1) Downloaded [gradle 3.0 complete](https://gradle.org/next-steps/?version=3.0&format=all) and put as D:\gradle30\ (2) Put [project](https://github.com/MarcoFalke/wiki-java-tools.git) as D:\gradle30\imker\ (3) Added line `task wrapper(type: Wrapper) { gradleVersion = '3.0' } ` at the end of file D:\gradle30\imker\build.gradle . **Question:** Should I now run `D:\gradle30\bin\gradle.bat wrapper` and then `D:\gradle30\bin\gradle.bat jar`? Thank you very much for your patience. – spcsLrg Jan 18 '20 at 13:09
  • Well, now you need to add the newly installed gradle ( `D:\gradle30\bin` ) to your path ( https://docs.gradle.org/current/userguide/installation.html#microsoft_windows_users_2 ). Then go to the workspace, and verify the installation ( https://docs.gradle.org/current/userguide/installation.html#sec:running_and_testing_your_installation ). Once that is done, you can use `gradle wrapper` to generate required files. – Suraj Muraleedharan Jan 19 '20 at 06:24
  • After path & verifying ( - [screenshot](https://i.imgur.com/ohBpy9h.jpg) - ), I did `gradle wrapper` followed by `gradle jar` ( - [screenshot](https://i.imgur.com/waEIrMP.jpg) - ), as per your instructions. But when I find generated `imker.jar` ( - [screenshot](https://i.imgur.com/e4P9A98.jpg) - ) it is only one tiny 261b JAR (as opposed to be 2 JARs of 231k and 170k plus an EXE as provided by [original build here](https://github.com/MarcoFalke/wiki-java-tools/releases/download/v16.09.13-imker/Imker_v16.09.13.zip). Can you please help what step am I missing here? Thank you very much. – spcsLrg Jan 19 '20 at 14:03
  • Good to know that you have done it the right way. Ideally, gradle doesn't generate EXE files, but it seems the project have some plugins that does this. Can you try running `gradle dist` . It seems the `dist` target will create a zip file contains both the jar files and EXE file. – Suraj Muraleedharan Jan 20 '20 at 17:25
0

Here's how I finally got it working in Eclipse (Windows), thanks to help by emmanuel-chebbi (See detailed discussion in comments below the question)

  1. Created a Windows environment variable JAVA_TOOL_OPTIONS value -Dfile.encoding=UTF8 ( See this )
  2. The file Commons.java in the project also needed to be changed to UTF-8 NOBOM (just UTF-8 not good for Windows!) So did that ( See this )
  3. Imported the project and overridden Gradle 3.0 to be the default ( File > Import > Existing Gradle Project > select dir > next > override > specific gradle version 3.0 > next > finish )
  4. Any code changes as desired, if any (beyond this question's scope)
  5. Ran default Gradle Tasks ( Gradle Tasks Tab > right-click project > Run Default Gradle Tasks )
  6. Two JARs generated in \distrib folder

By the way, meanwhile I have also been trying to get a non-GUI IDE based solution with Gradle 3.0 command line to work, thanks to suraj-muraleedharan, and will update here if I get anywhere with it. (It's good for me to know there's a direct way than GUI IDE, but at this point, I just want to keep it simple for my limitations' sake — so accepting this as answer since it was posted as an Eclipse question anyway.)

Thank you both for your kind help and patience!

spcsLrg
  • 340
  • 2
  • 11