简体   繁体   English

使用终端在 Ubuntu 上运行 java 项目

[英]Run java project on Ubuntu using terminal

Currently i have java project with multiple classes and the main class is importing some of them.目前我有多个类的 java 项目,主要的 class 正在导入其中的一些。 The project is working fine when i import it in VScode and run it on windows, but when i upload it on server and run the main class from command line i get erros.当我在 VScode 中导入它并在 windows 上运行它时,该项目工作正常,但是当我将它上传到服务器上并从命令行运行主 class 时,我得到了错误。

my main class is:我的主要 class 是:

package test;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import test.model.FileInfo;


public class PublishApiDemo {

    /**
     * Token domain name.
     */
    private static String domain = "xx";

    /**
     * clientId
     */
    private static String clientId = "xxxxx";

    /**
     * clientSecret
     */
    private static String clientSecret = "xxxxx";

    /**
     * App ID.
     */
    private static String appId = "xxxx";

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {

        // Obtain the token.
        String token = GetToken.getToken(domain, clientId, clientSecret);

        // Query app information.
        GetAppInfo.getAppInfo(domain, clientId, token, appId, "en-GB");

        // Submit for review.
        SubmitAudit.submit(domain, clientId, token, appId);
    }

}

the error im getting is:我得到的错误是:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        GetToken cannot be resolved
        GetAppInfo cannot be resolved
        SubmitAudit cannot be resolved

        at test.PublishApiDemo.main(PublishApiDemo.java:40)

i have tried to run我试着跑

javac filename.java 
java filename
javac -cp lib.jar PublishApiDemo.java

EDIT:编辑:

after i have imported the classes at the top like this:在我像这样导入顶部的类之后:

import test.SubmitAudit;
import test.GetToken;
import test.GetAppInfo;

now im getting another error现在我得到另一个错误

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        HttpPost cannot be resolved to a type
        HttpPost cannot be resolved to a type
        JSONObject cannot be resolved to a type
        JSONObject cannot be resolved to a type
        StringEntity cannot be resolved to a type
        StringEntity cannot be resolved to a type
        CloseableHttpClient cannot be resolved to a type
        HttpClients cannot be resolved
        HttpResponse cannot be resolved to a type
        HttpStatus cannot be resolved to a variable
        JSONObject cannot be resolved to a type
        JSON cannot be resolved

seems that error is not with the xOS you use, it's in java code itself.似乎错误不在于您使用的 xOS,而在于 java 代码本身。 how and where you intend to see the result?您打算如何以及在哪里看到结果? where is the print command after the method call?方法调用后的打印命令在哪里?

It looks like the classes you are importing have dependencies on the items listed in your runtime errors.看起来您正在导入的类依赖于运行时错误中列出的项目。 You will need to include the jar files that the test.* classes use in the runtime classpath.您将需要包含 test.* 类在运行时类路径中使用的 jar 文件。

I use findjar.com to locate common jars given a class.在给定 class 的情况下,我使用 findjar.com 来定位常见的 jars。 For example, StringEntity can be found in org/apache/httpcomponents/httpcore/4.0 which is a jar file called httpcore-4.0.jar.例如,可以在 org/apache/httpcomponents/httpcore/4.0 中找到 StringEntity,这是一个名为 httpcore-4.0.jar 的 jar 文件。 This may or may not be the one needed though.这可能是也可能不是需要的。 If you have source for test.* you can check the import statements to confirm and specify the fully-qualified import package in the findjar search.如果您有 test.* 的来源,您可以检查导入语句以确认并在 findjar 搜索中指定完全限定的导入 package。

More than likely, wherever you got the test.* classes will indicate what runtime jars you will need in documentation.很有可能,无论您在哪里获得了 test.* 类,都会在文档中指明您需要的运行时 jars。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM