我有一个具有两个主要类的maven项目,并希望像这样通过命令单独运行每个类:
function reducer2(state, action){
switch(action.type) {
case "RESET_STATE":
return {
someCount: 0,
someArray: [],
someBoolean: false,
};
}
}
我尝试将绝对路径添加到execute标签中的两个类,但是这样做不允许我单独运行它们。
例如,无论我在运行jar时指向哪个主类,RunApp1都将始终运行。我很确定这是我忽略的一个小问题。
我的pom.xml:
java -jar appName.jar -cp com.green.RunApp1
java -jar appName.jar -cp com.blue.RunApp2
答案 0 :(得分:1)
您需要在该部分中使用不同的ID指定主要类。像这样:
<execution>
<id>main1</id>
<configuration>
<mainClass>Main1</mainClass>
</configuration>
</execution>
<execution>
<id>main2</id>
<configuration>
<mainClass>Main2</mainClass>
</configuration>
</execution>
答案 1 :(得分:1)
我能够通过制作两个不同的配置文件来使其工作,但是我必须为它的工作构建两个不同的jar,这违背了目的。这是我的新pom.xml
<profiles>
<profile>
<id>Tiger</id>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.abc.Tiger</mainClass>
<jvmArguments>
-Dtest.dbUser=${test.dbUser}
-Dtest.dbPassword=${test.dbPassword}
-Dtest.environment=${test.environment}
</jvmArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>nexus</serverId>
<skipStaging>true</skipStaging>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>Lion</id>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.abc.Lion</mainClass>
<jvmArguments>
-Dtest.dbUser=${test.dbUser}
-Dtest.dbPassword=${test.dbPassword}
-Dtest.environment=${test.environment}
</jvmArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>nexus</serverId>
<skipStaging>true</skipStaging>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
这里是我如何构建和运行它们的方法。
mvn clean package -DskipTests -P Tiger
java -jar -Dspring.profiles.active=Tiger target/amazingApp.jar
mvn clean package -DskipTests -P Lion
java -jar -Dspring.profiles.active=Lion target/amazingApp.jar
这不是我所期望的。相反,我想建立一个jar,然后在单个jar中的配置文件之间切换。有人可以指出我正确的方向吗?