Run the Maven java project via terminal?

Asked

Viewed 2,733 times

0

I did a Maven project on Eclipse, I installed a Mahout dependency on pom.xml, I made the code and it works beautiful, it’s beautiful. But I have to run it on a virtual machine, that is without Eclipse. How do I run my project on the virtual machine? I have a little experience in java know that an executable is generated, but what exactly I have to pass to the virtual machine and how to run via terminal?

The tree of my project is this, my main code is in App.java. data.csv is the input file, the rest was generated automatically.

Recommender/
├── data
│   └── data.csv
├── pom.xml
├── src
│   ├── main
│   │   └── java
│   │       └── com
│   │           └── predict
│   │               └── Recommender
│   │                   └── App.java
│   └── test
│       └── java
│           └── com
│               └── predict
│                   └── Recommender
│                       └── AppTest.java
└── target
    ├── classes
    │   ├── com
    │   │   └── predict
    │   │       └── Recommender
    │   │           └── App.class
    │   └── META-INF
    │       ├── MANIFEST.MF
    │       └── maven
    │           └── com.predict
    │               └── Recommender
    │                   ├── pom.properties
    │                   └── pom.xml
    └── test-classes
        └── com
            └── predict
                └── Recommender
                     └── AppTest.class

I installed Maven on the virtual machine ran Hello World so I added my code inside the App.java and added the dependency inside the pom.xml and ran the code strings:

mvn package

java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

But my gave the following mistake:

Exception in thread "main" java.lang.NoClassDefFoundError: 
org/apache/mahout/cf/taste/model/DataModel
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at 
 sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at 
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: 
org.apache.mahout.cf.taste.model.DataModel
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more
  • Ever tried to use mvn clean install?

  • But using mvn install would have to rearrange my directories?

  • So, how’s your pom.xml?

  • Take the test with the mvn clean install. It should probably work. If it goes wrong, edit the question to post the error.

  • 1

    Do you want to run the application with Maven or generate a jar with dependencies that runs without Maven? In the first case you probably want to use something like mvn exec:java -Dexec.mainClass="com.predict.Recommender.App", in the second there are several options with plugins Maven, since generate a Uber with all dependencies up to exporting dependencies to a lib folder and generating a jar with a proper MANIFEST.MF.

  • I wanted to run the application, no need to have the isntal Maven. But I installed the dependencies through the Maven

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.