perf_tester
perf_tester

Reputation: 1

Gatling : Scala - Could not find or load main class Engine

I am getting error Could not find or load main class Engine while running the simulation through command line. I used below command to create the jar file.

mvn clean scala:compile assembly:single package

Folder Structure

Maven - 3.6.3 Intellij - 2021.1 Scala - 2.13.10 Gatling - 3.9.0 JDK - 1.8

Below is the POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>io.gatling.demo</groupId>
  <artifactId>gatling-maven-plugin-demo-scala</artifactId>
  <version>3.9.0</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <gatling.version>${project.version}</gatling.version>
    <gatling-maven-plugin.version>4.2.9</gatling-maven-plugin.version>
    <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
    <scala-maven-plugin.version>4.8.0</scala-maven-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

 
  <build>
    <resources>
      <resource>
        <directory>src/test/resources</directory>
      </resource>
    </resources>    
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>io.gatling</groupId>
          <artifactId>gatling-maven-plugin</artifactId>
          <version>${gatling-mvn-plugin.version}</version>
          <configuration>
            <configFolder>src/test/resources</configFolder>
            <simulationsFolder>src/test/scala</simulationsFolder>
            <resultsFolder>src/results</resultsFolder>
            <simulationClass>testrunner.testsimuation1</simulationClass>
            <jvmArgs>
              <jvmArg>-Dsimulation=testsimuation1</jvmArg>
              <jvmArg>-Xmx6g</jvmArg>
              <jvmArg>-Xms2g</jvmArg>
            </jvmArgs>
          </configuration>
        </plugin>
        <plugin>
          <groupId>net.alchim31.maven</groupId>
          <artifactId>scala-maven-plugin</artifactId>
          <version>4.4.1</version>
          <executions>
            <execution>
              <id>scala-compile-first</id>
              <phase>process-resources</phase>
              <goals>
                <goal>add-source</goal>
                <goal>compile</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>3.2.0</version>
          <configuration>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
              <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <mainClass>io.gatling.app.Gatling</mainClass>
              </manifest>
            </archive>
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id> <!-- this is used for inheritance merges -->
              <phase>package</phase> <!-- bind to the packaging phase -->
              <goals>
                <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

I tried moving src/test -> src/main but it threw the compilation error. Using this tool for the first time and struggling to resolve the issues.

I tried few solutions from other threads. It didn't help.

Thanks

Upvotes: 0

Views: 817

Answers (1)

St&#233;phane LANDELLE
St&#233;phane LANDELLE

Reputation: 6623

The Engine class is only supposed to be used as a helper to launch with a "Right Click" when using your IDE.

Using this tool for the first time and struggling to resolve the issues.

You're using maven. The way you're supposed to be running Gatling with maven is to run mvn gatling:test, see gatling-maven-plugin's documentation.

Whatever else you're doing with maven-assembly-plugin is custom development, not really related to Gatling.

Note: if you're looking for handling Gatling deployments, Gatling Enterprise is an option.

Upvotes: 0

Related Questions