简体   繁体   中英

Java executable jar file with missing package and its contents

I inherited java maven project composed of cucumber, junit and selenium frameworks which I am new to except Junit. I noticed its pkg name is under src/test/java instead of src/main/java .

src/test/java
    com.somewhere.test
        FooRunner.java

I was told that I can run junit test from FooRunner class by right click Run as > Junit Test in eclipse IDE.

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resources/com/sowhere/test/features",tags = {"@Test"}, plugin = {
    "pretty",
    "junit:target/results.xml",
    "html:target/cucumber"},
    dryRun = false)

public class FooRunner {
  public static void main(String[] args) {
    
  }
}

I was able to run its unit test just fine. My question is I need this mvn project to generate executable jar file then be able to run its unit test from

java -jar Foo.jar

I followed this thread to Running Cucumber tests directly from executable jar by updating pom.xml file and adding public static void main method however when I executed the jar file I received following error msg..

Error: Could not find or load main class com.somewhere.test.FooRunner

I changed jar to zip then unpacked it all. Surprisingly I didn't see pkg name com.somewhere.test but I see other pkgs of external libraries such as cucumber and etc. Yes META-INF/MANIFEST.MF is there with proper data I believe.

I am curious to know why the pkg (ie com.somewhere.test) is missing along with class (ie FooRunner.class)

Update:

I found an answer from this thread: How can I include test classes into Maven jar and execute them?

Maven has a src/main/java/ whose classes go into the product jar, and src/main/test/java/ whose classes go in a test jar (or are just tested), not needed to run the application. This separation makes sence. The test jar depends on the production jar too, as it tests those classes.

This test jar can be created with goal jar:test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM