31

I write maven project and I run it in Eclipse but I want to run maven project in using command line so I write

java -jar -Dapple.awt.UIElement="true" target/myproject-1.0-SNAPSHOT.jar -h

line in cmd but I have this error https://i.stack.imgur.com/c03mN.png.

How can I solve it?

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
kbry
  • 421
  • 1
  • 5
  • 4
  • 1
    https://stackoverflow.com/questions/33613857/noclassdeffounderror-while-executing-main-class-using-java-classpath-command/33616594#33616594 – Rajat Mar 08 '19 at 07:12
  • Possible duplicate of [Why am I getting a NoClassDefFoundError in Java?](https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – Rajat Mar 08 '19 at 07:14

6 Answers6

42
  1. Move to your project root folder in command line - cd ~/Project.
  2. mvn compile
  3. mvn exec:java -Dexec.mainClass=com.kub.App

Please check for more information here.

Artyom Vancyan
  • 5,029
  • 3
  • 12
  • 34
Thu Rein Tin
  • 421
  • 4
  • 4
42

You can run mavan spring-boot project using the following command

mvn spring-boot:run
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Priyansh Sheth
  • 441
  • 1
  • 5
  • 6
2

Go to project :

  1. open cmd
  2. cd c:/project
  3. mvn clean install
  4. java -jar -Dapple.awt.UIElement="true" target/myproject-1.0-SNAPSHOT.jar -h

Add this in pom:

    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>com.kub.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
     </plugins>
halfer
  • 19,824
  • 17
  • 99
  • 186
question_maven_com
  • 2,457
  • 16
  • 21
  • @question-maven-com I did your said but I have this error : could not find or load main class com.kub.App but I run this project correctly in Eclipse but this project didn't work my cmd .How I solved it? – kbry Nov 28 '15 at 23:13
  • @question-maven-com my pom.xml as you say. It' correct. but I have still this error :( I import this maven project in my workspace in Eclipse but this project is not seen in my workspace directory so I run this project download directory not Eclipse workspace directory so Could this lead? I want to run this project in cmd but I did'nt – kbry Nov 28 '15 at 23:31
0

Are you sure that you are in the correct path for loading the .jar file?

maybe you need something like this?

java -jar -Dapple.awt.UIElement="true" USERS/eclipse-project/projectname/target/myproject-1.0-SNAPSHOT.jar -h 
johnstreip
  • 25
  • 5
0
  1. Please make sure that JAVA_HOME and MAVEN_HOME path are set in environment variables as follows:

    JAVA_HOME: C:\Program Files\Java\jdk1.8.0_181 (Path till JDK folder only not bin folder) MAVEN_HOME: C:\Users\Amit Joshi\Downloads\apache-maven-3.6.0

  2. Add both paths in environment variable 'Path' as follows: %MAVEN_HOME%\bin %JAVA_HOME%\bin

  3. Open your project using IDE (in my case I am using intelliJIDEA)

  4. Click on Run button and copy the command executed in console window.

  5. Open cmd and traverse to the root folder of your maven project.

  6. Paste and execute the copied command and your project will run successfully.

Community
  • 1
  • 1
Amit Joshi
  • 57
  • 3
0

You have called the java command from an incorrect path ( i.e., Windows/system32 ) instead of your projects base directory .... cd to your projects base directory and try again .... That might solve your problem ....