Maven构建机器学习 - 我如何使其工作?

时间:2015-03-03 11:54:12

标签: maven machine-learning pom.xml

我正在尝试编译并运行此存储库中的一些基本Java代码: https://github.com/jasebell/mlbookexamples

例如,在Java文件夹中,chapter2.BritneyDilemma。

我正在尝试用maven做这个(因为有一个pom.xml)但是我觉得有一些东西阻碍了我。我对Maven了解不多;我的背景是C和cmake。乍一看,我可以看到为什么人们讨厌Maven。该项目的pom.xml似乎没有完全配置/显得非常标准:

  • 它只会降低一些依赖关系,例如Br​​itneyDilemma需要classifier4J,但pom.xml中没有提到。
  • 当我执行mvn install / compile等任何简单命令时,输出到目标基本上没什么(它几乎是空的jar)。

我尝试了各种方法,例如:

  • 修改pom.xml以添加maven assembly plugin并运行mvn clean compile package。最多我设法得到一个打包pom.xml依赖项的jar,但由于没有classifier4j仍然无法编译BritneyDilemma(这在pom.xml中没有提到所以我不确定maven应该怎么知道这是一个要求/从哪里拉出来。
  • 远离maven,下载classifer4j并通过命令行进行编译。运行时错误和一些调查指出我错过了一些classifier4j dependency,我认为这是因为我离开了maven,否则这将被一些递归建筑所照顾。

这是一个库存构建尝试,不做任何修改/采用pom.xml:

~/projects/mlbookexamples/java (master) $ mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building mlbook
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/alex/projects/mlbookexamples/java/src/main/resources
Downloading: http://repo.springsource.org/libs-milestone//javax/batch/javax.batch-api/1.0/javax.batch-api-1.0.jar
34K downloaded  (javax.batch-api-1.0.jar)
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/alex/projects/mlbookexamples/java/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] No sources to compile
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] Surefire report directory: /home/alex/projects/mlbookexamples/java/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar {execution: default-jar}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /home/alex/projects/mlbookexamples/java/target/mlbookexamples-1.0-SNAPSHOT.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing /home/alex/projects/mlbookexamples/java/target/mlbookexamples-1.0-SNAPSHOT.jar to /home/alex/.m2/repository/com/datasentiment/mlbook/mlbookexamples/1.0-SNAPSHOT/mlbookexamples-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Wed Mar 04 08:38:56 NZDT 2015
[INFO] Final Memory: 33M/249M
[INFO] ------------------------------------------------------------------------
~/projects/mlbookexamples/java/target (master) $ java -jar mlbookexamples-1.0-SNAPSHOT.jar 
no main manifest attribute, in mlbookexamples-1.0-SNAPSHOT.jar

我正在运行arch linux。

1 个答案:

答案 0 :(得分:0)

要编译第2章,似乎没有要求获取pom.xml中列出的依赖项。

你可以简单地从chapter2文件夹中编译BritneyDilemma(记住要包含从下载的Classifier4J依赖项) http://sourceforge.net/projects/classifier4j/files/,这可以保存在chapter2文件夹中。

~/projects/mlbookexamples/java/src/chapter2 (master) $ javac -cp Classifier4J-0.6.jar BritneyDilemma.java 

然后你可以转到src文件夹并运行该类,再次引用chapter2文件夹中的classifier4j jar。

~/projects/mlbookexamples/java/src (master) $ java -classpath .:chapter2/Classifier4J-0.6.jar chapter2.BritneyDilemma 
brittany spears = 0.7071067811865475
brittney spears = 0.7071067811865475
britany spears = 0.7071067811865475
britny spears = 0.7071067811865475
briteny spears = 0.7071067811865475
britteny spears = 0.7071067811865475
briney spears = 0.7071067811865475
brittny spears = 0.7071067811865475
brintey spears = 0.7071067811865475
britanny spears = 0.7071067811865475
britiny spears = 0.7071067811865475
britnet spears = 0.7071067811865475
britiney spears = 0.7071067811865475
christina aguilera = 0.0
britney spears = 0.9999999999999998

您可能已经拥有了所需的日志库,但它可以通过软件包管理器获取,如libcommons-logging-java。

另外,一般来说使用eclipse要容易得多。只需创建一个新的Java项目,但将工作目录从缺省值更改为存储库中的java目录。创建一个新文件夹' lib'在这里并放入classifier4j jar。在eclipse中,右键单击classifier4j并添加到构建路径'。您现在只需单击BritneyDilemma或任何其他源(向lib添加依赖项并在必要时添加到构建路径),然后根据需要运行。

快乐的机器学习。