0

I am looking at this project: https://github.com/xtuhcy/gecco

It includes some demo code: https://github.com/xtuhcy/gecco/blob/master/src/test/java/com/geccocrawler/gecco/demo/MyGithub.java

I cloned the repo.

I'm trying to run the demo code but I can't figure out how.

I don't really understand how to use maven.

I managed to install maven and install the dependencies for the project.

mvn verify and mvn test both run without error

I found this article:

http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/

Which suggests doing something like this:

mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main"

But I can't figure how what the value of mainClass should be.

I have tried:

mvn exec:java -Dexec.mainClass="com.geccocrawler.gecco.demo.MyGithub" mvn exec:java -Dexec.mainClass="test.java.com.geccocrawler.gecco.demo.MyGithub" 

both result in java.lang.ClassNotFoundException

I also tried:

java -cp target/gecco-1.3.1.jar com.geccocrawler.gecco.demo.MyGithub java -cp target/gecco-1.3.1.jar test.java.com.geccocrawler.gecco.demo.MyGithub 

neither worked

1
  • It seems like pretty much everyone uses IDEs to run Java projects. I downloaded IntelliJ, imported the project, and was able to run the file that way. Commented Nov 10, 2019 at 2:45

1 Answer 1

1

Ugh, you've made everything right, the issue is that the class that you're trying to run is in src/test/java... and not in src/main/java/. I'll explain.

Maven is pretty advanced build tool, it differentiates between sources that will reach "production" eventually and the tests that are executed during the build process.

More specifically it provides different classpaths for them, so that for tests for example you'll want to have a testing framework in a classpath and for production its irrelevant.

Tests should be tests and not something with "main" method (tests unlike real classes do not have the main method and are driven by testing framework). This is maven's "by-the-book" approach.

But this project for some reason uses the classes with method main in folder that should contain tests (I admin, I've seen this from time to time in other projects as well).

So you need to run the classs with the "classpath" of tests (otherwise maven won't see this class at all), here is how its done:

mvn exec:java -Dexec.mainClass="com.geccocrawler.gecco.demo.MyGithub" -Dexec.classpathScope=test 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.