嗨,我用 maven 创建了一个项目。基本上我使用eclipse创建了项目。然后我建立项目。一切都从 Eclipse 运行良好。现在当我编译项目时,maven 在目标目录中创建了一个类目录。
该目录包含所有类文件。现在我移动到我的主文件并从命令提示符运行它
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>
谢谢
编辑 - - - - - - - - -
我用 BatchImport.class 和 BatchImport 尝试过,但我没有得到主类?
谢谢