java.lang.ClassFormatError: Incompatible magic value 1347093252 in class file

java.lang.ClassFormatError: Incompatible magic value 1347093252 in class file

4
NewbieNewbie
4

    Sep 08, 2019#1

    Hello. I'm trying to execute a Java console application from UEStudio v15.10.0.11. I've set the Java compiler settings in a project I called HelloWorld. When I compile the program using UEStudio, it builds the class file (I see the date modified update). I have to use the "execute class" from the build menu to get it to find the class file. I get the incompatible magic value.  If I compile the source in a DOS command window storing the class file to the same directory, then run /build/execute class it works. I'm using java 12.0.2. Has anyone else had this problem and found a solution?

    6,687587
    Grand MasterGrand Master
    6,687587

      Sep 08, 2019#2

      Have you multiple versions of Java installed?

      What does the project.mak file generated by UEStudio contain?
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        Sep 09, 2019#3

        I only have 1 version of Java installed. Here are the contents of the mak file. I've pasted in the debug version. It has the most recent altered date.

        I've also attached a snippet of "programs and features" showing the only Java I have installed.

        Code: Select all

        ################################################################################
        # [May..8.2015.17:36:10]                                                       #
        #                                  HelloWorld                                  #
        #                                                                              #
        #                                           Sunday 08 September 2019, 10:03:15 #
        ################################################################################
        ##### GROUPS ###################################################################
        FG00=\
         "C:/Users/KEITHU~1/DOCUME~1/Projects/HELLOW~1/HelloWorld.java"
        FG01=\
         "C:/Users/KEITHU~1/DOCUME~1/Projects/HELLOW~1/Debug/HelloWorld.class"
        
        ##### BUILD ####################################################################
        ALL: $(FG00)
         javac -version -target 12 -d .\ -classpath "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug";.; -g @HelloWorld.object
         jar cvfm HelloWorld.class HelloWorld.man @HelloWorld.resource [m:F|.|*.class| %s\%s|]
        HelloWorld.class: $(FG00)
         javac -version -target 12 -d .\ -classpath "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug";.; -g @HelloWorld.object
         jar cvfm HelloWorld.class HelloWorld.man @HelloWorld.resource [m:F|.|*.class| %s\%s|]
        
        ##### COMMANDS #################################################################
        run:  HelloWorld.class
         @java -classpath "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug";. -jar HelloWorld.class
        classrun:  HelloWorld.class
         @java -classpath "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug";. HelloWorld
        debug:  HelloWorld.class
         jdb -classpath "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug";. HelloWorld
        gindex:  HelloWorld.class
         jar -i HelloWorld.class
        makef: 
         uestudio HelloWorld.mak
        
        ##### CLEAN ####################################################################
        CLEAN:
         -@erase "HelloWorld.class"
         -@erase "C:/Users/KEITHU~1/DOCUME~1/Projects/HELLOW~1/Debug/HelloWorld*.class"
         -@erase "C:/Users/KEITHU~1/DOCUME~1/Projects/HELLOW~1/HelloWorld*.class"
        
        Capture.JPG (19KiB)

        6,687587
        Grand MasterGrand Master
        6,687587

          Sep 09, 2019#4

          I am not a Java programmer and so don't have installed Java at all, but there is something wrong with your compiler settings.

          The option -version is not defined in the two default configs Console Application and Windows Application for Java Compiler. So I suppose you have edited the used compiler configuration and added option -version. This could be no problem if javac is compiling the Java source code files nevertheless and additionally prints its version. But it is not standard and so I suggest to remove -version from used compiler configuration.

          I am quite sure that the version value after option -target is wrong because of defined wrong in compiler settings. This option defines the Java version for the compiled Java code which is something like 1.6, 1.7 or 1.8, i.e. the version of the Java Virtual Machine. The version of the Java SE Development Kit is the wrong version. I assume you are using UEStudio with ribbon mode as user interface. Please click on ribbon tab Build on first item Set Compiler Options. In section COMPILER OPTIONS there is the setting Target VM. 1.7 is the most used version in the last years. For that reason I recommend to double click on Target VM and select 1.7 from the list of versions predefined in Java configuration file.

          The next issue is with option -classpath. The next argument string should be a semicolon separated list of folders containing classes used by the Java source code files. The default is just . which means current directory. UEStudio makes the target directory the current directory before running any command defined in .mak file like build, run or classrun. It looks like you have edited in compiler settings in section PATHS/DIRECTORIES the setting Class Paths and inserted left to the dot the string "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug"; resulting in argument string is defined with:

          Code: Select all

          "C:\Users\Keith User HP\Documents\Projects\HelloWorld\Debug";.;
          whereby the appended semicolon is from configuration file from $(Class Paths); which should be removed in my point of view as otherwise it is impossible to define -classpath argument string ever 100% correct.
          The other usages of $(Class Paths) for the three commands run, classrun and debug are correct defined in configuration file without a semicolon appended to this argument string.

          It should be enough for your simple Hello World project to have just . configured for setting Class Paths in Compiler Options. So please change this setting back to just . in Compiler Options window. The right syntax would be ".;C:\Second Folder Path;C:\Third Folder Path", i.e. a semicolon separated list of folder paths and the entire string enclosed in " on any folder path containing a space or one of these characters &()[]{}^=;!'+,`~ (Windows command processor requirement) and not some folder paths inside argument string.

          So I suggest to make the suggested corrections in used compiler configuration by removing -version and, although not really needed, also ; after $(Class Paths) and correct in compiler settings Target VM and Class Paths. Then rebuild the Java project and see if execution is working now without the error message.

          But if there is still an error output, please post the command line used by you to compile the Java project from Windows command line so we can see the difference in comparison with the command lines executed by UEStudio according to generated .mak file. And please compare the file HelloWorld.class created via UEStudio with the file HelloWorld.class created on manual compilation from within a Windows command prompt window. The magic value is defined by the first four bytes of this file according to information read by me in world wide web. So it should be quite easy to see the difference on comparing the two generated class files.
          Best regards from an UC/UE/UES for Windows user from Austria

          4
          NewbieNewbie
          4

            Sep 10, 2019#5

            I made your suggested changes (I think). I didn't understand what your reference to $(Class Paths) so I didn't do anything there. I now get a warning in my output window when I compile HelloWorld...
            --------------------Configuration: HelloWorld - Debug--------------------
            warning: target release 1.7 conflicts with default source release 12
            added manifest
            adding: Users/KEITHU~1/DOCUME~1/Projects/HELLOW~1/Debug/HelloWorld.class(in = 1958) (out= 1751)(deflated 10%)
            HelloWorld.class - 0 error(s), 1 warning(s)


            Here are the command lines I use to compile from a DOS window.
            C:\Users\Keith User HP\Documents\Projects\HelloWorld>javac HelloWorld.java
            C:\Users\Keith User HP\Documents\Projects\HelloWorld>java HelloWorld
            Hello World, yall!
            C:\Users\Keith User HP\Documents\Projects\HelloWorld>

            Thanks for the help

            6,687587
            Grand MasterGrand Master
            6,687587

              Sep 10, 2019#6

              Okay, it looks like the option -target is counterproductive and it would be better to run javac without this option. Please do following:
              1. Click on ribbon tab Build on down arrow below first item Set Compiler Options and click on first pop-up menu item Select compiler.
              2. Click on button Edit configuration.
              3. Click on button Make configuration local (save in project directory)
              4. Scroll down to section [Variables] and remove from line starting with COPT the variable reference $(Target VM) and the space after this string.
              5. Scroll down to section [Build] near end of configuration and remove ; after $(Class Paths) on line starting with Cmd0.
              6. Click on button Save configuration.
              7. Click on button OK.
              8. Build or Rebuild the Java project.
              In my test without having Java compiler installed and using configuration for a console application the file HelloWorld.mak contains now the command lines:

              Code: Select all

              javac -d .\ -classpath . -g @HelloWord.object
              jar cvfm HelloWorld.jar HelloWorld.man @HelloWorld.resource [m:F|.|*.class| %s\%s|]
              It looks like you compile the Java source code with javac directly to HelloWorld.java while the Java compiler configuration in UEStudio compiles Java source code files in two steps. I suppose that the two steps procedure is necessary if a Java project consists of more than one source code file.

              I don't know what [m:F|.|*.class| %s\%s|] is for in second command line running jar. I would need to read manual of  jar to find out what these arguments are for and if that is correct.

              If execution of HelloWorld.jar is still not working with these edits in configuration, I suggest editing the configuration once more and comment out in section [Build] the line starting with Cmd1 by inserting # at beginning of the line and replace at end of line starting with Cmd0 object by java to compile the single source file directly to HelloWorld.java using javac as done by you on manual compilation from Windows command line. I don't know what is the difference between a .java and a .jar file. I suppose the latter is a RAR compressed version of the former.
              Best regards from an UC/UE/UES for Windows user from Austria

              4
              NewbieNewbie
              4

                Sep 14, 2019#7

                Your suggestions worked. It seemed to require all of them. The class file isn't exactly the same size as when I build it running javac from a command line but it still executes as expected.

                The only other oddity is when I click on Build/Run application I get the following error.
                Error: Invalid or corrupt jarfile HelloWorld.class

                But if I click on Build/Run Commands/Execute class [HelloWorld], it works!!! I don't see this as a show stopper though. Unless you've seen this before and know what the problem is, I'm good. We don't need to research this one.

                Thanks for your help.

                6,687587
                Grand MasterGrand Master
                6,687587

                  Sep 14, 2019#8

                  That's fine. So we need to finally change also the command executed on clicking on Run application.

                  It can be seen in file HelloWorld.mak that the generated command line for run: is:

                  Code: Select all

                  @java -classpath . -jar HelloWorld.jar
                  This command line cannot work anymore because there is no file HelloWorld.jar created anymore (most likely as I have never executed a Java compilation).
                  1. Click on ribbon tab Build on first item Set Compiler Options, change at top setting Target to just HelloWorld without file extension and close window Compiler Options with button OK.
                  2. Click on ribbon tab Build on down arrow below first item Set Compiler Options and click on first pop-up menu item Select compiler.
                  3. Click on button Edit configuration if not already activated and configuration shown on right side.
                  4. Scroll down to section [Execute] and remove on line starting with Cmd0 the option -jar with the following space.
                  5. Click on button Save configuration.
                  6. Click on button OK.
                  7. Press Shift+F4 or click Regenerate makefile (second item) on ribbon tab Build to regenerate file HelloWorld.mak.
                  The file HelloWorld.mak contains now for run: the command line:

                  Code: Select all

                  @java -classpath . HelloWorld
                  I must add that I am not a Java programmer. I have not read Java manual and Java is not installed on my Windows PC. All the steps written by me for Compiler Options configuration and modification of Java Console Application configuration are just for creating the command lines in generated HelloWorld.mak for execution on Build and Run application as posted by you as working on manual execution from command line. So it is possible that all those modifications were in real a bad idea as not really correct for compilation of a Java project with one or more source code files with using other classes in other Java archives.
                  Best regards from an UC/UE/UES for Windows user from Austria