无法编译扩展JAR文件中的类的java类

时间:2015-01-03 17:47:06

标签: android jar

我正在尝试创建一个JAR文件,其中包含我可以访问所有Android应用程序的所有主要常用文件。我无法编译以下错误的代码:

  • 错误:无法找到或加载主要类学生
  • Student.java:4:错误:找不到符号公共类学生扩展人{

这就是我的所作所为:

我创建了一个文件夹/ home / erikt / app / mylib /来存储我所有的java类。

Person.java

package com.mylib;

public class Person {

public String name;

  public static void main(String[] args) {
  }

public Person(String name) {
  this.name = name;
}

public String toString() {
  return name;
}
}

MANIFEST.MF在

Manifest-version: 1.0
Main-Class: Person

然后我跑:

javac com/mylib/Person.java
jar cvfm mylib.jar manifest.mf com/mylib/*.class

我明白了:

added manifest
adding: com/mylib/Person.class(in = 427) (out= 273)(deflated 36%)

mylib.jar的内容

  META-INF/
  META-INF/MANIFEST.MF
  com/mylib/Person.class

现在这是我的问题:

路径:/ home / erikt / app / mytest /

cd /home/erikt/app/mytest/
cp ../mylib/mylib.jar .

Student.java

package com.mytest;
import com.mylib;

public class Student extends Person {
  public String somethingnew;

  public Student(String name) {
    super(name);
    somethingnew = "surprise!";
  }

  public String toString() {
    return super.toString() + "\t" + somethingnew;
  }

  public static void main(String[] args) {
    Person you = new Person("foo");
    Student me = new Student("boo");

    System.out.println("Your name is " + you);
    System.out.println("My name is " + me);
  }
}

编译:

javac -classpath。 -cp ./mylib.jar Student.java

我明白了:

$ javac -classpath . -cp ./mylib.jar Student.java

Student.java:4: error: cannot find symbol
public class Student extends Person {

                         ^

或者如果我尝试:

$ java Student
Error: Could not find or load main class Student

0 个答案:

没有答案