Unmarked class

Asked

Viewed 144 times

0

I am testing a . jar where I will pass named parameters on the command line, etc. The problem is that you are not finding my main class. Somebody help me?

package appOptions;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class Main {

    public static void main(String[] args) throws ParseException {
        Options options = new Options();
        options.addOption("t", true, "Teste");

        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse( options, args);

        if(cmd.hasOption("t")) {
            System.out.println("Funcionou");
        }
        else {
            System.out.println("Não funcionou");
        }

    }

}

And my file pom:

<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>com.roknauta</groupId>
    <artifactId>appOptions</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.roknauta.addOption.src.main.java.addOptions.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.3.1</version>
        </dependency>
    </dependencies>
</project>

I’ve changed course and nothing.

  • Try the plugin Maven-Assembly-plugin follows the documentation. https://maven.apache.org/guides/mini/guide-assemblies.html

  • Add your full class, including package name and Imports.

  • Ready @Felipemarinho

1 answer

0

Change that:

<mainClass>com.roknauta.addOption.src.main.java.addOptions.Main</mainClass>

To:

<mainClass>appOptions.Main</mainClass>
  • Wasn’t :( . Erro: Não foi possível localizar nem carregar a classe principal addOption.Main

  • @Douglas You put in your pom.xml <mainClass>appOptions.Main</mainClass> or `<mainClass>addOptions.Main</mainClass> ? Also, how are you creating/executing the jar?

  • I tested the 2 ways. I am creating with the mvn package and running with the java -jar <arquivo>

  • @Douglas Instead of using mvn package, try to use mvn clean package.

Browser other questions tagged

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