How to run a Maven project from Eclipse?

前端 未结 3 1609
眼角桃花
眼角桃花 2020-12-25 11:41

I am trying to run a simple Java project. I had created a project using the \'Maven Project\' type. I have one main class called \'TestMain\'. When I tried to run the projec

3条回答
  •  太阳男子
    2020-12-25 12:00

    Well, you need to incorporate exec-maven-plugin, this plug-in performs the same thing that you do on command prompt when you type in java -cp .;jarpaths TestMain. You can pass argument and define which phase (test, package, integration, verify, or deploy), you want this plug-in to call your main class.

    You need to add this plug-in under tag and specify parameters. For example

       
        ...
        ...
        
         
          
           org.codehaus.mojo
           exec-maven-plugin
           1.1.1
           
            
             test
             
              java
             
             
              my.company.name.packageName.TestMain
              
               myArg1
               myArg2
              
             
            
           
          
         
        
        ...
        ...
       
    

    Now, if you right-click on on the project folder and do Run As > Maven Test, or Run As > Maven Package or Run As > Maven Install, the test phase will execute and so your Main class.

提交回复
热议问题