I have a task to do so that the application would be launched with the command:

java –jar tracker.jar.

I added a menifest from https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

But I still write:

 Mac-mini-Pavel:tracker pavel$ java –jar tracker.jar Error: Could not find or load main class –jar 

I in this block from the original on the site changed only this line

  <mainClass>ru.pravvich.start.StartUI</mainClass> 

The rest left as it was. Tell me maybe you need to add something else? In general, my manifesto looks like this:

 <build> <plugins> <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>ru.pravvich.start.StartUI</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> 
  • Use a hyphen instead of a dash: -jar instead of –jar . - Roman
  • The same does not help. - Pavel
  • And what error now occurs? - Roman
  • the same as with the hyphen that with the minus (( - Pavel
  • Now he does not find tracker.jar . Is this file in the current folder? Did you build through maven? Keep in mind, maven places the finished jar in the target folder, not the current one. - Roman

2 answers 2

The solution to the problem ("

 У меня задание сделать так что бы приложение запускалось командой: java –jar tracker.jar. 

") using the Eclipse IDE (Version: Neon.1 (4.6.1)) features:

  1. Create a simple (simple) project Maven ru.pravvich.start .

    Creating a Maven project

  2. Fill the pom-file with the content:

Add plugin Adding configuration information

  <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>ru.pravvich</groupId> <artifactId>ru.pravvich.start</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Tracker</name> <description>Creating tracker.jar. Just do it.</description> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <finalName>tracker</finalName> <archive> <manifest> <mainClass>ru.pravvich.start.Main</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project> 
  1. Customize the launch of the Maven command (mvn jar: jar) using the Eclipse IDE Setting up Maven commands

  2. Localize the jar file:

    Jar file localization

  3. Run the jar file: Run jar file

    The application is NOT built, but launched by the java -jar tracker.jar .

    Compiled by mvn package command or if without maven jar cf tracker.jar *.class

    • Yes, yes, I wrote about ... it starts - Pavel
    • Now such a mistake - Pavel
    • Error: Unable to access jarfile tracker.jar - Pavel
    • But it is clear with a hyphen, he doesn’t find main, but with a minus jar cannot open at all. Well, this is progress, at least now I know about the hyphen ... Thanks Roman. But what to do next? - Pavel
    • maybe some of these solutions will work with stackoverflow.com/questions/11943948/… - NetL