This question already has an answer here:
- Can't execute jar- file: “no main manifest attribute” 34 answers
While the project executes from the IDE, how is the JAR
created so that a hello world type console app will actually run?
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloMaven ---
[INFO] Deleting /home/thufir/NetBeansProjects/HelloMaven/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ HelloMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/thufir/NetBeansProjects/HelloMaven/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/thufir/NetBeansProjects/HelloMaven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloMaven ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ HelloMaven ---
[INFO] Building jar: /home/thufir/NetBeansProjects/HelloMaven/target/HelloMaven-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.400 s
[INFO] Finished at: 2017-10-21T10:50:42-07:00
[INFO] Final Memory: 14M/47M
[INFO] ------------------------------------------------------------------------
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ tree
.
├── nbactions.xml
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── net
│ │ │ └── bounceme
│ │ │ └── dur
│ │ │ └── hello_maven
│ │ │ └── Main.java
│ │ └── resources
│ └── test
│ └── java
└── target
├── classes
│ └── net
│ └── bounceme
│ └── dur
│ └── hello_maven
│ └── Main.class
├── generated-sources
│ └── annotations
├── HelloMaven-1.0-SNAPSHOT.jar
├── maven-archiver
│ └── pom.properties
└── maven-status
└── maven-compiler-plugin
├── compile
│ └── default-compile
│ ├── createdFiles.lst
│ └── inputFiles.lst
└── testCompile
└── default-testCompile
└── inputFiles.lst
25 directories, 9 files
thufir@dur:~/NetBeansProjects/HelloMaven$
thufir@dur:~/NetBeansProjects/HelloMaven$ java -jar target/HelloMaven-1.0-SNAPSHOT.jar
no main manifest attribute, in target/HelloMaven-1.0-SNAPSHOT.jar
thufir@dur:~/NetBeansProjects/HelloMaven$
apparently just need to specify the Main-Class
entry for the manifest.
Just focusing on the package
phase:
Running Maven Tools Maven Phases
Although hardly a comprehensive list, these are the most common default lifecycle phases executed.
validate: validate the project is correct and all necessary information is available compile: compile the source code of the project test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed package: take the compiled code and package it in its distributable format, such as a JAR. integration-test: process and deploy the package if necessary into an environment where integration tests can be run verify: run any checks to verify the package is valid and meets quality criteria install: install the package into the local repository, for use as a dependency in other projects locally deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects