我有一个Spring启动应用程序,我用命令
创建了JARmvn package
JAR文件位于target
文件夹parser.jar
提供了Spring启动主类,
@EnableTransactionManagement
//@ComponentScan({"com.ef"})
@EntityScan("com.ef.entity")
@EnableJpaRepositories("com.ef.repository")
@SpringBootApplication(scanBasePackages = {"com.ef"}, exclude = JpaRepositoriesAutoConfiguration.class)
public class Parser implements CommandLineRunner {
public Parser() {
}
public static void main(String[] args) throws Exception {
SpringApplication application = new SpringApplication(Parser.class);
application.run(args);
}
@Override
public void run(String... args) throws Exception {
Options options = new Options();
Option start = new Option("startDate", "startDate", true, "Start date");
start.setRequired(true);
options.addOption(start);
Option duration = new Option("duration", "duration", true, "duration");
duration.setRequired(true);
options.addOption(duration);
Option threshold = new Option("threshold", "threshold", true, "threshold");
threshold.setRequired(true);
options.addOption(threshold);
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("utility-name", options);
System.exit(1);
return;
}
String startDate = cmd.getOptionValue("startDate");
String dur = cmd.getOptionValue("duration");
String thers = cmd.getOptionValue("threshold");
System.out.println(startDate);
System.out.println(dur);
System.out.println(thers);
exit(0);
}
}
我在IntelliJ终端中运行命令,
java -cp target/"parser.jar" com.ef.Parser --startDate=2000-10-21.21:55:36 --duration=hourly --threshold=100
并且,我在Mac OS
,/Users/XYZ/IdeaProjects/LogParser
我想从参数startDate
,duration
和threshold
中删除值,然后在控制台中打印它们。但是,我收到了Error: Could not find or load main class com.ef.Parser
这里有什么问题?
Update
正如有人建议双引号,我试过没有使用它们仍然没有帮助。我会提出其他建议。
pwd
命令结果:/Users/XYZ/IdeaProjects/LogParser
ls
命令结果打印:
LICENSE Log.txt README.txt hello-springboot.iml pom.xml src target
更新了POM
文件以进入主类
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<finalName>parser</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.ef.Parser</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
我仍然没有帮助