2013-08-05 3 views
0

Привет, я использовал maven для создания проекта. В основном я создал проект с использованием eclipse. Затем я строю проект. Все отлично работает от затмения. Теперь, когда я компилирую проект, maven создал каталог классов в целевом каталоге.maven не запускается основной класс при запуске из команды promt

Maven Target directory structure

Этот каталог содержит все файлы классов. Теперь я, когда я перейти к моему основному файлу и запустить его из командной строки с помощью

java BatchImport.class 

Тогда я получаю сообщение об ошибке, что

could not find or load main class BatchImport.class. 

Как я могу запустить его из командной строки?

вот моя конфигурация Maven

<build> 

    <!-- to avoid maven-dependency-plugin (goals “copy-dependencies”, “unpack”) is not supported by m2e error --> 
    <pluginManagement> 
     <plugins> 

      <!-- Ignore/Execute plugin execution --> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 

          <!-- copy-dependency plugin --> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-dependency-plugin</artifactId> 
            <versionRange>[1.0.0,)</versionRange> 
            <goals> 
             <goal>copy-dependencies</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore /> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 

     <!-- Maven compiler plugin 
      If you run the code maven package now, Maven will package this Java project into a jar file 
      named “LS360BatchImportIntegration-1.0.0.jar“, in target folder. 
     --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>${maven-compiler-plugin.version}</version> 
      <configuration> 
       <source>${java-version}</source> 
       <target>${java-version}</target> 
       <compilerArgument>-Xlint:all</compilerArgument> 
       <showWarnings>true</showWarnings> 
       <showDeprecation>true</showDeprecation> 
      </configuration> 
     </plugin> 

     <!-- To make jar file like a exe file, you need to define a manifest file and declare the application 
      entry point inside via maven-jar-plugin in pom.xml. 
     --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>${maven-jar-plugin.version}</version> 

      <!-- The configuration of the plugin --> 
      <configuration> 

       <!-- Configuration of the archiver --> 
       <archive> 

        <!-- Manifest specific configuration --> 
        <manifest> 

         <!-- Classpath is added to the manifest of the created jar file. --> 
         <addClasspath>true</addClasspath> 

         <!-- 
          Configures the classpath prefix. This configuration option is 
          used to specify that all needed libraries are found under dependency-jars/ 
          directory. 

          Use “classpathPrefix” to specify folder name in which all properties will be placed. 
         --> 
         <classpathPrefix>dependency-jars/</classpathPrefix> 

         <!-- Specifies the main class of the application --> 
         <mainClass>pk.training.basitMahmood.BatchImport</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
     </plugin> 

     <!-- uses maven-dependency-plugin to copy all dependencies to "target/dependency-jars/" folder, and 
       defines the dependency classpath with maven-jar-plugin 
     --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>${maven-dependency-plugin.version}</version> 
      <executions> 
       <execution> 
        <id>copy-dependencies</id> 
        <phase>package</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <includeGroupIds> 
          log4j, org.slf4j, org.springframework, commons-net, commons-collections, 
          org.apache.commons, javax.mail, org.apache.velocity, commons-logging 
         </includeGroupIds> 
         <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

Благодаря

Редактировать -----------------

enter image description here

Я пробовал его с BatchImport.class и просто BatchImport, но я не получаю никакого основного класса?

Thanks

ответ

1

В каждом классе есть декларация пакета. Вы должны запустить свой класс с

java my.pkg.MyClass 

где «my.pkg» это имя пакета и «MyClass» является именем класса.

И только чтобы избежать осложнений в будущем: вы должны запустить его из каталога, являющегося родителем каталогов пакетов. В вашем случае это каталог классов из вашего скриншота.

+0

Просьба проверить изменение .. – Basit

+0

Затем проконтролируйте скриншот и, пожалуйста, снова прочитайте мой ответ. – Seelenvirtuose

+0

Эта команда запускает 'D: \ Personal Work \ eclipse 32 Bit \ workspace \ Spring Integration \ LS360BatchImportIntegration \ target \ classes> java -cp".; D: \ dependency-jars \ * "com/softech/ls360/integration/Тест BatchImport' – Basit

Смежные вопросы