Jar does not perform

Asked

Viewed 417 times

-1

I am using netbeans and Maven. When I try to run the jar file in cmd, the error shown is "no major manifest attribute in".

Follow the nbactions.xml code:

<?xml version="1.0" encoding="UTF-8"?>
<actions>
        <action>
            <actionName>run</actionName>
            <packagings>
                <packaging>jar</packaging>
            </packagings>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
            </goals>
            <properties>
                <exec.args>-classpath %classpath br.com.swing.Main</exec.args>
                <exec.executable>java</exec.executable>
                <exec.workingdir>C:\Users\Fabio\Documents\NetBeansProjects\EnterpretadorQRcode\src\main\java\br\com\swing</exec.workingdir>
            </properties>
        </action>
        <action>
            <actionName>debug</actionName>
            <packagings>
                <packaging>jar</packaging>
            </packagings>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
            </goals>
            <properties>
                <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath br.com.swing.Main</exec.args>
                <exec.executable>java</exec.executable>
                <jpda.listen>true</jpda.listen>
                <exec.workingdir>C:\Users\Fabio\Documents\NetBeansProjects\EnterpretadorQRcode\src\main\java\br\com\swing</exec.workingdir>
            </properties>
        </action>
        <action>
            <actionName>profile</actionName>
            <packagings>
                <packaging>jar</packaging>
            </packagings>
            <goals>
                <goal>process-classes</goal>
                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
            </goals>
            <properties>
                <exec.args>-classpath %classpath br.com.swing.Main</exec.args>
                <exec.executable>java</exec.executable>
                <exec.workingdir>C:\Users\Fabio\Documents\NetBeansProjects\EnterpretadorQRcode\src\main\java\br\com\swing</exec.workingdir>
            </properties>
        </action>
    </actions>
segue codigo do pom.xml

``` lang-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>Enterpretador</groupId>
    <artifactId>EnterpretadorQRcode</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>com.1stleg</groupId>
            <artifactId>jnativehook</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <name>EnterpretadorQRcode</name>
</project>

2 answers

1

You need to add the main class in the file pom.xml. Browse the plugins tag and add the following:

<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>3.8.0</version>
         <configuration>
            <archive>
               <manifest>
                  <mainClass>br.com.renan.MinhaClasse</mainClass>
               </manifest>
            </archive>
         </configuration>
      </plugin>
   </plugins>
</build>
  • I added this plugin information in pom.xml. started presenting this error: Some problems Were encountered while building the effective model for Enterpretador:Enterpretadorqrcode:jar:1.0 'build.plugins.plugin.version' for org.apache.Maven.plugins:Maven-jar-plugin is Missing. @ line 23, column 20 It is highly Recommended to fix These problems because they threaten the Stability of your build. For this Reason, Future Maven versions Might no longer support building such malformed Projects.

  • @Fabiodasilvagarcia I think the version is missing, I added the version tag in the reply

  • I added the following line: <version>3.1.1</version> the error has now changed this stating that it is not finding the jnativehook dependency classes

  • @Fabiodasilvagarcia what is the message?

  • Follow print screen link link

  • In Netbeans try a clean and build

  • It remains the same thing. the jar file is 13KB and too small to be with the dependencies

  • Look this, maybe I can help

Show 3 more comments

0

I managed to solve the problem by adding a build plugin I do not know how it works right. But this way it creates two jars. One with classes without dependencies and one with dependencies. Follows lines added in pom:

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>  
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>br.com.swing.Main</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

Browser other questions tagged

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