首页 > 解决方案 > 如何编写 bash 脚本来运行导入 maven 依赖项的 java 文件?

问题描述

如何创建运行此文件的 bash 脚本这是我尝试运行的 github 文件javac -d . App.java,但它不起作用,因为它导入了不同的库。这是我尝试运行文件时遇到的错误。如何编写执行时运行此文件的 bash 脚本,或者是否有可用于运行具有导入语句的 java 程序的命令?

App.java:17: error: unclosed string literal
        menu = """
                 ^
App.java:18: error: ';' expected
                                Application Menu
                                                ^
App.java:20: error: ';' expected
                1. Type one to decrypt a file.
                           ^
App.java:20: error: ';' expected
                1. Type one to decrypt a file.
                                      ^
App.java:20: error: ';' expected
                1. Type one to decrypt a file.
                                             ^
App.java:21: error: ';' expected
                2. Type two to encrypt a file.
                           ^
App.java:21: error: ';' expected
                2. Type two to encrypt a file.
                                      ^
App.java:21: error: ';' expected
                2. Type two to encrypt a file.
                                             ^
App.java:22: error: ';' expected
                3. Type three to encrypt text from terminal
                             ^
App.java:22: error: ';' expected
                3. Type three to encrypt text from terminal
                                        ^
App.java:22: error: ';' expected
                3. Type three to encrypt text from terminal
                                                  ^
App.java:22: error: not a statement
                3. Type three to encrypt text from terminal
                                                   ^
App.java:22: error: ';' expected
                3. Type three to encrypt text from terminal
                                                           ^
App.java:23: error: ';' expected
                4. Type four to decrypt text from terminal.
                            ^
App.java:23: error: ';' expected
                4. Type four to decrypt text from terminal.
                                       ^
App.java:23: error: ';' expected
                4. Type four to decrypt text from terminal.
                                                 ^
App.java:23: error: <identifier> expected
                4. Type four to decrypt text from terminal.
                                                           ^
App.java:23: error: not a statement
                4. Type four to decrypt text from terminal.
                                                          ^
App.java:24: error: ';' expected
                5. Type five to exit. 
                            ^
App.java:24: error: ';' expected
                5. Type five to exit. 
                                    ^
App.java:25: error: not a statement
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                   ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                             ^
App.java:25: error: '(' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                ^
App.java:25: error: ')' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                    ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                             ^
App.java:25: error: variable declaration not allowed here
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                          ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                    ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                             ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                                    ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                                             ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                                                        ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                                                                     ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                                                                            ^
App.java:25: error: ';' expected
                *  Disclaimer if you pick one or two the path of the file you enter will be rewritten as the encrypted version.
                                                                                                                              ^
App.java:26: error: ';' expected
                Pick an option. """;
                       ^
App.java:26: error: <identifier> expected
                Pick an option. """;
                               ^
App.java:26: error: not a statement
                Pick an option. """;
                              ^
App.java:26: error: unclosed string literal
                Pick an option. """;
                                  ^
38 errors

Github 完整回购

编辑:这是我遇到的另一个错误,有人可以告诉我如何解决吗?谢谢!

import methods.mainPackage;
              ^
App.java:13: error: cannot find symbol
        mainPackage p = new mainPackage();
        ^
  symbol:   class mainPackage
  location: class App
App.java:13: error: cannot find symbol
        mainPackage p = new mainPackage();
                            ^
  symbol:   class mainPackage
  location: class App
3 errors

标签: javabash

解决方案


您正在使用不支持String文字的 Java 版本。

用于java --version确定哪一个并确保它至少是版本 13


推荐阅读