Dynamic jar file inclusion at run time

Hello,
I have a java application which should accept the three parameters.
1) The jar file location
2) Particular Class file insdie that jar(we specified the location in step number 1)
3) And method name in that class.
My question is how to include specified jar location with jar name to CLASSPATH at run time. So that i can execute a particular method name in step number (3).
I would appreciate for the quick reponse or any input.
Thanks,
Raghu

And if you want to change the system classpathduring
runtime, don't forget that you can always use
reflection to call the System classloader'sprotected
addUrl method :)Really?
Seems reasonable although this is the first time I
have seen that referred to.you can indeed. I've done this, as a quick avoid-writing-a-classloader hack. wouldn't really recommend it, though. if you're using reflection to modify access, chances are you're doing a massive fudge
and of course, since it's not part of a public API, there's absolutely no reason to the method won't simply disappear in a future release....

Similar Messages

  • Can we load and unload the files in the run time?

    Can we load and unload the files in the run time?
    For example there are four files named "test1.h & test1.c" and another set "test2.h & test2.c" (I attached them as attachment to this post).
    test1.h contains code:
    int variable; //variable declared as integer
    test1.c contains code:
    variable = 1; //variable assigned a value
    test1.h contains code:
    char *variable; //variable declared as string
    test1.c contains code:
    variable = "EXAMPLE"; //variable assigned a string
    So here, in this case can I dynamically load / unload the first & second group of files so that the same variable name "variable" can be used both as integer and string? And if yes, how is that to be done?
    Solved!
    Go to Solution.
    Attachments:
    test.zip ‏1 KB

    What do you mean by "dynamically"?
    If you want to have a variable that either is an int or a char in the same program run, I'm afraid your only option is to define it as a variant and assign from time to time the proper data type in the variant according to some condition. Next, every time you access the variable you must firstly check which data type is stored in it, next access it in the proper way.
    If on the other hand your option or to have a run in which the variable is an int, next you stop the program and in a following run it is a char, you may have it by using some appropriade preprocessor clause:
    #ifdef  CHAR_TYPE
    #include "test1.h";        // variable defined as a char
    #else
    #include "test2.h";        // variable defined as int
    #endif
    Next, every time you want to access the variable you must proceed in the same vay:
    #ifdef  CHAR_TYPE
      variable = "string";
    #else
      variable = 1;
    #endif
    Does it worth the effort?
    Additionally, keep in mind that this "dynamical" approach can work only in the IDE, where you can properly #define your CHAR_TYPE or not depending on your wishes: when you compile the program, it will have only one #include depending on the definition of the macro.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Reading from a file. How to ask the user for file name at run time????

    I have the code to read from a file but my problem is how to prompt the user for the file name at run time.
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class FileRead {
        public static void main(String args[]) {
            Scanner scan = null;
            File file = new File("Results.txt");
            String number;
            try {
                scan = new Scanner(file);
                while (scan.hasNext()){
                number = scan.next();
                System.out.println(number);}
            catch (FileNotFoundException ex1){
                System.out.println("No such file");
            catch (IllegalStateException ex2){
                System.out.println("Did you close the read by mistake");
            catch (InputMismatchException ex){
                System.out.println("File structure incorrect");
            finally{
                scan.close();}
    }Any hints would be greatly appreciated. Thank you in advance

    I have read through some of the tutorials that you have directed me too and they are very useful, thank you. however there are still a few things that i am not clear about. I am using net beans 5.0 I have placed a text file named Results.txt into the project at the root so the program can view it.
    When I use the code that you provided me with, does it matter where the file is, or will it look through everywhere on the hard drive to find a match?
    This code compiles but at run time it comes up with this error
    run-single:
    java.lang.NoClassDefFoundError: NamedFile
    Exception in thread "main"
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    import java.util.Scanner;
    import java.io.*;
    class NamedFileInput
      public static void main (String[] args) throws IOException
        int num, square;   
        // this Scanner is used to read what the user enters
        Scanner user = new Scanner( System.in );
        String  fileName;
        System.out.print("File Name: ");
        fileName = user.nextLine().trim();
        File file = new File( fileName );     // create a File object
        // this Scanner is used to read from the file
        Scanner scan = new Scanner( file );     
        while( scan.hasNextInt() )   // is there more data to process?
          num = scan.nextInt();
          square = num * num ;     
          System.out.println("The square of " + num + " is " + square);
    }his is the code that i used. It is the same as the code you posted for me (on chapter 23 I/O using Scanner and PrintStream) Sorry im just really stuck on this!!

  • Getting adobe form file size at run time

    hi,
    ya i need the adobe form file size at run time. my requirement
    is to get xstring and file size of the adobe form. adobe form format is already in xstring format, but how to get the file size.

    Hi,
    try the following:
      DATA lv_file_content TYPE xstring.
      DATA lv_file_size    TYPE i.
      lv_file_size = XSTRLEN( lv_file_content ).
    This will give you the file size in Byte. For KB, just divide by 1024, and once more for MB.
    Kind regards
    Ole

  • Appending in file and supplying file name at run time using File Adapter

    Hi,
    Can we use File Adapter to write in a file in append mode. i.e. a BPEL process opening a file appending some text and closing the file each time it called.
    Another query is can we create the file at run time with the supplied file name?

    In order to append to a file, we can use Append="true" in the interaction spec for the File/Ftp adapter.
    <jca:operation
    FileType="ascii"
    PhysicalDirectory="/home/adapter/output"
    FileNamingConvention="OutputFile.txt"
    NumberMessages="1"
    Append="true"
    >
    Filename we can specify in wsdl...

  • How can I create a jar file that will run automatically on double click

    all the jars I created run only from the command-line.
    how can I make it run by double-click on it?

    First you will need to associate .jar files with the javaw.exe program in order to just be able to double click on the jar and run it from within a windows explorer application. Next you will need to set the main class attribute of the manifest file. My understanding is that the value of this attribute is used by the launcher to know which class to load. In other words, which is your main application class. To specify this attribute open your manifest file in a text editor. You will find this file located within the jar at META-INF/MANIFEST.MF. Then, add the line,
    "Main-Class:<relative path to the main class>" However, remember not to add the .class extension to the end of the class name.
    In Windows 2000 you can associate jar files with javaw by finding a jar file in Windows Explorer and right clicking it. This will give you a context menu which should have an Open With... option (if you are not using Windows 2000 and don't see the 'open with' menu item, try holding down the shift button while right click on the file). Select the Open With... option, then, when the dialog appears highlight javaw and select the "Always use this program to open these files" checkbox. When you hit the OK button you should have all your jar files associated with the javaw process.
    Once you've done this, you should be able to double click on your jar file and run your application.
    Regards,
    Daniel Walsh

  • JAR file decompressed before run?

    hi,
    does anyone know if a JAR file is decompressed totally to some temporary location before it is run? So if you had a 1Gb Jar file that was mostly odd files, and a few java classes to do some optional processing which never occured, would the remainder of the jar be decompressed?
    thanks,
    asjf

    Oops, wrong answer to wrong thread.
    Jars a decrompressed on demand but the JRE might cache the whole Jar file.
    But anyways: Who uses such big Jar files?

  • Jar file won't run

    Why is it that whenever i run my program using eclipse it works fine but whenever i export a jar file of it, it doesn't run at all?
    It does not even give an error message and this happens for only one specific class, all the others expoort perfectly

    Probably either 1) the jar file is not located where it should be, or 2) the jar file does not have (or it's incorrect) a manifest file.
    Since you don't give any useful diagnostic information, hard to tell more.

  • Jar file doesn't run properly, please help!

    Hi everyone, i'm a student and i'm programming a game for my homework of AI subject. When i compiled the code from Eclipse, the game run smoothly, but when I create the jar file of the project, it appear blank when i run it. Here is the image:
    [blank screen|http://c.upanh.com/upload/4/299/3L0.8429518_1_1.png]
    and run from Eclipse:
    [Run from Eclipse|http://c.upanh.com/upload/4/299/TL0.8429668_1_1.png]
    I have followed the instruction of creating jar file in Eclipse properly, and now the trouble come. If anyone can show me how to solve this problem?
    Thanks all.

    I have all of e.printStackTrack( ) in my try - catch block. But i also think the blank screen appears because the class can not find my resources. Maybe it's my fault, because i create by hand a folder name "res" in project folder, then put all my resource in this folder. And in Eclipse when i try to get these resource, i wrote something like this:
         Image robot1N, robot1E, robot1S, robot1W;
         private void initResources() {               
              try {               
                   String sb = "car1";
                   robot1N = ImageIO.read(new File("res\\img\\unit\\" + sb +"_N.png"));
                   robot1E = ImageIO.read(new File("res\\img\\unit\\" + sb +"_E.png"));
                   robot1S = ImageIO.read(new File("res\\img\\unit\\" + sb +"_S.png"));
                   robot1W = ImageIO.read(new File("res\\img\\unit\\" + sb +"_W.png"));
              catch(Exception e) {
                   e.printStackTrace();
         }Maybe the string of path to resource is right in Eclipse but wrong in Window?

  • How to insert records dynamically in a table at run time

    hi, all
      please help me out,
      my problum is how can i insert records from on table to another table at  run time dynamically. Initally the records are coming  from R/3 backend.
    regards

    Hi,
    One way is to first create a Value node (NewNode) with structure binding of that of the model node. Then iterate through the model node, create NewNode elements and set the value from model node elements into it.
    IPrivate<view>.I<model node> mele;
    IPrivate<view>.I<NewNode> nele;
    for(int=0;i<wdContext.node<output>().node<record>().size();i++)
    mele = wdContext.node<output>().node<record>().get<record>ElementAt(i);
    nele = wdContext.node<NewNode>().create<NewNode>Element();
    wdContext.node<NewNode>().addElement(nele);
    nele.set<attr>(mele.get<attr>());
    Second way is to create that NewNode inside the model node and create a supply function.
    Regards,
    Piyush.

  • Decompiling jar file and then run

    Dear Members,
    I have a jar file and I have decompiled that jar file and converted into class file,
    now I want to run/edit using source code ,I am unable to run source code with out put whatever coming in jar file running,
    I am trying with class in which
    public static void main(String[] args)
    function defined,
    I am using Jcreater1.5 and from command prompt also running but unable to run and edit the programm,
    how to run these class file in complete project that output will come as running jar file
    regards
    SACHIN

    It sounds like you have unpacked the jar.
    To edit the source you need to decompile the classes to .java files.
    [http://www.google.co.uk/search?q=java+decompiler]

  • JAR files don't run on Linux

    Hey All:
    I installed JDK1.3.1(win32) on Windows, double clicked my JAR file (proper manifest and classes within) and it started the swing program just fine.
    I installed JDK1.3.1(linux) on Red Hat 7, double clicked my JAR file, and it wants to know which Fk'n program to open it with! What happened here, I thought java/swing runs on linux?
    The JDK installed java in /usr/java/jdk1.3.1/bin/java, do I somehow need to point linux there for .jar files to execute automatically? What are the commands to do this?
    Thanks in advance,
    Stephan

    As far as I know, the double clicking on a jar file to execute it only works on windoze. On linux, you can can use:
    java -jar foo.jar&
    to execute the jar, assuming you have the main class included in the manifest. I don't know if there are any plans to change this. You should be able to write a script or somesuch which prepends 'java -jar' when you double-click.
    m

  • How to change property file contents during run time?

    Hi everyone. First post so go easy on me please.
    I have a couple of properties that I want to read from a from a file. To achieve this I simply use:
    ResourceBundle.getBundle("my.package.MyItems").getString("MyProperty");
    This works like a wonder. The problem is, i want to change the property "MyProperty" during runtime. I've found the properties file (MyItems.properties) inside weblogic, but if a change its contents it does not reflect in the application.
    I can come up with a couple of justifications:
    * I'm not looking in the right folder/changing the wrong file in the server;
    * Weblogic caches the properties file, meaning that I have to redeploy the project (defeating the purpose of actually having a properties file).
    Can anyone help with this one?
    [EDIT] Forgot important info:
    * JDeveloper 11.1.1.4
    * Weblogic 11.3 (not 100% sure)
    * Both JDev and WebLogic running on Windows 7 64 bits
    Thank you in advance!
    Best Regards
    J. Peixoto
    Edited by: 868634 on Jul 12, 2011 9:37 AM
    Edited by: 868634 on Jul 12, 2011 10:21 AM
    JDeveloper 11.1.1.4, not 3

    I tried it all.
    Just an explanation of my context.
    I have 1 application with 2 projects in it. First project is called "CommonUI_ViewController" and the second one "FO_ViewController".
    The properties file I'm trying to change is located inside "CommonUI_ViewController", in package "PropertiesConfig" and the file is called "PhaseListener.properties".
    "FO_ViewController" is dependent on "CommonUI_ViewController". When I run "FO_ViewController" the integrated weblogic server log shows this (among other things):
    [10:25:55 AM] Wrote Web Application Module to D:\JDeveloper\dump\system11.1.1.4.37.59.23\o.j2ee\drs\SPV_BPM\FO_ViewControllerWebApp.war
    [10:25:57 AM] Wrote Web Application Module to D:\JDeveloper\dump\system11.1.1.4.37.59.23\o.j2ee\drs\SPV_BPM\CommonUI_ViewControllerWebApp.war
    Note: both lines above point to folders. "FO_ViewControllerWebApp.war" and "CommonUI_ViewControllerWebApp.war" are NOT war files, but folders that have that name.
    I tried changing the properties file in the following locations:
    * D:\JDeveloper\dump\system11.1.1.4.37.59.23\o.j2ee\drs\SPV_BPM\FO_ViewControllerWebApp.war\WEB-INF\lib\adflibSPVCommonUI.jar > PropertiesConfig\PhaseListener.properties;
    * D:\JDeveloper\dump\system11.1.1.4.37.59.23\o.j2ee\drs\SPV_BPM\CommonUI_ViewControllerWebApp.war\WEB-INF\lib\adflibSPVCommonUI.jar > PropertiesConfig\PhaseListener.properties;
    * D:\JDeveloper\dump\system11.1.1.4.37.59.23\o.j2ee\drs\SPV_BPM\CommonUI_ViewControllerWebApp.war\WEB-INF\classes\PropertiesConfig\PhaseListener.properties (no need to open any jar/war to get to this one).
    I changed all these files with different values but no change was shown in the application (using the method in the previous post).
    I believe that I'm still doing something wrong :/
    Thank you for your help so far vinod_t_krishnan!
    J. Peixoto

  • Help please - how can i change a file extension at run time

    hi all
    i have a question about file created on the run. for instance, if i need to create a file initially with a an extension of '.in'. and there are some processes writing data to it, and after the file is written. i need to change it to some thing like '.out'. is it possible to do this? can u please provide some samples if you have any solution or suggestion. thanks.

    do u have the links of these tutorials?IO tutorials...
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Appel dynamique sous VI en mode run time

    Bonjour,
    En mode developpement, dans le VI principal, je lance un sous-VI de façon dynamique en faisant appel au chemin complet du sous VI en question, pas de problème.
    En mode RunTime (donc une fois le programme installé sur l'ordinateur cible), ou se trouve ce sous VI ? Je sais comment retrouvé le chemin de l'appli, mais je ne sais pas ou trouver le sous VI pour l'appel dynamique ... est-il dans une librairie ? est-il inclus dans l'exe ? comment le lancer ?
    Merci d'avance.
    Wilfried.
    Résolu !
    Accéder à la solution.

    Au moment de construire ton application, tu peux choisir dans les options dans quel répertoire copier les sous-VI, comme sur ce screenshot :
    Par défault, ils ne sont pas inclus "physiquement". En cochant l'option "set destination for all contained items", ils le seront.
    Cordialement,
    J.D.
    French Labview beginner
    N'oubliez pas de complimenter les bonnes réponses - Don't forget Kudos for good answers

Maybe you are looking for

  • K7N2 Delta-ILSR + FX5700-256td = PC Shudown and Lock

    i play a Doom 3 demo or Morrowind and in the short while to be playing the computer it is extinguished MSI K7N2 Delta-ILSR (v7.8 Bios) MSI FX5700-256td (last bios) AMD Sempron 2600+ 512 DDR 300W power WinXP SP2, Suse Linux 9.1 all patch´s and last dr

  • In MIRO system showing different vendor other thar PO

    Hi During Invoice booking in MIRO, system is showing different vendor other than the vendor in Purchase order. As a result different vendor other than PO vendor is getting credited. We have checked below settings. u2022 Partner roles in vendor master

  • Sort by Release Date option?

    I don't know why an option to sort by "release date" is absent from iTunes. It seems like an obvious way to layout/view music. There isn't even an option to enter the "Release Date"(only "Year") on music files. I use the pattern "Year/Month/Date - Al

  • My video shots and u tube crash

    I have a MacBook Pro 10.6.8 (Feb 2011) 2.66 i7 8GB ram, 128GB solid state drive. Graphics NVIDIA GeForce GT 330M. About 3 months ago I started to get iphoto crashing as soon as I started to scroll thro the 100's of pics. Then also on video picture pl

  • .MTS Audio Files help needed

    I'm having a little trouble with editing. The footage I am editing are .MTS files. Both the audio and video. The video is playing fine (well, as best it can for my rubbish uni computers) but I am having trouble hearing the audio - and I'm getting lot