Accessing web application JAR files from applet

I've got an applet which is part of a web application.
All the web application JARs are in the webapps/myappl/WEB-INF/lib directory, and I
can't seem to place anything in that directory on the archive attribute of <OBJECT> tag.
I'm running into trouble because I'm sending objects from the servlet to the applet and keep getting classnot found during deserialization because I've missed some jar file on the archive attribute. I've had to copy lots of jar files up to where the codebase in the HTML file is to make this run. My question is this.
Is it better to just change the tomcat security policy file (catalina.policy in tomcat conf directory) so that the JARs are directly accessible and I don't have to copy them from WEB-INF/lib???? Has anyone done this before? What would the line look like?
I'm assuming that I have to follow the instructions (THAT I DON'T UNDERSTAND)
at the bottom of the policy file. Can someone help me out here????
should I have something like
grant codeBase "file:${catalina.home}/webapps/myappl/WEB-INF/classes/-"
{ permission java.security.AllPermission; };
grant codeBase "file:${catalina.home}/webapps/myappl/WEB-INF/lib/-"
{ permission java.security.AllPermission; };
Will this allow me to place references to jar files (and the classes directory) in the archive attribute, such as
<OBJECT .....  >
    <param name="archive" value="../WEB-INF/lib/applet.jar,../WEB-INF/lib/someapp.jar,../WEB-INF/classes" />trailer for catalina.policy is
// You can assign additional permissions to particular web applications by
// adding additional "grant" entries here, based on the code base for that
// application, /WEB-INF/classes/, or /WEB-INF/lib/ jar files.
// Different permissions can be granted to JSP pages, classes loaded from
// the /WEB-INF/classes/ directory, all jar files in the /WEB-INF/lib/
// directory, or even to individual jar files in the /WEB-INF/lib/ directory.
// For instance, assume that the standard "examples" application
// included a JDBC driver that needed to establish a network connection to the
// corresponding database and used the scrape taglib to get the weather from
// the NOAA web server.  You might create a "grant" entries like this:
// The permissions granted to the context root directory apply to JSP pages.
// grant codeBase "file:${catalina.home}/webapps/examples/-" {
//   permission java.net.SocketPermission "dbhost.mycompany.com:5432", "connect";
//   permission java.net.SocketPermission "*.noaa.gov:80", "connect";
// The permissions granted to the context WEB-INF/classes directory
// grant codeBase "file:${catalina.home}/webapps/examples/WEB-INF/classes/-" {
// The permission granted to your JDBC driver
// grant codeBase "file:${catalina.home}/webapps/examples/WEB-INF/lib/driver.jar" {
//   permission java.net.SocketPermission "dbhost.mycompany.com:5432", "connect";
// The permission granted to the scrape taglib
// grant codeBase "file:${catalina.home}/webapps/examples/WEB-INF/lib/scrape.jar" {
//   permission java.net.SocketPermission "*.noaa.gov:80", "connect";
// };

Thank you for your reply.
As I mentioned in my first post I had seen a couple of posts mentioning ServletContext before, but dismissed them as I am not using any servlets of my own. However, since you showed me exactly how it was used I realised I could probably just use a dummy servlet to get this information.
The following page suggests a couple of techniques for doing just this.
http://www.jguru.com/forums/view.jsp?EID=1087411
So I think that's me sorted, cheers.

Similar Messages

  • How to access additional supporting jar files from EJB JAR?

    Hi,
    How can we access additional supporting jar files as part of my EJB JAR .
    I don't want to keep them in the top level because other EJB JAR files also has
    the same jar files(code in the classes in the jar is slightly different)
    can I keep the additional jar files in my EJB JAR?
    Thanks
    NLB

    Include the supporting jar files in the Ejb jar file.
    Specifiy the jar files in the Ejb jar manifest file.
    Manifest-Version: 1.0 [CRLF]
    Class-Path: utility.jar [CRLF]
    thanks,
    Deepak
    "NLB" <[email protected]> wrote:
    >
    Hi,
    How can we access additional supporting jar files as part of my EJB JAR
    I don't want to keep them in the top level because other EJB JAR files
    also has
    the same jar files(code in the classes in the jar is slightly different)
    can I keep the additional jar files in my EJB JAR?
    Thanks
    NLB

  • Download and extract jar file from applet

    Can any one provide me a solution for my below problem. Thanks in advance for all the suggestions.
    I want my applet to download a jar file, extract into users home directory by creating a folder and then set the created folder to java library path.
    My applet html file is in "root" directory. The applet is included into applet.jar and placed under "lib" directory which is under "root" directory.
    Now i also had another jar file(contains dlls what I packed) under the same lib folder.
    The below is the following directory structure in my server.
    root ---
         |
         |
         default.html
         lib--
         |
         |
         applet.jar - contains applet related classes
         native.jar - contains dlls which are to be loaded
    When a client downloads my applet, it should copy the native.jar and then extract into a new folder under user home directory. Then set this folder to java library path.
    Regards
    raman kumar

    I managed to do it this way, Just remember that you need to sign the jar files for your applet, else it won't work.
    package jar.extract;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.jar.JarFile;
    import java.util.zip.ZipEntry;
    public class JarExtractor {
         // Dll file in the jar
         private static String JAR_FILE = "dll.jar";
         public void extract() {
              try {
                   JarFile jf = new JarFile(JAR_FILE);
                   // Entry in the jar file rember package and dll file
                   ZipEntry ze = new ZipEntry("package/dll_file");      
                   int length = (int) ze.getSize();
                   byte fileContent[] = new byte[length];
                   InputStream fin = jf.getInputStream(ze);
                   fin.read(fileContent, 0, length);
                   // CODE missing.
                   // You need to write the input stream (fin) to a new files output stream
                   // it is like copying a file !!!
              } catch (IOException e) {
                   e.printStackTrace();
    }Tom

  • Protecting the jar files from being web access

    I have a jnlp file which is put under tomcat webapps folder, say (\webapps\TEST\launch.jnlp), with the jar and lib files put in the subfolder (\webapps\TEST\folder1\*.jar AND \webapps\TEST\folder1\lib\*.jar).
    My question is how can i prevent user from direct access to the jar files via typing http://www.someip.com/TEST/folder1/main.jar ? I tried the following methods but it seemed not working:
    1. Change the folder permisson in \webapps\TEST\*.*, but when user type the above hyperlink they can still get the jar file
    2. put the jar and related files under \WEB-INF\, but now this time running the launch.jnlp, it returns an error saying that it can't access/find the WEB-INF.
    Is there any method? Or should I say, when you published jnlp to web, the related jar files are forced to be accessed by everyone.

    Sounds easy to me: encrypt your xml, then instead of just storing your key as plain bytes do some reversable operations on it (xor masks, reversions, whatever you like), just do them in many different points (and classes) of your code, have some parts done by methods that actually check application is running under JWS with proper codebase, scramble it all, and suddently the whole stealing operation won't be worth the effort. Obviously you should have many private (and package protected) methods, seal packages and so on. Maybe, somehow, you can even use reflection to identify calling classes (not sure, never looked for anything similar).
    What else? write down some c++ code into your own dll/JNI library and make it do something too, so they'll even need to decompile the dll. If you know first execution is always online you can send another xor key and store it with persistence service or write it down to windows registry. You can keep making it harder as much as you like, even just with silly code like
    Math.ceil((new GregorianCalendar.getField(Calendar.YEAR)%2000)/1000)*((int)('c'-'a'))just to retrieve the number 2. If you distribute such code through many lines and methods, once you scramble it, most people will give up.
    Bye.

  • Access jar file from in-memory classes...

    I have some classes that I compile to memory and everything works fine until one class that must access some external jar files. I have been unable to access those jar files from disk after trying every suggestion using URLClassLoader. I even tried someone's example to hack the SystemClassLoader which properly adds the jar file paths, but still they can't be seen. The only way it works is if I put the files in the jdk/jre/lib/ext directory. Then everything works fine. There must be a way to load the jar files in memory as well as the class files so they can be accessible. Has anyone done anything like this? Is it possible? Even though the class files are in memory, why would the jar files not be seen even when they are added to the same URLClassLoader's URL's. Thanks.

    Sorry that wasn't clear. What I mean is that the classes are compiled to byte code directly to memory and no physical .class file is created. Yes, I'm using my own ClassLoader that extends URLClassLoader and I'm setting the parent to ClassLoader.getSystemClassLoader(). I also should mention that I'm doing this inside a Netbeans module that is part of a Netbeans Platform application. I don't know why that should matter though, since I'm trying to do everything in memory without creating the physical files. Thanks.

  • My application needs to access web server. So, from that application how do i call firefox ? and how do i pass an argument such as url/web server ip address?

    My application needs to a access web server. So, from that application how do i call Firefox ? And how do i pass an argument such as the url/web server ip address?
    == This happened ==
    Not sure how often

    Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The helpers over there are more knowledgeable about web page development issues with Firefox.
    [http://forums.mozillazine.org/viewforum.php?f=25]
    You'll need to register and login to be able to post in that forum.

  • Multiple jar files from different locations

    Hello,
    I am having an applet that access code from two different jar files. Of them one is a common jar file for many applets. So I couldn't place it in the local dir as that of the applet's html. I am not using any web server.
         Just to give you a feel of it :
         <PARAM NAME = archive VALUE = "DVApplet.jar,DVVP.jar" > are the jar files my applet is dependant on. But DVVP.jar has to be accessed from a dir different from local dir.
         Will be glad if someone can throw some light on accessing different jar files from different dirs.
         Thanks for your time.
    Regards,
    Anantha

    [url=
    http://forum.java.sun.com/thread.jsp?forum=421&thread=425724&tstart=0&trange=100
    ]This question is a bit similar
    You can use a class loader to do such things.

  • How to protect my jar file from being downloaded

    How can i protect my jar file from being downloaded by users by accessing it through the web site.
    Now everybody can just type the url www.mysite.com/applets/myApplet.jar
    And download it to his computer.
    I realize that anybody who really wants to download it he will get it anyway, but I want to make it harder.
    thanks in advance

    Your browser has to download the jar file if it's going to run the applet. That's applets work. The browser downloads the classes and then runs them locally.
    I suppose if you wanted to make something to make it difficult for users to explicitly download the jar, you could set some kind of permission flag when the HTML is page is rendered, and then unset it some amount of time (10 seconds?) later, and then only let the user download the jar when the flag is set. But this would be fragile and irritating and unhelpful. It would probably break more than you'd like and not prevent download very much (it wouldn't take long to figure out what was happening), and besides nobody is ever going to try to steal your code.

  • Accessing RS232 Port (Comm Port) from Applet

    I have an interesting "problem". I would like to create an applet that allows me to read the Comm port of the client machine but obviously I get a security exception when I try to do this. Firstly is this possible (I know it can be done from an application)? If so, how would I go about doing it?
    Thanks,
    Rishi

    you need to install the jre, and place the win32.dll at JavaSoft\JRE\1.3.1_06\bin, that properties file place at JavaSoft\JRE\1.3.1_06\lib, comm.jar at JavaSoft\JRE\1.3.1_06\lib\ext\
    and in ur code try to use it to open ur com port
    public String test() {
              String drivername = "com.sun.comm.Win32Driver";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
                   {* Discard it */}
              drivername = "javax.comm.*";
              try
                   CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
              catch (Throwable th)
                   {* Discard it */}
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM2")) {
    //if (portId.getName().equals("/dev/term/a")) {
    try {
    serialPort = (SerialPort)
    portId.open("SimpleWriteApp", 2000);
    } catch (PortInUseException e) {}
    try {
    outputStream = serialPort.getOutputStream();
    } catch (IOException e) {}
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}
                             int i=0;
                             while(true)
         try {
                                       messageString="hi";
                                       System.out.println(i++);
         outputStream.write(messageString.getBytes());
         } catch (IOException e)
                                       System.out.println(e);
                                       messageString=String.valueOf(e);
              return messageString;
    and yet u need to signed the applet
    1.     Compile the applet
    2.     Create a JAR file
    3.     Generate Keys
    4.     Sign the JAR file
    5.     Export the Public Key Certificate
    6.     Import the Certificate as a Trusted Certificate
    7.     Create the policy file
    8.     Run the applet
    Susan
    Susan bundles the applet executable in a JAR file, signs the JAR file, and exports the public key certificate.
    1.     Compile the Applet
    In her working directory, Susan uses the javac command to compile the SignedAppletDemo.java class. The output from the javac command is the SignedAppletDemo.class.
    javac SignedAppletDemo.java
    2.     Make a JAR File
    Susan then makes the compiled SignedAppletDemo.class file into a JAR file. The -cvf option to the jar command creates a new archive (c), using verbose mode (v), and specifies the archive file name (f). The archive file name is SignedApplet.jar.
    jar cvf SignedApplet.jar SignedAppletDemo.class
    3.     Generate Keys
    Susan creates a keystore database named susanstore that has an entry for a newly generated public and private key pair with the public key in a certificate. A JAR file is signed with the private key of the creator of the JAR file and the signature is verified by the recipient of the JAR file with the public key in the pair. The certificate is a statement from the owner of the private key that the public key in the pair has a particular value so the person using the public key can be assured the public key is authentic. Public and private keys must already exist in the keystore database before jarsigner can be used to sign or verify the signature on a JAR file.
    In her working directory, Susan creates a keystore database and generates the keys:
    keytool -genkey -alias signFiles -keystore susanstore -keypass kpi135 -dname "cn=jones" -storepass ab987c
    This keytool -genkey command invocation generates a key pair that is identified by the alias signFiles. Subsequent keytool command invocations use this alias and the key password (-keypass kpi135) to access the private key in the generated pair.
    The generated key pair is stored in a keystore database called susanstore (-keystore susanstore) in the current directory, and accessed with the susanstore password (-storepass ab987c).
    The -dname "cn=jones" option specifies an X.500 Distinguished Name with a commonName (cn) value. X.500 Distinguished Names identify entities for X.509 certificates.
    You can view all keytool options and parameters by typing:
    keytool -help
    4.     Sign the JAR File
    JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, Susan uses jarsigner to make a signed copy of the SignedApplet.jar file.
    jarsigner -keystore susanstore -storepass ab987c -keypass kpi135 -signedjar SSignedApplet.jar SignedApplet.jar signFiles
    The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.
    5.     Export the Public Key Certificate
    The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.
    The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.
    5: Export the Public Key Certificate
    The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.
    In her working directory, Susan uses keytool to copy the certificate from susanstore to a file named SusanJones.cer as follows:
    keytool -export -keystore susanstore -storepass ab987c -alias signFiles -file SusanJones.cer
    Ray
    Ray receives the JAR file from Susan, imports the certificate, creates a policy file granting the applet access, and runs the applet.
    6.     Import Certificate as a Trusted Certificate
    Ray has received SSignedApplet.jar and SusanJones.cer from Susan. He puts them in his home directory. Ray must now create a keystore database (raystore) and import the certificate into it. Ray uses keytool in his home directory /home/ray to import the certificate:
    keytool -import -alias susan -file SusanJones.cer -keystore raystore -storepass abcdefgh
    7.     Create the Policy File
    The policy file grants the SSignedApplet.jar file signed by the alias susan permission to create newfile (and no other file) in the user's home directory.
    Ray creates the policy file in his home directory using either policytool or an ASCII editor.
    keystore "/home/ray/raystore";
    // A sample policy file that lets a JavaTM program
    // create newfile in user's home directory
    // Satya N Dodda
    grant SignedBy "susan"
         permission java.security.AllPermission;
    8.     Run the Applet in Applet Viewer
    Applet Viewer connects to the HTML documents and resources specified in the call to appletviewer, and displays the applet in its own window. To run the example, Ray copies the signed JAR file and HTML file to /home/aURL/public_html and invokes Applet viewer from his home directory as follows:
    Html code :
    </body>
    </html>
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="600" height="400" align="middle"
    codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,1,2">
    <PARAM NAME="code" VALUE="SignedAppletDemo.class">
    <PARAM NAME="archive" VALUE="SSignedApplet.jar">
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    </OBJECT>
    </body>
    </html>
    appletviewer -J-Djava.security.policy=Write.jp
    http://aURL.com/SignedApplet.html
    Note: Type everything on one line and put a space after Write.jp
    The -J-Djava.security.policy=Write.jp option tells Applet Viewer to run the applet referenced in the SignedApplet.html file with the Write.jp policy file.
    Note: The Policy file can be stored on a server and specified in the appletviewer invocation as a URL.
    9.     Run the Applet in Browser
    Download JRE 1.3 from Javasoft
    good luck! [email protected]
    i already give u many tips, i use 2 weeks to try this to success, hopw that u understand that, a result of success is not important, the process of how to get things done is most usefull!

  • Can't run JavaFX app as a jar file from command line

    I'm trying to build a JavaFX app from scratch (that is, by including the jar file from the JavaFX SDK rather than by using the special JavaFX project type from NetBeans). It runs fine in NetBeans. However, when I try to launch it as a jar file from the command line (using "java -jar dist\TestApp") I get the following. Has anybody seen this before, and if so how can I fix it?:
    *** Fallback to Prism SW pipeline
    Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLink
    Error: Can't load library: C:\dev\TestApp\dist\bin\mat.dll
    at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:
    289)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:68)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
    pl.java:145)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:
    27)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:97)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\dev\RedactionT
    oolPrototype\RedactionToolPrototype.Core\dist\bin\mat.dll
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoad
    er.java:155)
    at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoad
    er.java:85)
    at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:
    30)
    at com.sun.glass.ui.Application$1.run(Application.java:28)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:26)
    at com.sun.glass.ui.win.WinApplication.<clinit>(WinApplication.java:33)
    at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatform
    Factory.java:20)
    at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatform
    Factory.java:17)
    at com.sun.glass.ui.Application.Run(Application.java:51)
    at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:
    279)
    ... 5 more

    Unsatisfied link means that Java is trying to access a native library, but it cannot be found. As to why this error is being thrown, here is my guess:
    If you open up one of the sample jars with a zip viewer, you will see that the Manifest file has the following entries:
    >
    Manifest-Version: 1.0
    JavaFX-Version: 2.0
    implementation-vendor: Oracle
    implementation-title: BrickBreaker
    implementation-version: 1.0
    JavaFX-Application-Class: brickbreaker.Main
    Created-By: JavaFX Packager
    Main-Class: com/javafx/main/Main
    >
    In other words, a JavaFX project works a bit differently than a normal Java project. com/javafx/main/Main is used as the Main class and your "Main" class is called later.
    If you are trying to build this from a normal Java project, then com/javafx/main/Main will not be created and it will call your Main class right away. Thus, whatever setup is needed to run JavaFX will not occur.

  • How to call a jar file from oracle forms (6i)

    Hi,
    I'm working with oracle 6i. I want to know that how to call a .jar file from forms menu. when I use HOST('<path>\test.jar') it is working in 'Client Server' any way. but the problem is I use application server in order to run my form. so my form is in the server and I run the form via clients web browser. in that case above solution will not work. if any body knows how to overcome this problem please reply.
    thanks.
    duminda

    I created a bean area and set the class name as implementation class. within that java bean class I called to a bat file which consists of the execution command of the jar file ( because i don't know how to call .jar file from my bean class directly).
    then i tried to run it in application server. its still not running.
    can you tell me what i have to do within my bean class? or can you suggest any solution?
    thank you.

  • Running a jar file from java code

    Hi!
    Im trying to run a jar file from my code.
    I've tried Classloader, but that doesnt work because it doesnt find the images (also embedded in the 2nd jar file).
    WHat I would like to do is actually RUN the 2nd jar file from the first jar file. There must be a way to do this right?
    any ideas?

    ok, I found some wonderful code (see below) that will try to start the jar. But it doesn't. What it does is produce the following error when my application runs...
    So it's not finding the images in the jar file that I am trying to run? Strange. I checked the URL that sending, but it seems ok....
    I think I will check the url again to make sure......
    any ideas?
    Uncaught error fetching image:
    java.lang.NullPointerException
         at sun.awt.image.URLImageSource.getConnection(Unknown Source)
         at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
         at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
         at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
         at sun.awt.image.ImageFetcher.run(Unknown Source)
    the code....
    /* From http://java.sun.com/docs/books/tutorial/index.html */
    import java.io.IOException;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    import java.net.JarURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.jar.Attributes;
    * Runs a jar application from any url. Usage is 'java JarRunner url [args..]'
    * where url is the url of the jar file and args is optional arguments to be
    * passed to the application's main method.
    public class JarRunner {
      public static void main(String[] args) {
        URL url = null;
        try {
          url = new URL(args[0]);//"VideoTagger.jar");
        } catch (MalformedURLException e) {
          System.out.println("Invalid URL: ");
        // Create the class loader for the application jar file
        JarClassLoader cl = new JarClassLoader(url);
        // Get the application's main class name
        String name = null;
        try {
          name = cl.getMainClassName();
        } catch (IOException e) {
          System.err.println("I/O error while loading JAR file:");
          e.printStackTrace();
          System.exit(1);
        if (name == null) {
          fatal("Specified jar file does not contain a 'Main-Class'"
              + " manifest attribute");
        // Get arguments for the application
        String[] newArgs = new String[args.length - 1];
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
        // Invoke application's main class
        try {
          cl.invokeClass(name, newArgs);
        } catch (ClassNotFoundException e) {
          fatal("Class not found: " + name);
        } catch (NoSuchMethodException e) {
          fatal("Class does not define a 'main' method: " + name);
        } catch (InvocationTargetException e) {
          e.getTargetException().printStackTrace();
          System.exit(1);
      private static void fatal(String s) {
        System.err.println(s);
        System.exit(1);
    * A class loader for loading jar files, both local and remote.
    class JarClassLoader extends URLClassLoader {
      private URL url;
       * Creates a new JarClassLoader for the specified url.
       * @param url
       *            the url of the jar file
      public JarClassLoader(URL url) {
        super(new URL[] { url });
        this.url = url;
       * Returns the name of the jar file main class, or null if no "Main-Class"
       * manifest attributes was defined.
      public String getMainClassName() throws IOException {
        URL u = new URL("jar", "", url + "!/");
        JarURLConnection uc = (JarURLConnection) u.openConnection();
        Attributes attr = uc.getMainAttributes();
        return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
       * Invokes the application in this jar file given the name of the main class
       * and an array of arguments. The class must define a static method "main"
       * which takes an array of String arguemtns and is of return type "void".
       * @param name
       *            the name of the main class
       * @param args
       *            the arguments for the application
       * @exception ClassNotFoundException
       *                if the specified class could not be found
       * @exception NoSuchMethodException
       *                if the specified class does not contain a "main" method
       * @exception InvocationTargetException
       *                if the application raised an exception
      public void invokeClass(String name, String[] args)
          throws ClassNotFoundException, NoSuchMethodException,
          InvocationTargetException {
        Class c = loadClass(name);
        Method m = c.getMethod("main", new Class[] { args.getClass() });
        m.setAccessible(true);
        int mods = m.getModifiers();
        if (m.getReturnType() != void.class || !Modifier.isStatic(mods)
            || !Modifier.isPublic(mods)) {
          throw new NoSuchMethodException("main");
        try {
          m.invoke(null, new Object[] { args });
        } catch (IllegalAccessException e) {
          // This should not happen, as we have disabled access checks
    }

  • Moving all jar files from our applcation to applib folder on server

    Hi,
    In our project we have three web applications bundled into a EAR file,to reduce the upload size we had a plan of moving all the jar files from WEB-INF/lib to the applib folder in the standalone server, but after moving i tried to run the application I get the following error,can someone help on this?
    login: JspServlet: unable to dispatch to requested page: Exception:oracle.jsp.parse.JspParseException: /jsp
    /common/page1.jsp: Line # 5, <%@ taglib uri="http://xmlns.oracle.com/adf/faces" prefix="af"%>

    Hi,
    appears that it cannot find teh tag library. However, I think the right way of sharing libraries is to read into the topic of shared library support of the server you are working with
    Frank

  • Protecting your jar file from been extracted

    Please i noticed that the java jar file of a software can easily be extracted to review the class files with winrar which allows just anyone to have access to your class file and decompile to get source codes, allowing pirating of the software. How can I lock the jar file to prevent extraction of my class files.

    1. why are you mocking others instead of answering the question ? some one wants to protect his jar file. the solution is simple.
    2. you can use google to search, here is result :
    http://stackoverflow.com/questions/1280702/protecting-java-jar-files-for-distribution
    http://stackoverflow.com/questions/9633455/how-to-protect-a-jar-file-from-being-decompiled
    http://www.thegeekstuff.com/2008/06/protect-your-java-code-from-reverse-engineering/
    http://answers.google.com/answers/threadview/id/431511.html
    http://stackoverflow.com/questions/1879061/how-to-protect-java-codes-against-decompiler
    http://viralpatel.net/blogs/2009/07/protect-java-code-decompilation-using-java-obfuscator.html
    http://www.coderanch.com/t/430716/java/java/Protect-class-file-not-decompile
    http://stackoverflow.com/questions/7324708/are-jar-file-insecure-what-can-done-apart-from-code-obfuscation
    http://stackoverflow.com/questions/3647255/how-do-i-copy-protect-my-java-application
    http://www.javaworld.com/javaworld/javatips/jw-javatip22.html
    http://stackoverflow.com/questions/12088/do-you-obfuscate-your-commercial-java-code
    3. it is true if you can use basic methods that EJP mentioned, there would be no need for obfuscators, nor native library use.
    but there are many situations that you can't do any of those methods.
    4. EJP claims that he probably is the one "who have had perhaps 40 times as long as you've had to think about it."
    here is the problem that made me use both obfuscation and native library :
    My company released a simple java library that scanned a document (directly from scanner or camera device).
    the documents were exam papers.
    Use some OCR techniques to convert image to text so some other application could calculate the score using it's api.
    For marketing purposes, the company needed to publish a 7-day trial version of this library.
    So, as you can see I'm eager to hear what you want to suggest.

  • Need help compiling external jar files into my one jar file from cmd line

    Here is my problem, let me see if I can explain it right:
    I am making a jar file on my development computer that will run my java project. In this java project, it references a couple Java3D jar files. On my development computer, I create the jar file and it runs correctly, but when I move that jar file over to the test computer, the parts of the application needing those Java3D jars are not found in my jar I created. I isolated the problem and it is because those Java3D jar files I needed are not on my test machine. But that is the way I need it to be. I need it so that when I compile all my code on the development machine, I need it to also compile those two Java3D files into my one jar that I move to the test machine. You get what I'm saying? I must do all the compiling from the command line and have only one jar file to put on the test machine that contains all my compiled code and the two Java3D files needed to run some of the applications in the project.
    Here a brief sample of what I'm doing:
    To compile my java files in my project, I simply to this for all my files:
    javac file.java
    javac file2.java... and so on for all my java files.
    Then I create my jar file:
    jar -cfm MyJar.jar manifest.mf file.class
    jar -fmu MyJar.jar manifest.mf file2.class... and so on for all my class files.
    Also when compiling my jar file, I do this thinking that it would include the two Java3D jars into my one jar file:
    jar -fmu MyJar.jar manifest.mf jars/j3d-org-images.jar
    jar -fmu MyJar.jar manifest.mf jars/j3d-org.jar
    My manifest file looks something like this:
    Manifest-Version: 1.0
    Main-Class: Main
    Class-Path: jars/j3d-org.jar jars/j3d-org-images.jar
    Do I have to have that Class-Path in there pointing to those jar files? Those jar files will not exist on my test machine because the directory structure will not be the same. I've tried a manifest without specifying my Class-Path to those jar files, but I get the same problem when I run my application on the part that needs the Java3D files.
    The error I am getting is that there is a RasterTextLabel class inside one of those Java3D jar files that my application cannot access because those jar files are not on my test machine.
    So basically what I really need to know is how I get those two Java3D jar files compiled into my one jar file that I move to a test machine and run with the following command:
    java -jar MyJar.jar
    Can anyone help me??
    Thanks.

    Here what you need is to have all the files present in a single jar file, and the classpath is set properly to the required jar files.
    Do the following in steps:
    1)
    Create a custom manifest file,say mymanifest.mf, with the following contenets, put it in current directory:
    Manifest-Version: 1.0
    Created-By: 1.4.0_01 (Sun Microsystems Inc.)
    main-Class: Main
    Class-Path: jars/j3d-org.jar jars/j3d-org-images.jar <press ENTER key>
    2)
    jar -cfm MyJar.jar manifest.mf file.class
    jar -fmu MyJar.jar manifest.mf file2.class... and so on for all class files.
    3)
    jar -fmu MyJar.jar manifest.mf jars/j3d-org.jar
    jar -fmu MyJar.jar manifest.mf jars/j3d-org-images.jar
    (Make sure that j3d-org-images.jar and j3d-org.jar are present in a subdirectory called 'jars')
    Now you would be able to run,
    java -jar myjar.jar

Maybe you are looking for

  • Free Goods Should not down MAP -

    Hi, MM / FI Gurus! We have a scenario where Vendor offers a Discount in Kind. For e.g. For Order Qty over 1000 Pcs vendor offers 10 Pcs free over each 100 Pcs. Assuming PO price as 10 units then for 1200 Ordered Qty vendor delivers 1200 + 120 = 1320

  • Use of Regular Expressions in BI Query Designer

    Hello All, For a particular requirement in Inventory, I have the following to be achieved: If at the input selection screen, if Plant entered is 'AB12', then it should show batches only startign with 'J' and if Plant entered is 'AB13' then the query

  • I need a new database engine, can you help?

    Greetings, I have a fairly unique application that I need to find a new database for. It currently uses an embedded database but we now want to go client server with it. Background: The application downloads a large amount of data, millions of record

  • Secure Payment File Transfer

    Hi, Currently we are using the SAP Classic programs ( RFFO* ) which produce our payment files and store them in a directory from where they can be transferred to another payment system, There is a couple of tools which we could use for this Connect:D

  • Material Column invisible in Purchase Order Screen after Upgrade

    Hi Freinds, Subject: MEPO1211-EMATN field invisible in Purchase Order (ME21N) We are doing an SAP Technical upgrade project from 4.6C to ECC6.0. The 4.6C developement box is upgraded to ECC6.0. I found that the Material Column is missing from the Pur