Mac OS错误:无法找到或加载主类com.ef.Parser

时间:2017-10-10 12:08:20

标签: java spring macos intellij-idea

我有一个Spring启动应用程序,我用命令

创建了JAR
mvn package 

JAR文件位于target文件夹parser.jar

enter image description here

提供了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

的项目文件夹中

我想从参数startDatedurationthreshold中删除值,然后在控制台中打印它们。但是,我收到了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>

我仍然没有帮助

我尝试过非常简单的Spring启动模板,但仍无效

0 个答案:

没有答案