OCR4all / LAREX

A semi-automatic open-source tool for Layout Analysis and Region EXtraction on early printed books.
MIT License
179 stars 33 forks source link

cannot build LAREX on macOS #253

Closed jthale76 closed 3 years ago

jthale76 commented 3 years ago

Hi, LAREX looks perfect for our digital humanities project here at the University of Georgia (USA) but I am not very knowledgeable about web application deployment. When I follow the macOS installation directions on Big Sur (11.4) the maven build fails with an error about API incompatibility. I'll be grateful for any suggestions about how to proceed! -john

[INFO] --------------------------< de.uniwue:Larex >--------------------------- [INFO] Building Larex 0.5.0 [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Larex --- [INFO] Deleting /Users/john/projects/quechua/LAREX/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Larex --- [WARNING] Using platform encoding (ISO8859-1 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /Users/john/projects/quechua/LAREX/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Larex --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 61 source files to /Users/john/projects/quechua/LAREX/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Larex --- [WARNING] Using platform encoding (ISO8859-1 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /Users/john/projects/quechua/LAREX/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ Larex --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Larex --- [INFO] No tests to run. [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ Larex --- [WARNING] Error injecting: org.apache.maven.plugin.war.WarMojo com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties at org.apache.maven.plugin.war.WarMojo.(Unknown Source) while locating org.apache.maven.plugin.war.WarMojo

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project Larex: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.2:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.2' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: Cannot access defaults field of Properties

realm = plugin>org.apache.maven.plugins:maven-war-plugin:2.2 strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy urls[0] = file:/Users/john/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.2/maven-war-plugin-2.2.jar urls[1] = file:/Users/john/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar urls[2] = file:/Users/john/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar urls[3] = file:/Users/john/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar urls[4] = file:/Users/john/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar urls[5] = file:/Users/john/.m2/repository/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar urls[6] = file:/Users/john/.m2/repository/org/codehaus/plexus/plexus-io/2.0.2/plexus-io-2.0.2.jar urls[7] = file:/Users/john/.m2/repository/org/codehaus/plexus/plexus-archiver/2.1/plexus-archiver-2.1.jar urls[8] = file:/Users/john/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.15/plexus-interpolation-1.15.jar urls[9] = file:/Users/john/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar urls[10] = file:/Users/john/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar urls[11] = file:/Users/john/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar urls[12] = file:/Users/john/.m2/repository/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar urls[13] = file:/Users/john/.m2/repository/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar Number of foreign imports: 1 import: Entry[import from realm ClassRealm[maven.api, parent: null]]

maxnth commented 3 years ago

Are you using Java 8 to build LAREX?

jthale76 commented 3 years ago

Thanks for replying Maximilian.. my versions are:

bash-3.2$ java -version openjdk version "16.0.1" 2021-04-20 OpenJDK Runtime Environment Homebrew (build 16.0.1+0) OpenJDK 64-Bit Server VM Homebrew (build 16.0.1+0, mixed mode, sharing)

bash-3.2$ mvn -version Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: /usr/local/Cellar/maven/3.8.1/libexec Java version: 16.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/16.0.1/libexec/openjdk.jdk/Contents/Home Default locale: en_US, platform encoding: ISO8859-1 OS name: "mac os x", version: "11.4", arch: "x86_64", family: "mac"

I got OpenJDK by issuing "brew install openjdk" the command with "cask" in the Larex macOS build instructions did not work for me... maybe it's from an old version of homebrew?

outside of homebrew I also have "Java 8 Update 291" installed. Do I need to put this openjdk ahead of jdk1.8.0_121 on my PATH?

maxnth commented 3 years ago

LAREX currently only builds with Java 8 so setting export JAVA_HOME=`/usr/libexec/java_home -v 1.8` (or something similar according to your setup / OS) before building should hopefully fix this problem.

the command with "cask" in the Larex macOS build instructions did not work for me... maybe it's from an old version of homebrew?

I wouldn't be surprised if the macOS build instructions are a bit outdated, changing brew cask install java to brew install openjdk@8 would probably work for newer macOS / homebrew versions. I'm not a macOS user so I sadly can't verify this.

jthale76 commented 3 years ago

okay the build succeeds with JAVA_HOME set to the 1.8 version! I've copied the .war file into tomcat

bash-3.2$ ls -l /usr/local/Cellar/tomcat/10.0.6/libexec/webapps/ total 228640 drwxr-x--- 5 john admin 160 Jun 4 10:13 Larex -rw-r--r-- 1 john admin 117063041 Jun 4 10:13 Larex.war drwxr-x--- 13 john admin 416 May 8 11:24 ROOT drwxr-x--- 60 john admin 1920 May 8 11:24 docs drwxr-x--- 8 john admin 256 May 8 11:24 examples drwxr-x--- 7 john admin 224 May 8 11:24 host-manager drwxr-x--- 9 john admin 288 May 8 11:24 manager

and tomcat is running:

bash-3.2$ brew services Name Status User Plist tomcat started john /Users/john/Library/LaunchAgents/homebrew.mxcl.tomcat.plist

but I get this message upon browsing localhost:8080

HTTP Status 404 – Not Found Type Status Report Message The requested resource [/Larex] is not available Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Do I need to tweak something else?

maxnth commented 3 years ago

but I get this message upon browsing localhost:8080

Is it reachable under localhost:8080/Larex/?

jthale76 commented 3 years ago

uh, no not reachable. I used the correct URL, and the error message acknowledges that the problem is more about the "availability" of /Larex Do I need to configure something to make it "available" ?

maxnth commented 3 years ago

Do I need to configure something to make it "available" ?

Usually copying / linking the war file after a successful build and restarting / reloading the tomcat service should suffice.

The only other possibility I can think of right now is that it's rights related (in my setup the webapp directories are owned by a tomcat user) but this might as well differ depending on the OS and / or how tomcat was installed.

jthale76 commented 3 years ago

hmm, on the brew setup they're all owned by my user account:

bash-3.2$ ls -al total 228640 drwxr-x--- 9 john admin 288 Jun 4 10:13 . drwxr-xr-x 11 john admin 352 Jun 4 10:06 .. drw-r----- 5 john admin 160 Jun 4 10:13 Larex -rwxr-xr-x 1 john admin 117063041 Jun 4 10:13 Larex.war drwxr-x--- 13 john admin 416 May 8 11:24 ROOT drwxr-x--- 60 john admin 1920 May 8 11:24 docs drwxr-x--- 8 john admin 256 May 8 11:24 examples drwxr-x--- 7 john admin 224 May 8 11:24 host-manager drwxr-x--- 9 john admin 288 May 8 11:24 manager

This post https://www.codejava.net/java-ee/servlet/solved-tomcat-error-http-status-404-not-found suggests checking web.xml

but there are several such files find . -name "web.xml" ./docs/appdev/sample/web/WEB-INF/web.xml ./docs/WEB-INF/web.xml ./manager/WEB-INF/web.xml ./examples/WEB-INF/web.xml ./ROOT/WEB-INF/web.xml ./host-manager/WEB-INF/web.xml

I'm not sure which is relevant. Is there any way to check which WebServelets are actually defined?

jthale76 commented 3 years ago

hmm, the "Larex" directory seems to be unreadable regardless of how I set the unix permission bits

The folder “Larex” can’t be opened because you don’t have permission to see its contents.

is that important?

jthale76 commented 3 years ago

Larex is there, just not "available"

Message The requested resource [/Larex/] is not available

Screen Shot 2021-06-04 at 11 11 13 AM
jthale76 commented 3 years ago

I tried rebuilding everything fresh and now the tomcat manager console reports

FAIL - Application at context path [/Larex] could not be started

is there a log or something that I could check to find out why?

jthale76 commented 3 years ago

I noticed that tomcat was not using Java 1.8, so I forced that by setting JAVA_HOME in setenv.sh as described here but it did not help, I still get the message

FAIL - Application at context path [/Larex] could not be started

however I can confirm that tomcat shows JVM version 1.8.0_282-bre_2021_01_20_16_06-b00

maxnth commented 3 years ago

is there a log or something that I could check to find out why?

Log files should be under CATALINA_HOME/logs (CATALINA_HOME is probably at /opt/tomcat/ or somewhere similar) but I also saw some operating systems log directly to journalctl so this probably heavily depends on your setup as well.

I sadly can't assist much with the tomcat / macOS setup (I will ask a colleague who's a macOS user though whether it works for him) but I just updated my LAREX Docker image which I use myself for testing and which should be more or less platform agnostic.

The repository can be found here: https://github.com/maxnth/LAREX_Docker and the README should contain most information for getting the container running. I mostly used the container myself so the documentation might be a bit lacking / some use cases might not be covered, so feel free to open an issue if something isn't working as intended / expected.

jthale76 commented 3 years ago

thanks for the pointer to the Docker stuff... maybe I'll try that path, if the published directions really turn out to be irreparably wrong. But there ought to be a way to solve this... once upon a time, java was supposed to be "write-once, run anywhere" :)

My log shows

05-Jun-2021 12:27:15.508 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal Context [/Larex] startup failed due to previous errors

where that previous error is

Error configuring application listener of class [org.springframework.web.context.ContextLoaderListener]

Other people out there on the web suggest that this situation may arise when a developer has forgotten to include Spring or Maven dependencies in the Web Deployment Assembly. In $CATALINA_HOME/Larex/WEB-INF/lib I find plenty of jar files with "spring" in their namee.g. /usr/local/Cellar/tomcat/10.0.6/libexec/webapps/Larex/WEB-INF/lib/spring-web-5.1.0.RELEASE.jar

but nothing named "maven". Should there be some Maven-related jars in there? The end of the build process mentions some directory .m2/repository

[INFO] --- maven-install-plugin:2.4:install (default-install) @ Larex --- [INFO] Installing /Users/john/projects/quechua/LAREX/target/Larex.war to /Users/john/.m2/repository/de/uniwue/Larex/0.5.0/Larex-0.5.0.war [INFO] Installing /Users/john/projects/quechua/LAREX/pom.xml to /Users/john/.m2/repository/de/uniwue/Larex/0.5.0/Larex-0.5.0.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.101 s [INFO] Finished at: 2021-06-05T12:38:40-04:00 [INFO] ------------------------------------------------------------------------

I don't understand what it does. This .m2 directory contains lots of maven-related jars e.g. /Users/john/.m2/repository/org/apache/maven/maven-core/2.0.6/maven-core-2.0.6.jar /Users/john/.m2/repository/org/apache/maven/maven-core/2.0.9/maven-core-2.0.9.jar /Users/john/.m2/repository/org/apache/maven/maven-core/3.0/maven-core-3.0.jar

As directed in the instructions, I copied the Larex.war file into the location specified within my tomcat installation.

Below is the full log showing how the listener can't get started:

04-Jun-2021 18:08:20.988 SEVERE [http-nio-8080-exec-6] org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class [org.springframework.web.context.ContextLoaderListener] java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:756) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470) at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4589) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5121) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1396) at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:703) at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:223) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:689) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:770) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:211) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:668) at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:378) at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:56) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1401) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224) ... 48 more

jthale76 commented 3 years ago

it works if you downgrade to tomcat@9 making sure to also specify Java 1.8 for the build export JAVA_HOME=/usr/local/Cellar/openjdk@8/1.8.0+282/libexec/openjdk.jdk/Contents/Home

and in $CATALINA_BASE/bin/setenv.sh

ie

Jun 7 18:14 2021 /usr/local/Cellar/tomcat@9/9.0.46//libexec/bin/setenv.sh Page 1

1   #!/usr/bin/env bash
2   
3   JAVA_HOME=/usr/local/Cellar/openjdk@8/1.8.0+282/libexec/openjdk.jdk/Contents/Home
maxnth commented 3 years ago

Great to hear that it's now working. I'll add Tomcat <= 9 to the README.