ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

QSH: How to execute a java program in a subfolder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QSH: How to execute a java program in a subfolder

    Hi everyone,

    I tried to execute some java programs ( QShell ). Obviously a highly complicated task o.0.

    To keep things simple i started with a hello world program and I am aware that the HelloWorld program needs to be called without .class suffix and that the name is case sensetive.

    When I call this program which is stored in a subfolder I get the following error message:
    Code:
      Exception in thread "main" java.lang.NoClassDefFoundError: .avs.HelloWorld (wrong name: HelloWorld)       
              at java.lang.ClassLoader.defineClassImpl(Native Method)                                           
              at java.lang.ClassLoader.defineClass(ClassLoader.java:266)                                        
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)                        
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:600)                                   
              at java.net.URLClassLoader.access$400(URLClassLoader.java:124)                                    
              at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1055)                              
              at java.security.AccessController.doPrivileged(AccessController.java:274)                         
              at java.net.URLClassLoader.findClass(URLClassLoader.java:492)                                     
              at java.lang.ClassLoader.loadClass(ClassLoader.java:639)                                          
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)                                  
              at java.lang.ClassLoader.loadClass(ClassLoader.java:605)
    My command to start the HelloWorld is this one:
    Code:
    java /avs/HelloWorld
    If I change in to the subdirectory (/avs) i can finally execute the HelloWorld program (what took me some time to figure out....). So I am doing something wrong by telling the java engine where the class file is.... I tried it with backslashes, double backslashes.....no change

    How do I have to type in the command to start a java programm in a subfolder or am I forced to "cd ..." everytime I want to execute a java program (not really, or?)

  • #2
    Re: QSH: How to execute a java program in a subfolder

    Originally posted by souljumper
    So I am doing something wrong by telling the java engine where the class file is....
    Hi there,
    you have add environment variable to tell the system to where is your class file located & start QSHELL
    in your case
    WRKENVVAR
    Code:
                         Add Environment Variable (ADDENVVAR)                   
                                                                                    
     Type choices, press Enter.                                                     
                                                                                    
     Environment variable . . . . . . > 'CLASSPATH'   Character value               
     New value  . . . . . . . . . . .   '/avs'
    then you can call java HelloWorld from QSHELL

    Comment


    • #3
      Re: QSH: How to execute a java program in a subfolder

      You always need to use CD to change directory if calling from QShell. It would be the same if you were running this on a windows or linux PC. You always need to navigate to the directory containing the program.

      You may also need to set a classpath but this is a different requirement. You only need to do this if your class references a class not included in the standard Java runtime. Normally your programs would have more than one class so you would need each one on the classpath, unless you package it all up into an executable jar and execute that rather than the class.

      Adding the environment variable is how you set the classpath if you want to call Java from RPG. If you do this then you don't need to change directory using CD.
      Ben

      Comment


      • #4
        Re: QSH: How to execute a java program in a subfolder

        if you are only want to call it from qshell (not from rpgle!), it doesn't need to navigate to the directory where the class file containing but you have to set -classpath with your java command
        same as windows/linux :
        Code:
        java -classpath /home/XXXX/java/ HelloWorld
        Code:
        java -classpath /avs/ HelloWorld

        Comment


        • #5
          Re: QSH: How to execute a java program in a subfolder

          Thx, it works now

          I am intending to use a java program for productive use (not the Hello World ....), but the Java Runtime as well as the JDK is on Release 1.3 which is far away from being up-to-date. The iSeries is a V5R1M0 - so not the newest model either.

          I tried to google the information how to deinstall the old java version, where to get the new version (propably 1.5 or even 1.6) and install it on an iSeries. Unfortunatley I lack experience in doing such thinks on the iSeries - something like IBM Guide would be fine.
          Does something exists or does someone know some sources where to get information regarding this matter

          Comment

          Working...
          X