5 Replies Latest reply: Mar 20, 2012 11:38 PM by safarmer RSS

    Ant tools: converter java card -  class file  not belonging to the package!

    923272
      Hi

      I have another problem with converter. Could you help me please again if you have the time?

      I have created a directory when I save the class files generated by javac. After That , I use convert in this way:

      <convert
      JCA="true"
      EXP="true"
      CAP="true"
      packagename="testUn/classes/testUn"
      packageaid="0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x02:0x00"
      majorminorversion="1.0"
      verbose = "true">
      <AppletNameAID
      appletname="testUn.classes.testUn.PorteAppUn"
      aid="0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x02:0x00:0x00"/>
      <classpath refid="classpath"/>
      </convert>

      Here is the answer of the computer:

      [echo] Generation of the CAP,JCA and EXP files...
      [convert] Java Card Ant Tasks, Version 1.0
      [convert] Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
      [convert] Note: Usage of Java Card Ant Tasks is optional. Java Card Ant Tasks are not supported by Sun Microsystems, Inc.
      [convert] Java Card 2.2.2 Class File Converter, Version 1.3
      [convert] Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
      [convert] parsing /home/ehoudart/app-manager/VersionZero/src/testUn/classes/testUn/PorteAppUn.class
      [convert] converting testUn.PorteAppUn
      [*convert] error: class PorteAppUn does not belong to package testUn.classes.testUn.*
      [convert] conversion completed with 1 errors and 0 warnings.

      I do not understand why this unique applet class file does not belong to its own package. Is someone an idea?
      Thanks very much in advance for your answer.
        • 1. Re: Ant tools: converter java card -  class file  not belonging to the package!
          safarmer
          Hi,

          To help you I will need a little more information.

          1) What is the package declaration at the top of the Java source file?

          2) What is the directory structure of your project?

          Cheers,
          Shane
          • 2. Re: Ant tools: converter java card -  class file  not belonging to the package!
            923272
            Hi,

            Here is my package declaration at the top of my java file:

            package testUn;
            import versionZero.VersionZeroShareable; => It is a file that we import from another package.
            import javacard.framework.*;

            My directory structure is the following:
            I have a project named "VersionZero" which contains the directory "src".
            This one contains four packages, among them testUn.
            TestUn contains:
            - the java files PorteAppUn.java
            - the file PorteAppUn.opt
            - the directory "javacard" so as to save the files .EXP, .JCA, .CAP and .script
            - the directory "classes" which contains the directory "testUn" which contains the file PorteAppUn.class

            Thanks you very much in advance for your help.
            • 3. Re: Ant tools: converter java card -  class file  not belonging to the package!
              safarmer
              Try something like:
              <convert JCA="true" EXP="true" CAP="true" packagename="testUn" packageaid="0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x02:0x00" majorminorversion="1.0" verbose = "true">
                <AppletNameAID appletname="testUn.PorteAppUn" aid="0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x02:0x00:0x00"/>
                <classpath refid="classpath"/>
              </convert>
              classpath should include the classes directory you compiled to.

              Cheers,
              Shane
              • 4. Re: Ant tools: converter java card -  class file  not belonging to the package!
                923272
                Hi,

                Thanks you very much for your help. I have solved the problem. I generated the class files in the same directory of the .java files. I would prefer store them in the "classes" directory but I do not succeed in converting them when they are in the classes directory.
                Here is an example of my final code, in case other people encounter the same problem:
                COMPILATION:
                <echo message = "Compilation TestUn"/>
                               <javac
                                    debug="yes"
                                    optimize="no"
                                    srcdir="testUn"
                                    destdir=".">
                                    <classpath refid="pathJava"/>
                                    <classpath refid ="classpath" />
                                    <classpath refid ="pathVersionZero"/>
                               </javac>
                CONVERSION:
                <convert
                               JCA="true"
                               EXP="true"
                               CAP="true"
                               packagename="testUn"
                               packageaid="0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x02:0x00"
                               majorminorversion="1.0"
                               verbose = "true">               
                               <AppletNameAID
                                    appletname="testUn.PorteAppUn"
                                    aid="0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x01:0x02:0x00:0x00"/>
                               <classpath refid="classpath"/>
                          </convert>
                • 5. Re: Ant tools: converter java card -  class file  not belonging to the package!
                  safarmer
                  Here is a complete example build.xml (I think I have posted this before).
                  <?xml version="1.0" encoding="UTF-8" ?>
                  <project default="convert" name="javacard-starter">
                    <!-- Build specific properties -->
                    <property name="target.classes" location="${basedir}/target/classes" />
                    <property name="target.javacard" location="${basedir}/target/javacard" />
                    <property name="source.java" location="${basedir}/src/main/java" />
                    
                    <!-- Must point to the folder containing the JAR files from the JCDK -->
                    <property name="javacard.libs" location="${basedir}/lib" />
                    
                    <!-- Must point to the folder containing the JAR file from the JCDK ant task -->
                    <property name="javacard.ant-task" location="${basedir}/lib" />
                    
                    <!-- Must point to the folder containing the API export files from the JCDK -->
                    <property name="javacard.export" location="${basedir}/src/main/export" />
                  
                    <property name="verbose" value="true" />
                    <property name="noverify" value="false" />
                  
                    <!-- Path for JC tasks -->
                    <path id="classpath">
                      <fileset dir="${javacard.ant-task}">
                        <include name="*.jar" />
                      </fileset>
                      <fileset dir="${javacard.libs}">
                        <include name="*.jar" />
                      </fileset>
                    </path>
                  
                    <!-- set the export path to the Java Card export files -->
                    <path id="export" description="set the export file path">
                      <fileset dir="${javacard.export}">
                        <include name="**/*.exp" />
                      </fileset>
                      <pathelement path="${javacard.export}" />
                      <pathelement path="${target.classes}" />
                      <pathelement path="${target.javacard}" />
                    </path>
                  
                    <!-- Definitions for tasks for Java Card tools -->
                    <taskdef name="capgen" classname="com.sun.javacard.ant.tasks.CapgenTask" classpathref="classpath" />
                    <taskdef name="deploycap" classname="com.sun.javacard.ant.tasks.DeployCapTask" classpathref="classpath" />
                    <taskdef name="convert" classname="com.sun.javacard.ant.tasks.ConverterTask" classpathref="classpath" />
                    <taskdef name="verifyexport" classname="com.sun.javacard.ant.tasks.VerifyExpTask" classpathref="classpath" />
                    <taskdef name="verifycap" classname="com.sun.javacard.ant.tasks.VerifyCapTask" classpathref="classpath" />
                    <taskdef name="verifyrevision" classname="com.sun.javacard.ant.tasks.VerifyRevTask" classpathref="classpath" />
                    <typedef name="appletnameaid" classname="com.sun.javacard.ant.types.AppletNameAID" classpathref="classpath" />
                    <typedef name="jcainputfile" classname="com.sun.javacard.ant.types.JCAInputFile" classpathref="classpath" />
                  
                    <target name="init">
                      <mkdir dir="${target.classes}" />
                      <mkdir dir="${target.javacard}" />
                    </target>
                  
                    <target name="clean">
                      <delete dir="${target.classes}" />
                      <delete dir="${target.javacard}" />
                      <delete dir="${javacard.eeprom}" />
                    </target>
                  
                    <target name="compile" depends="init" description="Compile source code to class files">
                      <!-- Compile the java code from ${src} to ${classes} -->
                      <javac debug="yes" optimize="no" srcdir="${source.java}" destdir="${target.classes}" source="1.5" target="1.5">
                        <classpath refid="classpath" />
                      </javac>
                    </target>
                  
                    <target name="convert" depends="compile" description="Convert class files to cap files">
                            <convert packagename="chaining" packageaid="0xF0:0x00:0x00:0x01:0x00:0x01" majorminorversion="1.0" classdir="${target.classes}" outputdirectory="${target.classes}" jca="true" exp="true" cap="true" debug="true" verbose="${verbose}" noverify="${noverify}">
                                 <appletnameaid aid="0xF0:0x00:0x00:0x01:0x00:0x01:0x00:0x01" appletname="chaining.ChainingApplet" />
                                 <exportpath refid="export" />
                                 <classpath refid="classpath" />
                            </convert>
                    </target>
                  
                    <target name="copy-debug">
                      <mkdir dir="${target.debug}" />
                      <echo>Copying cap files</echo>
                      <copy flatten="true" todir="${target.debug}" verbose="true">
                        <fileset dir="${target.classes}" includes="**/*.cap" />
                        <fileset dir="${target.classes}" includes="**/*.exp" />
                        <fileset dir="${target.classes}" includes="**/*.jca" />
                      </copy>
                    </target>
                  
                    <target name="all" depends="clean, convert" />
                  </project>