Java 从命令promt运行时,maven不是运行主类
嗨,我用maven创建了一个项目。基本上,我使用eclipse创建了这个项目。然后我构建这个项目。从eclipse开始,一切都运行良好。现在,当我编译项目时,maven在目标目录中创建了一个classes目录 此目录包含所有类文件。现在,当我移动到主文件并在命令提示符下运行它时Java 从命令promt运行时,maven不是运行主类,java,maven-3,Java,Maven 3,嗨,我用maven创建了一个项目。基本上,我使用eclipse创建了这个项目。然后我构建这个项目。从eclipse开始,一切都运行良好。现在,当我编译项目时,maven在目标目录中创建了一个classes目录 此目录包含所有类文件。现在,当我移动到主文件并在命令提示符下运行它时 java BatchImport.class 然后我得到一个错误 could not find or load main class BatchImport.class. 如何从命令提示符运行它 这是我的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>
org.eclipse.m2e
生命周期映射
1.0.0
org.apache.maven.plugins
maven依赖插件
[1.0.0,)
复制依赖项
org.apache.maven.plugins
maven编译器插件
${maven编译器plugin.version}
${java版本}
${java版本}
-Xlint:全部
真的
真的
org.apache.maven.plugins
maven jar插件
${maven jar plugin.version}
真的
依赖罐子/
pk.training.basitMahmood.BatchImport
org.apache.maven.plugins
maven依赖插件
${maven dependency plugin.version}
复制依赖项
包裹
复制依赖项
log4j,org.slf4j,org.springframework,commons-net,commons-collections,
org.apache.commons、javax.mail、org.apache.velocity、commons日志
${project.build.directory}/dependency jars/
谢谢
编辑
-----------------
我用BatchImport.class尝试了它,只使用了BatchImport,但没有得到主类
谢谢每个类都有一个包声明。您必须使用
java my.pkg.MyClass
其中“my.pkg”是包名,“MyClass”是类名
为了避免将来的麻烦:您必须从目录运行它,它是您的包目录的父目录。在您的情况下,它是您屏幕截图中的类目录。然后请检查您的屏幕截图,请再次阅读我的回答。此命令正在运行
D:\Personal Work\eclipse 32 Bit\workspace\Spring Integrati在\LS360BatchImportIntegration\target\classes>java-cp“;d:\dependency jars\*”com/softech/ls360/integration/BatchImport test