简体   繁体   English

java 编译失败,其中带有 jar 文件的类路径

[英]java compile failed where classpath with jar files

There is a jar named 353.jar in a directory.目录中有一个名为jar353.jar I new a java class and import a class that is in 353.jar .我新建了一个 java class 并导入了一个 class 在353.jar

import com.coxier.test.DrawaerLayout;


class Test {
    public static void main(String[] args) {
        DrawaerLayout d = new DrawaerLayout();
    }
}

I compile Test.java with below command:我使用以下命令编译Test.java

javac -verbose -classpath /Users/coxier/test/app/build/intermediates/transforms/dexBuilder/debug/353.jar:. TestA.java

But here is a error:但这里有一个错误:

error: package com.coxier.test does not exist

EDIT 1编辑 1

Thanks @Marquis.谢谢@Marquis。 I know this jar is a dex format file.我知道这个 jar 是一个 dex 格式的文件。

jar tvf 351.jar

The output is: 1080024 Thu Jul 02 17:52:10 CST 2020 classes.dex output 是: 1080024 Thu Jul 02 17:52:10 CST 2020 classes.dex

javac has nothing to do with android. javac与android无关。

Android development can be done using a language that is extremely java like but not quite java. Android 开发可以使用与 java 非常相似但不完全 java 的语言来完成。 In particular, all the infrastructure around it, such as what the compiled code looks like, is entirely non-java (as in, the tooling that ships with not-android-targeted java, such as your OpenJDK installation, doesn't know about it and can't read any of it).特别是,它周围的所有基础设施,例如编译后的代码,完全是非 Java 的(例如,不针对 Android 的 java 附带的工具,例如您的 OpenJDK 安装,不知道它并且无法阅读任何内容)。

That jar file contains, as far as java itself is concerned (and javac is just java, not android), absolutely nothing: It has no idea what a dex file is, so that is just ignored.该 jar 文件包含,就 java 本身而言(而 javac 只是 java,而不是 android),完全没有:它只是不知道什么是 dex 文件,所以它被忽略了。

This code would work if the jar file contained the entry:如果 jar 文件包含以下条目,则此代码将起作用:

/com/coxier/test/DrawaerLayout/Test.class

then, javac -cp thatJar.jar TestA.java would work, assuming TestA.java is in the current working directory and contains:然后, javac -cp thatJar.jar TestA.java可以工作,假设TestA.java在当前工作目录中并且包含:

import com.coxier.test.DrawaerLayout.Test;

public class TestA {
    Test test;
}

If you have the source of that Test.dex file, you could make a class file instead, but it sounds like what you need is for TestA.java to also be compiled with the android toolkit, which presumably does know what dex files are, and may even accept them in jars (though I recall that jars aren't a thing android does either, just like it doesn't 'do' class files).如果您有该Test.dex文件的来源,则可以制作一个 class 文件,但听起来您需要的是TestA.java也可以使用 ZC31B32364CE19CA8FCD150A417ECCE5 进行编译and may even accept them in jars (though I recall that jars aren't a thing android does either, just like it doesn't 'do' class files).

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

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