Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

amazon s3 - Java Incompatible magic value 4022320623

Im getting a strange error when im compiling my code on a server and downloading it and trying to run it on my computer.

Im basically compiling some java files on an EC2 instance, then loading them into a storage for later use.

When i download the files onto my computer and try to run them i am getting the following errors:

Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value  
     4022320623 in class file HelloWorldPackage/HelloWorldClass
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:787)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476)

I am compiling the files using the following method:

public void compileProject()
{


    String command = "javac ";
    for(String s: this.getPackages())
    {
        File[] files = new File("/home/benuni/CompileFiles/" + project + "/src/" + s).listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".java");
            }
        });

        for(File f: files)
        {
            command = command + f.getAbsolutePath() + " ";
        }
    }

    try {
        System.out.println("command: '"+ command +"'");
        Process pro = Runtime.getRuntime().exec(command);
         printLines(" stderr:", pro.getErrorStream());

        pro.waitFor();

        this.moveClassFiles();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

and am uploading the files with this method:

public void uploadBin()
{
    for(String s: this.getPackages())
    {
        File[] filesInPackage = new File("/home/benuni/CompileFiles/"+this.project+"/bin/"+s).listFiles();

        for(File f: filesInPackage)
        {
            String key = this.project+"/"+this.version+"/bin/"+s+"/"+f.getName();
            s3.putObject("devcloud",key,f);

        }

    }

}

does anyone know what i am doing wrong? The class files are runnable when i compile them on the computer, but when i upload them to the cloud and download them im getting the error?

Thanks,

Ben

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you use Maven te build your project. try to disable resource filtering in maven-war-plugin like that <filtering>false</filtering> in POM file:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
    <webResources>
        <resource>
            <filtering>false</filtering>
            <targetPath>WEB-INF/classes</targetPath>
            <directory>${project.basedir}/target/classes</directory>
        </resource>
    </webResources>
    <filtering>false</filtering>
  </configuration>
</plugin>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...