CompEvol / beast2

Bayesian Evolutionary Analysis by Sampling Trees
www.beast2.org
GNU Lesser General Public License v2.1
240 stars 84 forks source link

Running into errors when following "WRITING A BEAST 2.7 PACKAGE" guide #1128

Closed jacklo225 closed 1 year ago

jacklo225 commented 1 year ago

Hi, When following the guide, I get stuck at the debug configuration/run step. I'm running the main function in beast.pkgmgmt.launcher.BeastLauncher with project MyPackage, and get a ClassNotFoundException. The guide said to run BeastMain.java in beast.app.beastapp which doesn't exist any more so I looked around and thought beast.pkgmgmt.launcher.BeastLauncher might serve the same purpose.

java.lang.ClassNotFoundException: javafx/application/Application at beast.pkgmgmt.BEASTClassLoader.forName(BEASTClassLoader.java:133) at beast.pkgmgmt.launcher.BeastLauncher.run(BeastLauncher.java:697) at beast.pkgmgmt.launcher.BeastLauncher.main(BeastLauncher.java:44)

Has anyone run into this error before? Thanks!

rbouckaert commented 1 year ago

Thanks for the bug report -- indeed, the guide says beast.app.beastapp but it should be beastfx.app.beast. I updated the guide for this.

The ClassNotFoundException should not happen when using the recommended Zulu JDK that includes JavaFX. If you use a different JDK then you may need to install JavaFX separately, or provide java with some setting. This is a bit tedious and error prone to set up, which is why the Zulu JDK with JavaFX is recommended.

Just to clarify, BeastLauncher loads the packages from the package directory and attempts to install the BEAST.base and BEAST.app packages if not already installed. It then proceeds with calling beastfx.app.beast.BeastMain

Let me know if you run into any more trouble with the guide.

jacklo225 commented 1 year ago

Thanks for the response! I've seemed to fix the javafx ClassNotFoundException error, but now I'm running into an Error 1017. I do have beast2 on the classpath of BeastFX and both beast2 and BeastFX on the classpath for MyPackage, and the output seems to indicate that MyPackage v0.0.1 is being loaded, but the F84 class isn't being recognized. Also, just to double-check, beastfx.app.beast appears in BeastFX and not beast2, right?

Random number seed: 1695016618082

File: testF84.xml seed: 1695016618082 threads: 1
Loading package starbeast3 v1.1.7 SA v2.1.1 BEAST.base v2.7.5 MultiTypeTree v8.0.0 BEASTLabs v2.0.2 BEAST.app v2.7.5 ORC v1.1.2   MyPackage v0.0.1 BEAST.base v2.7.5 BEAST.app v2.7.5 

Error 1017 parsing the xml input file

Class could not be found. Did you mean beastlabs.inference.ML?
Perhaps a package required for this class is not installed?

Error detected about here:
  <beast>
      <input id='F84' spec='F84'>
rbouckaert commented 1 year ago

Thanks for you patience -- the spec attribute says F84, bit should be mypackage.evolution.substitutionmodel.F84 (in v2.6, beast.evolution.substitutionmodel was part of the default namespace, so did not require specifying explicitly. For v2.7, packages cannot share java namespaces, so either the full class path needs to be specified in the spec attribute, or the java package name added to the namespace attribute at the top of the XML).

Note that when running the XML in Eclipse it is necessary to specify the -version_file version.xml in the arguments.

You are right the beastfx.app.beast appears in BeastFX and not beast2.

I made a few more fixes to the tutorial and hope everything should be running smooth now, but let me know if you run into any other issues.

jacklo225 commented 1 year ago

It's working well now, thanks for the assistance.

jjmccollum commented 4 months ago

@rbouckaert I'm afraid I'm getting stuck on the same step in the updated tutorial with the latest version of BEAST 2. I'm using BEAST 2.7.7 with Azul Zulu 22.32.15 JDK on Windows 11. I've set up the projects for beast2, BeastFX, and MyPackage in Eclipse (where BeastFX has beast2 on its build path, and MyPackage has beast2 and BeastFX on its build path). If I debug BeastMain.java (in BeastFX) as a Java application, then the "Open file" dialog box opens up as expected. But if I go to the "Debug Configurations..." panel, change the project for this configuration from "BeastFX" to "MyPackage" (leaving "beastfx.app.beast.BeastMain" as the main class), modify the arguments as specified, and then click "Debug", I get the following error message:

Error: Could not find or load main class beastfx.app.beast.BeastMain
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

In the next step of the tutorial, you also state that "To run in debug mode, go the the main Eclipse Run menu, choose Debug configurations…, select 'BeastMCMC' under Java Application, then press the Debug button to start." But I do not see any configuration called "BeastMCMC" here. The only configuration I see under the Java Application list is "BeastMain", which is the only class I tried to debug earlier.

Is there something I'm missing?

jjmccollum commented 4 months ago

Okay, I think I've found a solution, although I'm not sure why it works. If I go into the Debug Configuration for BeastMain that I modified to have a different project and arguments, I just have to go to the JRE tab and change the project execution environment from "Java-SE 22 (jre)" to "Java-SE 21 (zulu 22)":

image

rbouckaert commented 4 months ago

The main class should be beastfx.app.beast.BeastMain not BeastMCMC. Thanks for point that out -- it should be fixed now.

Glad to see it is working regardless.

Just a word of caution: be careful developing against Java 22 -- currently, BEAST uses Java 17 since this was the current LTS version at the release of v2.7.0. Java 22 is not an LTS version. This means when building a package with Java 22 it will not run with Java 17 since the class files will not be recognised (unless you explicitly state that class versions should be for Java 17, e.g. by setting the target attribute on the javac element in the ant build.xml file).

jjmccollum commented 4 months ago

Thank you for warning me about that! I downloaded Azul Zulu 17 and set the execution environment and java version to Java 17 in Eclipse and for building with ant. The unit tests, debug configurations, and builds are all still successful, so the package should be targeted for the right version of Java now.