我将maven配置为在maven包中调用main方法:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.MyMainClass</mainClass>
<arguments>
<argument>arg1</argument>
<argument>arg2</argument>
</arguments>
</configuration>
</plugin>
org.jsoup
依赖关系是执行我的主要方法所必需的,但我不想为其设置compile
范围。如何仅为执行我的主类添加此依赖项?我尝试了几种方法,但我失败了。
==== EDIT ====
我不想设置compile
范围,因为我不希望maven-dependency-plugin
将其复制到依赖目录。
我刚刚意识到我可以设置compile
范围并将排除添加到maven-dependency-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeGroupIds>org.jsoup</excludeGroupIds>
</configuration>
</plugin>