newtfire / staticSearch

A codebase to support a pure JSON search engine requiring no backend for any XHTML5 document collection
https://endings.uvic.ca/staticSearch/docs/index.html
Mozilla Public License 2.0
0 stars 4 forks source link

Issues with building on Windows #3

Open ebeshero opened 2 years ago

ebeshero commented 2 years ago

We know the build will fail on Windows machines running ant on staticSearch "out of the box." The developers are aware of this but didn't have Windows machines available to help them debug it. We may be able to fix it and contribute solutions.

ebeshero commented 2 years ago

Windows: Configuring WSL to build staticSearch

This works just fine, but requires some careful configuration and moving between different command shells on your computer. WSL creates a Linux subsystem on your computer, and we can use it to run the build process so it doesn't warp the file path information that staticSearch depends on to build its search page.

  1. Install WSL, using the Windows CMD shell. Instructions: https://learn.microsoft.com/en-us/windows/wsl/install

    • We want the default Ubuntu shell
    • WSL won't work until you restart your machine
    • After restart, look for your new Ubuntu shell and open it.
    • Follow the prompts to configure a username and password for yourself on the new Linux subsystem. (Be sure to record your new username and password: you'll need them again).
  2. Once WSL is configured, you can open the Ubuntu shell and navigate around your file system. Ubuntu makes its own space on your computer, so you won't immediately see your Windows files. To find them, you need to navigate over to the Windows "mount" or drive. See https://learn.microsoft.com/en-us/windows/wsl/filesystems for details.

A few "big picture" things

Keep in mind:

ebeshero commented 2 years ago

Configuring your Ubuntu environment

You need a new installation of Java over here, because Linux does things differently than Windows. Fortunately this is very easy because we handle the download and installation all at once with shell commands in Linux.

Installing Java

  1. In your Ubuntu shell run: sudo apt update (to update the available packages to install)
  2. Then check if java is already there with java -version (probably it isn't).
  3. Get the latest current default developer Java for this environment with:
sudo apt install default-jdk
  1. When this task has finished downloading and installing, try java -version again (should be there now). You'll have an OpenJDK distribution, which is default for Linux systems.

====================

Find where Java is actually installed on your Ubuntu subsystem

Use cd and ls to navigate and look: see if you have a Java installation here. Right now, my java installation path looks like this:

/usr/lib/jvm/java-1.11.0-openjdk-amd64

Your version of java might be different, so notice and copy-paste whatever it is somewhere that you can use it again. We'll set your Ubuntu JAVA_HOME variable to point to this location.

Find the Linux file path to your Ant installation on Windows

Work with cd and ls to figure this out: You can get into your windows file system by switching over to it. If your Ant and GitHub are on the C: drive on your computer, start the path with /mnt/c/ and continue looking from there. Copy this path carefully so you can use it again in the steps below.

Example: Here's how I can find my ant installation from my Linux subsystem:

cd /mnt/c/Users/ebbon/ant/apache-ant-1.10.12

So, the file path I'll need will be: /mnt/c/Users/ebbon/ant/apache-ant-1.10.12

Setting your environment variables to find what they need

This is basically the same idea as editing Windows' environment variables, only we do this with a text editor connected to the Ubuntu shell. We'll use the nano editor.

In the Ubuntu shell, you need sudo (superuser administrator) privileges to write and edit environment variables. This is where you'll use your WSL username and password.

Enter this command to edit your Ubuntu environment variables:

sudo nano /etc/environment

We'll do a couple of things here. We'll set the JAVA_HOME variable and the ANT_HOME variable.

Add a new line to the bottom of the environment file to read something like this (only change it to point to your specific path to your Java that you copied down earlier:

JAVA_HOME="/usr/lib/jvm/java-ENTER_WHATEVER_YOU_HAVE_HERE"

Now add the ANT_HOME variable in the next line.

ANT_HOME="/mnt/c/Users/ebbon/ant/apache-ant-1.10.12"

Note: I also added the ant file-path to the end of the PATH variable at the top of the file.

One more thing. Let's make it as easy as possible to navigate over to the staticSearch GitHub repo on your computer over on Windows. Use your cd and ls commands to figure out where it is and get that path, and let's enter a couple of simple alias variables, so you just type a simple word and it navigates immediately to GitHub, and another word will get you to staticSearch.

An alias line for easy navigation basically gives the word you want to type, an = and then in quotation marks, the cd command to the literal filepath it stands for. I'll show two aliases in my example script below. Keep in mind these are configured for my computer and your paths will probably be a little different.

**Update: I noticed my Ubuntu shell wasn't responding to me entering the ant command. But it worked if it indicated the path to it by entering $ANT_HOME/bin. So I saved one last alias to make sure the ant command does what we need it to do (which is run the ant file in its bin/ folder).

============================= My /etc/environment file now looks like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Users/ebbon/ant/apache-ant-1.10.12:/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin"
JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64"
ANT_HOME="/mnt/c/Users/ebbon/ant/apache-ant-1.10.12"

alias GitHub="cd /mnt/c/Users/ebbon/Documents/GitHub"
alias static="cd /mnt/c/Users/ebbon/Documents/GitHub/staticSearch"
alias ant="$ANT_HOME/bin/ant"

In your Ubuntu shell, you need to refresh it to recognize the new info you just added. To do that, enter: source /etc/environment

Then try out your aliases first of all. Do they help you navigate quickly over to the staticSearch/ repo?

Last step! Test whether ant works to build staticSearch

In the Ubuntu shell, navigate to staticSearch (use your alias)! Run ant See if the build process completes and generates its search.html page in the /test directory.

If it doesn't work...

Read the error messages carefully. What do you think is wrong?

If it works...

Huzzah! Now go to your Git Bash shell and if you have Python 3 installed, you can run the web server to read the configured website in the test directory. NOTE: Python 3 probably came with your Ubuntu installation, so you can run this next command in Ubuntu:

Run python -m http.server 8000

Out in Windows, open a web browser (like Chrome or Firefox) to localhost:8000 and check out your successfully built page.

erinmooney commented 2 years ago

At heading: Last step! Test whether ant works to build staticSearch I had an issue running 'ant'.

I got an issue: "Command 'ant' not found, but can be installed with: sudo apt install ant"

So, I ran: sudo apt install ant Then refreshed Ubuntu, but got an issue with the Buildfile (could not be found) BUILD FAILED

staticAnt_issue

ebeshero commented 2 years ago

@erinmooney We worked on this after class and found out a few things: Your system was not reading the environment path we'd set back to ant on the Windows side of your machine due, alas, to spaces in the directory path! So! We ran with your solution: installing ant on the Ubuntu linux environment.

We found your new Linux ant over in usr/share/ and that is where we copied the ant-contrib jar file, using shell commands in the Ubuntu shell.

For all reading this: you may not need to take these steps, but note there may be complications if your filepath to your Windows ant installation contains spaces! Erin and I are troubleshooting this.

jbg5721 commented 2 years ago

Downloading WSL on Windows 10 is the same process but you need to run the wsl --install command on Powershell. When opening PowerShell, run it as administrator.

When editing the system variables using sudo nano /etc/environment Press F3 and then Enter to save the added lines. To exit press ^X at the same time, you will probably need to hold shift when doing this.

arrowarchive commented 2 years ago

The last step I am missing is installing Python 3. I don't know if Pycharm and Python 3 are different, the configured Pycharm I had was on my former laptop, and I'm unsure if I need to configure it for this project. I also don't recall what I did to configure it.

tec5271 commented 2 years ago

Screenshot (17) Pretty sure I am having the same issue that Erin was having when attempting to run ant in ubuntu

ebeshero commented 2 years ago

@tec5271 We discovered the issue here was with Ubuntu locating the ant files. You had let Ubuntu go ahead and install ant, so we solved this by copying your ant-contrib jar file over to the apache-ant installation in /usr/share/... (This is where Ubuntu actually installs ant.) If anyone else is having this problem: Use cd /usr/share and then ls to look inside. You should find apache-ant in there. Inside that is the lib/ folder where ant-contrib would go. We used the cp command to copy from the /mnt/c/...path-to-ant/lib/ant-contrib.jar to /usr/share/apache-ant.../lib

You might not have to do that cp command at all. We could have tried sudo apt-install ant-contrib and that would probably have worked in Ubuntu.

NOTE: If Python isn't running over in Windows, you probably have Python3 in Ubuntu already. You can run the web server by navigating to staticSearch and into the test/ directory inside. Then (in Ubuntu shell) run: python3 -m http.server 8000 That should run the web server for you.