0

I’m trying to use Mallet for the textual analysis of medieval English romances. Mallet is coded in Java and runs from the Command Line.

When I import a text file into Mallet with: bin\mallet import-dir --input sample-data\web\en\Chaucher.text --output tutorial.mallet --keep-sequence --remove-stopwords

I get a Java classpath error: Could not find or load main class Files\Mallet\Mallet-2.0.8\class;C:\Program Caused by: java.lang.ClassNotFoundException: Files\Mallet\Mallet-2/0/8\class;C:\Program

Suggested solutions found through Google failed. When I posted this question Stackoverflow automatically referred me to How do I resolve ClassNotFoundException?

Following this, I set the classpath by running Java -classpath c:\program files\mallet\mallet-2.0.8\sample-data\web\en. I still got the same error (Error: Could not find or load main class files\mallet\mallet-2.0.8\sample-data\web\en Caused by: java.lang.ClassNotFoundException: files\mallet\mallet-2.0.8\sample-data\web\en) - note, though, being unfamiar with Java I may have misunderstood this post.

I am now lost, unsure if my environment variables and paths are correctly set or if my Command Line Java code is incorrect. I believe I have correctly followed all the installation instructions, including setting environment and paths for Java, Ant and Mallet, as well advice in Stackoverflow posts.

I would, then, be most grateful for suggestions as to where I might go from here.

Background

I am running Windows 10 Professional on a Dell T7910 Workstation with 64 GB of memory.

I have 1) installed: Java, Ant and Mallet as instructed by various Mallet websites.* 2) have modified environment variables as follows:

Java_Home - C:\Program Files\Java\jdk-17.0.2 (This is in System Variables)

Mallet_Home - C:\Program Files\Mallet\Mallet-2.0.8 (This is in System Variables)

Ant_Home - c:\Program Files\Ant (I have this in User Variables rather than System Variables. Could this be a problem?)

My Paths are:
%ant_home%\bin
C:\Program Files\Java\jdk-17.0.2\Bin
%Mallet_Home%\
C:\Program Files\Common Files\Oracle\Java\javapath
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\ProgramData\Oracle\Java\javapath

I have successfully installed Mallet, as when I run bin\mallet, I get the verifying response, Mallet 2.0 commands:

My Mallet directory structure is as follows. The program is installed in: c:\program files\mallet This directory has four sub directories.

cc
class
mallet
mallet-2.0.8 (Mallet-2.0.8 has the following eight(8) sub directories)

bin
class
dist
lib
sample-data (which includes: \web\en\Chaucer.txt)
src
stoplists
test

with Chaucer.txt being the text file I want to load into Mallet (could this be the problem? I have read that “import-dir is designed to take multiple directories as input.” (Trick to use file paths with spaces in Mallet (Terminal, OSx)?).

I am running my Java classpath and Mallet import code from: c:\program files\mallet\mallet-2.0.8.

My thanks in advance for anyone who can advise me how I should set my Java classpaths when using Mallet.


  • I consulted the following webpages for installing and using Mallet:

https://mimno.github.io/Mallet/import
https://programminghistorian.org/en/lessons/topic-modeling-and-mallet

Postings I reviewed for answers to my path problem include:

Running MALLET on Windows; could not find or load main class cc.mallet.classify.tui.Text2Vectors Using Mallet on Cygwin
Error: Could not load or find main class language
Mallet SimpleTagger Classpath
Trick to use file paths with spaces in Mallet (Terminal, OSx)?
How do I resolve ClassNotFoundException?

Nivek
  • 1
  • 2
  • Given the presence of spaces in the path, you need to enclose the value of the classpath parameter in double quotes (i.e. instead of `-classpath c:\program files\mallet\mallet-2.0.8\sample-data\web\en`, you need to use `-classpath "c:\program files\mallet\mallet-2.0.8\sample-data\web\en"`, otherwise the part after the space is considered the classname you're trying to run. – Mark Rotteveel Feb 13 '22 at 08:55
  • Thanks for your suggestion. I very much appreciate it. – Nivek Feb 13 '22 at 17:16
  • Thanks for your suggestion. I very much appreciate it. Unfortunately, it did not work. Since my post I have tired very many combinations of environment variables and paths as well as command prompts. None of them have worked. I assume I am having a Java problem. For some reason I cannot fathom, I am unable to specify to Java a/the path(s) to the relevant Mallet sub directories - or at least this i how I understand the problem. Quite a few Mallet users have had this problem, but were able to overcome. Their solutions have not worked for me, though. Thanks again for your suggestion. – Nivek Feb 13 '22 at 17:22
  • The error shown in your question happens when using `java -classpath C:\program Files\Mallet\Mallet-2.0.8\class;C:\Program files\.... ClassNameToStart` instead of `java -classpath "C:\program Files\Mallet\Mallet-2.0.8\class;C:\Program files\...." ClassNameToStart`. There is nothing more to it. If your application is using a launcher script that doesn't properly handle spaces in paths, then consider installing the program in a path without spaces (i.e. *not* in `C:\Program Files`). – Mark Rotteveel Feb 13 '22 at 17:26
  • Tried this before to no avail Do I need to specify where my Mallet Java jar files are installed? Reviewed https://www.geeksforgeeks.org/how-to-add-jar-file-to-classpath-in-java/ and ran: java -classpath /classes;"C:\Program Files\Mallet\mallet-2.0.8\lib\*" Only to get an explanation of the Java classpath command. Any suggestions as to my error? My assumption now is that I need to set a Java classpath to the subdirectory were my Mallet Java jar files are stored. Do you agree? If so, how would you suggest I do this? Thanks again, for your suggestion. I much appreciate it. – Nivek Feb 15 '22 at 16:40
  • You're quoting part of your classpath instead of the classpath itself. That is, you should have used `java -classpath "/classes;C:\Program Files\Mallet\mallet-2.0.8\lib*"` (though that `/classes` looks incorrect to me). I have no idea what mallet is, or how it is installed. Your problem isn't even really a Java problem, but the basic functioning of arguments in command prompts/shells. – Mark Rotteveel Feb 15 '22 at 16:40
  • Thanks for all your suggestions, but I solved the problem by uninstalling Java, Ant and Mallet and then reinstalling them. Problem was probably that I installed Mallet in c:\Program Files\Mallet. When I reinstalled Mallet, I installed it in C:\Mallet. So far it seems to be working. Thanks again everyone for your suggestions. I very much appreciate them – Nivek Feb 17 '22 at 15:40
  • Which is what I suggested earlier (_"[..] then consider installing the program in a path without spaces (i.e. not in `C:\Program Files`)"_) – Mark Rotteveel Feb 17 '22 at 15:42

0 Answers0