我有一个maven模块和一个简单的主类如下:
public static void main(String[] args)
{
System.out.println("HELLO");
}
当我在main方法上面运行时,HELLO
打印在控制台上,但是当我向我的maven pom添加依赖项时如下:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>helper</artifactId>
<version>11.7.1.12-SNAPSHOT</version>
</dependency>
我运行main方法,控制台的输出是:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
我的主要方法没有执行。
上面发生了什么?
修改 完整的pom文件是:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testdevelop</groupId>
<artifactId>testevelop</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>helper</artifactId>
<version>11.7.1.12-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
helper
工件是我的自定义jar文件。
答案 0 :(得分:1)
当您的pom模块无效时发生此错误。我得到一次这个错误,因为我有一个父pom包含几个pom作为子模块,我只想打开一个子模块并运行它没有父模块。当我打开主要的pom并且工作正常时,这解决了。