1

를 사용하여 브라우저에서 실행하는 자바 애플릿을 가져 오기 : http://docs.oracle.com/javase/tutorial/deployment/applet/subclass.html내가 여기에서했다 매우 간단한 자바 애플릿이 JNLP

import javax.swing.JApplet; 
import javax.swing.SwingUtilities; 
import javax.swing.JLabel; 

public class HelloWorld extends JApplet { 
    //Called when this applet is loaded into the browser. 
    public void init() { 
     //Execute a job on the event-dispatching thread; creating this applet's GUI. 
     try { 
      SwingUtilities.invokeAndWait(new Runnable() { 
       public void run() { 
        JLabel lbl = new JLabel("Hello World"); 
        add(lbl); 
       } 
      }); 
     } catch (Exception e) { 
      System.err.println("createGUI didn't complete successfully"); 
     } 
    } 
} 

내가 마우스 오른쪽 버튼을 클릭하고 Run As > Java Applet을 수행 할 때 이클립스에서 실행되도록 애플릿을 얻을 수 있지만, 이제 jar 파일에 넣고 브라우저를 통해 jnlp를 사용하여 실행하려고합니다.

  1. javac -d build HelloClass.java
  2. cd build
  3. jar cvf Hello.jar *.class
  4. Hello.jnlp 파일을 만듭니다 :
<?xml version="1.0" encoding="UTF-8"?> 
    <jnlp spec="1.0+" codebase="" href=""> 
     <information> 
      <title>Hello Applet</title> 
      <vendor>Self</vendor> 
     </information> 
     <resources> 
      <!-- Application Resources --> 
      <j2se version="1.6+" 
       href="http://java.sun.com/products/autodl/j2se" /> 
      <jar href="Hello.jar" main="true" /> 

     </resources> 
     <applet-desc 
      name="Hello Applet" 
      main-class="HelloClass" 
      width="300" 
      height="300"> 
     </applet-desc> 
     <update check="background"/> 
    </jnlp> 
  1. 작성이 내가 시도하고 있다는 것은 어떻게 촬영 한 단계입니다 html 페이지 :
  2. 내 브라우저에서이 페이지를 열 때3210
<html> 
    <head> 
    <title>Hello Applet</title> 
    </head> 
    <body> 
     <!-- ... --> 
     <script src="http://www.java.com/js/deployJava.js"></script> 
     <script> 
      var attributes = { 
       code:'HelloClass', width:300, height:300} ; 
      var parameters = {jnlp_href: 'Hello.jnlp'} ; 
      deployJava.runApplet(attributes, parameters, '1.6'); 
     </script> 
     <!-- ... --> 
    </body> 
    </html> 

나는 애플릿의 실행을 허용하라는 메시지가 얻을 그러나 나는 다음과 같은 세부 오류 얻을 :

Exception: java.lang.UnsupportedClassVersionError: HelloClass : Unsupported major.minor version 51.0 

답변

3

코드는 cross-compilation options을 사용하지 않고 1.7 SDK로 컴파일 된 것 같습니다.로드하려고하는 JRE는 버전 6 이하입니다.

특정 Java 버전의 코드를 컴파일하려면 크로스 컴파일 옵션을 사용하십시오. 이를 올바르게 수행하려면 javacbootclasspath 옵션을 사용하려면 대상 버전의 rt.jar이 필요합니다.

+1

그게 전부 였어! 다음 명령을 사용하여 코드를 다시 컴파일 할 수있었습니다 :'javac -source 1.6 -target 1.6 -bootclasspath "C : \ Program Files \ Java \ jdk1.7.0_03 \ jre \ lib \ rt.jar"-d HelloClass.java' 이제는 잘 작동합니다. 여기에 링크 된 페이지의 예제를 참조하십시오. [Crosscompile-example] (http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#crosscomp-example) – nates

0

컴파일러 사이에 불일치가있다을 버전 및 JRE 버전이 동일한 (주요) 버전인지 확인하십시오.