Wildcards in classpath

Hi,
I am trying to deploy an application with a 3rd party API which has 10 .jar files. Is there a way I can use wildcards to specify these 10 .jar files? Basically I need to add all the .jar files from the main application folder to the classpath.
I tried to use from a batch file:
java -cp .;*.jar Main_Class
but it does not work.
I rather not hard code all the .jar files into my batch file, since the 3rd party may add some more .jars, and I would have to change the launch code for all my users in the field..
Any suggestions would be appreciated.

You absolutely cannot use wildcards in a classpath. No exceptions.
If you distributed your application as a jar file then you could add the Class-Path entry to it's manifest.
Lets say the 3rd party items come in abc.jar, def.jar, and hik.jar and you require that these jar files be installed into the same directory as your application's jar file which is called MyAppJarFile.jar. You could have a manifest.mf that looked like:
Manifest-Version: 1.0
Class-Path: abc.jar def.jar hik.jar
Main-Class: Main_Class
(Very important: make sure there is at least one-blank line after the last entry in your manifest.mf!)
When user's run your program they would need a simple command line of:
java -jar MyAppJarFile.jar
If a newer version of these 3rd party api's come available you would change the MANIFEST.MF class-path entry to use the newer 3rd party jar files and then distribute your app's jar file with the new 3rd party jar files.
See
http://java.sun.com/j2se/1.4.2/docs/guide/jar/index.html
and
http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html
for more info

Similar Messages

  • Wildcard for classpath

    I have all my jar files under a directory and I tried the below syntaxes in the classpath section but it won't work. Can we wildcard in classpath?
    I tried different syntaxes as below but no luck
    c:\lib\*
    and
    c:\lib\*.jar
    and
    c:\lib\*.*

    You can do it by copying all the name of the jars in a file and calling that file using the syntax in your program: -classpath @pathname\filename
    Note:Windows OS has a Classpath Length Limitation: Win32 systems have a 2K limitation on the length of the command line. If the classpath setting for the Windows service startup is very long, the 2K limitation could be exceeded.
    For example:
    set CMDLINE="%JAVA_VM% %MEM_ARGS% %JAVA_OPTIONS%
    -classpath *@c:\myClasspath.txt* -Dweblogic.Name=%SERVER_NAME% -Dbea.home=\"D:\bea_70sp2\" -Dweblogic.management.username=%WLS_USER% -Dweblogic.management.server=\"%ADMIN_URL%\" -Dweblogic.ProductionModeEnabled=%STARTMODE% -Djava.security.policy=\"%WL_HOME%\server\lib\weblogic.policy\" weblogic.Server"
    Refer the section " Adding Classes to the Classpath" in the below link
    http://docs.oracle.com/cd/E13222_01/wls/docs81/adminguide/winservice.html

  • Wildcards in Classpath for JNI-Calls

    Is it possible to use wildcards in the classpath for KNI-Calls?
    I would like to use wildcard for jni-calls like for normal java-calls (java -classpath *.jar ...), but it is not working.
    JDK version is JDK 1.5.0 on Win32

    I would like to use wildcard for jni-calls like for normal
    java-calls (java -classpath *.jar ...), but it is not working.It would be the Shell, not Java doing the wildcard magic.
    You would have to do the globbing manually (or use any OS APIs, or 3rd party APIs).

  • Wildcards in command line (classpath)

    Hello,
    I tried to do something like
    javac -cp *.jar MyProg.javaor
    java -cp .;*.jar MyProgwhich is not accepted. Is there another way to do it?
    Regards
    J�rg

    you can wildcard in Ant scripts, which can be used to run as well as compile.
    or write a batch file (Windows) or a shell script (Unix) to run it.
    Problem with batch files, though, is that usually the mode which would let you loop thru a directory listing and appent a variable to create the classpath is disabled. Had to do it once where I had a script which generated the real script dynamically, ran it with the right flags to get that special mode, then removed the script on exit.

  • Using wildcards in import statement

    I typically use wildcards in my import statements. For example:
    import javax.swing.*;
    Are there any advantages, though, in specifying exactly which classes I am importing?
    For example,
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JEditorPane;
    import java.swing.JProgressBar;
    // etc.
    Specigically, is the resulting class file any smaller if I specify exactly which classes to use and does the Java runtime engine load faster if I specify exactly which classes I use in the import statemetents?
    Thanks,

    Import has precisely zero runtime impact. I believe it is used to help locate the specified class at runtime. Take the following 2 simple source files:
    import java.util.Vector;
    //import java.util.*;
    public class VectorTest
         public static void main( String[] args )
              Vector v = new Vector();
              v.add("Item 1");
              v.add("Item 2");
              System.out.println( v.get(1) );
    public class Vector
         public boolean add(Object o)
              return true;
         public Object get(int index)
              return "doh!";
    }1) Run the code as is and "Item 2" is displayed
    2) Recompile the code using the generic import and "doh!" is displayed.
    The point is that by fully qualifying the import statement you are sure you are executing the correct class and not just some class that happens to be lying around somewhere in your classpath.

  • Adding Classes to the JAR File's Classpath

    Ques 1- Can I use the wildcard * symbol in Manifest file to add classes/othes jar files to the JAR File's Classpath.I have folder named - Lib . where there are many jar files.Now,do I have to add each jar file by- Class-Path: Lib/jar1-name Lib/jar2-name . Instead, can I do this- Class-Path: Lib/*.jar OR Class-Path: Lib/*.class
    RIDICULOUS....105 views has been made but YET NO ANSWER. Isn't there anybody who knows the answer.
    Edited by: Tanvir007 on Apr 30, 2008 2:21 AM

    Ques 1- Can I use the wildcard * symbol in Manifest file to add ... other jar files ...?No. You could, however, place all your needed JARs in JavaHome/jre1.x.x/lib/ext - if this is a way for you.
    Ques 2 ??
    RIDICULOUS....105 views has been made but YET NO ANSWER.What hindered you to test it yourself?
    And the things we don't know far exceed the things we know. Why do you wonder?
    Have a nice day
    J�rg

  • Including large number of jars in classpath...

    Hello,
    I have an application that relies on over 100 jars and a set of classes - I have been using an IDE to set the classpath so far, which has been fine, but I need to distribute the application to others, and so need to bundle the classes, preferably as a jar. I have tried multiple variations of setting the classpath within the manifest for the jar file (that includes only my source), and have finally resorted to setting the classpath using a batch file and running directly using the classes. Neither method works - the classpath seems to be too long - the best results I've got are with the bat file, but this loads all but the last 8 jars - taking out a few jars adds one or two more, so this seems to confirm a maximum length for the classpath. (FYI, I have previously used the manifest to set the classpath and this has been fine, but in this case I had only two jars.)
    Has anyone come across this problem, and if so, have you managed to find a solution - I've combed through the relevant postings to this forum and have found similar problems but no actual Manifest or bat file example apart from a description of what was done, all of which I've tried, and none of which worked. The option to use the wildcard * in the classpath environment variable doesn't work because I cannot use JDK1.6 - the external libraries need to run on JDK1.5 - I have actually tried this but it is not expanded.
    Aba-Sah

    Another option is to package (or "flatten") all the dependencies into a single JAR. I use the following Groovy script in ANT builds to copy files from many JARs to a single location ...
    <!-- set up a groovy task -->
    <taskdef name="groovy"
              classname="org.codehaus.groovy.ant.Groovy"
         classpathref="compile-cp"/>
    <!-- you'll need to adapt this to your environment -->
    <target name="flattenLibs">
              <mkdir dir="${dist-temp}"/>
              <groovy>
                   import java.io.*;
                   import java.util.zip.*;
                   import java.util.jar.*;
                   def copyBinary(isDir, dfile, is) {
                        def file = new File( dfile )
                        if ( isDir ) {
                             file.mkdirs()
                        else {
                             def preIndex = Math.max( dfile.lastIndexOf( "/" ), dfile.lastIndexOf( "\\" ) )
                             if ( preIndex > 0 )
                                  new File( dfile.substring( 0, preIndex + 1 ) ).mkdirs()
                             def fout = new BufferedOutputStream( new FileOutputStream( file ) )
                             try {
                                  byte[] buffer = new byte[ 1024 ]
                                  int i
                                  while ( ( i = is.read( buffer, 0, buffer.length ) ) > 0 )
                                       fout.write( buffer, 0, i )
                                  fout.close()
                             finally {
                                  fout.close()
                   def destDir = project.getProperty( "dist-temp" )
                   if ( destDir.endsWith( "\\" ) || destDir.endsWith( "/" ) )
                        destDir = destDir.subString( 0, destDir.length() - 1 )
                   // Look at "core-cp"
                   def libs = []
                   project.getReference( "core-cp" ).list().each { pe ->
                        if ( pe.endsWith( ".jar" ) )
                             libs.add( pe )
                   def noisy = "true".equalsIgnoreCase( project.getProperty( "noisy" ) )
                   // Copy:
                   libs.each { lib ->
                        def jfile = new JarFile( new File( lib ) )
                        def e = jfile.entries()
                        while ( e.hasMoreElements() ) {
                             def entry = e.nextElement()
                             def name = entry.getName()
                             if ( noisy )
                                  println "Copying \"${name}\" ..."
                             def is = new BufferedInputStream( jfile.getInputStream( entry ) )
                             try {
                                  copyBinary( entry.isDirectory(), "${destDir}/${name}", is )
                             finally {
                                  is.close()
              </groovy>
         </target>

  • WL-10.3.5 Error Creating Wildcard Hostname Verifier for Facebook OAuth

    Hi,
    I am writing an application that uses OAuth for 3rd party login. However, Weblogic 10.3.5 does not by default accept the way Facebook uses a wildcard in their SSL Certificate.
    Caused By: javax.net.ssl.SSLKeyException: [Security:090504]Certificate chain received from graph.facebook.com - 31.13.70.23 failed hostname verification check.
    Certificate contained *.facebook.com but check expected graph.facebook.comSo I am attempting to use a Custom Hostname Verifier that implements the weblogic.security.SSL.HostnameVerifier interface, to use instead of the standard BEA Hostname Verifier. I have packaged into a jar, my CustomHostnameVerifier class that implements the weblogic.security.SSL.HostnameVerifier interface. Here's where I might be running into trouble. To make this class available on the weblogic classpath, I have tried placing the jar in various weblogic lib directories on my development machine. (%WL_HOME%\wlserver_10.3\server\lib) And then in the weblogic console's advanced settings for SSL on the DefaultServer, I select that I want to use a Custom Hostname verifier, and provide the full class name of my class: my.package.prefix.CustomHostnameVerifier.
    Now when I reboot and try connecting with Facebook, a ClassNotFoundException is thrown:
    Caused By: weblogic.utils.NestedRuntimeException: [Security:090563]Cannot create instance of Hostname Verifier my.package.prefix.CustomHostnameVerifier...
    Caused By: java.lang.ClassNotFoundException: my.package.prefix.CustomHostnameVerifierI have checked that the class is in fact accessible from the jar, and have also used the start-up argument: -Dweblogic.security.SSL.HostnameVerifier=my.package.prefix.CustomHostnameVerifier, instead of and in addition to the SSL tab settings in the console. I've found no luck so far using suggestions from documentation and the web. I was just hoping someone might know what I'm doing wrong here, or be able to point me in the right direction for properly making classes available to weblogic.
    Thanks.
    -Tyler

    I solved this problem. I've extracted all required libraries from weblogic server.
    com.bea.core.descriptor.settable.binding_1.4.0.0.jar
    com.bea.core.descriptor.wl.binding_1.1.0.0.jar
    com.bea.core.descriptor.wl_1.1.0.0.jar
    com.bea.core.descriptor_1.4.0.0.jar
    com.bea.core.xml.beaxmlbeans_1.0.0.0_2-4-0.jar
    com.bea.core.xml.beaxmlbeans_2.2.0.0.jar
    com.bea.core.xml.staxb.buildtime_1.3.0.0.jar
    com.bea.core.xml.staxb.runtime_1.3.0.0.jar
    com.bea.core.xml.stax_1.1.0.0.jar
    com.bea.core.xml.xmlbeans_1.0.0.0_2-4-0.jar
    com.bea.core.xml.xmlbeans_2.2.0.0.jar
    glassfish.jaxb.xjc_2.1.6.jar
    glassfish.jaxws.rt_2.1.3.jar
    glassfish.jaxb_2.1.6.jar
    glassfish.jaxws.tools_1.0.0.0_2-1-3.jar     
    wlfullclient.jar
    weblogic.jar
    webserviceclient+ssl.jar
    webserviceclient.jar
    webservices.jar
    wlfullclient5.jar
    wlclient.jar

  • Using "." in CLASSPATH

    I am following the Tomcat/servlet tutorial at http://www.moreservlets.com/Using-Tomcat-4.html
    It's all been going great, until "Test 3: A Servlet That Uses Packages and Utilities". When I try to compile the servlet, I get an error because it can't find the class needed. They are both in the same folder. The tutorial says to include "." in my CLASSPATH variable. I have done that, but it still doesn't work. Here is what my CLASSPATH looks like...
    .;C:\ServletDevel;C:\j2sdk1.4.0_01\jre\lib\ext\servlet.jar
    How do I get the servlet to compile with the class in the same folder?

    first, if you're using the java compiler installed under C:\j2sdk1.4.0_01 you don't need to include C:\j2sdk1.4.0_01\jre\lib\ext\servlet.jar in your class path.
    second, some things to look out for:
    are you using package names in your source? if you are, you should use the -d switch to javac to make it put the compiled classes in some directory. you should also make this directory part of you class path instead of ".". -d makes javac put the compiled file into a sub-directory with the same name as the package, which is where the java command will later look for it.
    are you compiling your java files one by one, or are you using a wild card? by using a wild card, like "javac *.java", the compiler will compile all the files at once, taking care of dependencies as well.
    when you're saying the "missing" class is in the same directory, do you mean the .class file or the .java file? if you're using package names in the source code, the .class file will not be searched for in the same directory, even if it's in the class path. the java command tries to find the .class file by going through the class path, and for each directory found it will append the package name of the class to the directory name, then look for the class file in the subdirectory so named.
    here's an example:
    java Foo.java Bar.javawhere both Foo and Bar are specified to be in the package foo.bar, will create the files Foo.class and Bar.class in the directory where you did the compile. If you set the class path to "." and try to run foo using
    java Foohowever, it won't work, for several reasons.
    first of all, the command should actually be
    java foo.bar.Foobecause java needs the full class name of the class it's going to run, as input.
    second, that command wont work either, because, with the class path set to ".", java will look for the class foo.bar.Foo in the directory "./foo/bar". so you need to either put your .class files into this directory, or run javac with the -d option.
    here's how you would make it all work:
    - set CLASSPATH to an existing directory, eg. "classes"
    CLASSPATH=classes- compile using wildcards and -d
    javac -d classes *.java- verify that your class files were put in a sub directory under "classes"
    - run the class "Foo" (or copy everything to where the servlet engine wants it)
    java foo.bar.Foo

  • Help -setting long classpath in windows 2003

    i have around 50 jars .
    i have to set classpath for all these jars.
    when i try to set environmentvariables\classpath
    its not taking the classpath completly.
    and errors are thrown when program is compiled ..
    pls help
    arvin

    If you're using Java 6 a new classpath feature may help:
    "As a special convenience, a class path element containing a basename of * is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR (a java program cannot tell the difference between the two invocations).
    For example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to a A.jar:b.JAR, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory. The CLASSPATH environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started -- no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking System.getenv("CLASSPATH"). "

  • Does Unix support wildcard searches like DOS?

    I need to make my program (which takes arguments) to be able to support a wildcard char. when I first started testing this out, i found that DOS automatically takes care of the wildcard for me:
    ie: java myProgram c:/Alpha/*.txt
    there will be all the text files in that folder as my args array. Does Unix do this for me as well, or will I need to write code to handle this?

    It is well recognized that the common UNIX command-line shells eclipse the Windows command prompt in power. Regardless, we must use the Windows command line to invoke the jre for our Windows users. A good developer cheerfully overcomes OS and hardware constraints.
    Wildcards are useful as startup arguments to classes and for specifying JAR files on the classpath (-cp) option. My experiments and this forum seem to conclude that Java on Windows will glob its command-line arguments transparently to the developer. This is a helpful feature.
    Java on Solaris presumably do this too (after all, why not). Of course, it would not need to: the UNIX shells by default do this on every command. The Windows Console does not do this, rather, the executables themselves must glob.
    Can someone reference Sun documentation that confirms this? I don't know what to search for in order to find this. Without documentation, it is one of those undocumented features that might not be supported in future releases.

  • Classpath with *.jar?

    I want to run a Java program that requires several jars. I have all the jar files ina "lib directory. How can I refer to them all in the classpath in the java command without having to list each one? I'm quite familiar with referring to one specific jar in the classpath command or two jars, but I don't want to have to construct a command line that lists 25 jars. The last time I tried this sort of thing Java required that the classpath be named expliclty. You couldn't use wildcards. Any trick I haven't seen? Thanks.
    Ken

    I want to run a Java program that requires several
    jars. I have all the jar files ina "lib directory.
    How can I refer to them all in the classpath in the
    e java command without having to list each one?You don't.
    You can make a batch or shell script that finds all the jar files in a given dir or set of dirs and adds them to the classpath, but there's no way to just tell the VM directly "use all the jars in this dir."
    If you use ant to execute your program (not necessarily the best approach), you can define classpath element and tell it to use all the jars in a dir.

  • Classpath error while building the web dynpro project

    Hi
    I have created an application in which on clicking the button on one view , next view opens and data is displayed in the tables. This data i am giving as static, and for that i have created a java file. this java file is located in the subfolder i have created in the package path i have given. While building the application, i get these two errors :
    1) The project was not built due to classpath errors (incomplete or involved in cycle).
    2) Missing required source folder 'BPOutageTable/BPOT'
    BPOutageTable is the application name, and BPOT is the subfolder in which java file is present.
    This application is similar to "The Master/Detail Viewer Application" example in the tutorials.
    Can anybody please help in this?
    Thanks & regards,
    Anupreet

    Hi,
       You have give your classpath in your "lib" folder of the Dynpro application.
       check your lib folder shows exact class path or not.
    if you wish to add any jar files import it to your lib folder so you will not have compilation problem.
    Hope it helps.If it is then close this thread.
    Regards,
    Guru

  • Using wildcards (*) in sender file adapter - FTP type

    Hi guys!
    Dooes it work using wildcards in sender file adapter (FTP type(!) (filesystem obviously work))? I tried it and it failed. it works only for exact name..
    I read some articles about FTP and the result is, that ftp work always only with 1 file, so I'm wondering, if this is possible.
    Thanks for info!
    Olian

    Thanks for all replies..
    I know of course, that * can be used, I use it in many scenarios too. But on a FileSystem. It is not working if the sender type is FTP.
    *, ., *.dat, ...  nothing like that works..  Just exact file name.
    I am able to pick up file, if I specify it's exact name, so there should be no problem with permissions..
    Please, I'd appreciate one reply with comfirmation: yes, we are using asterisk (*) , we access source files via FTP and they are processed.
    Is there anybody with this experience, that it works?
    Thank you!
    Olian

  • How to include wildcard in FTP adapter header variable?

    I have two partner links that use FTP adapters. The first one puts a file on the FTP server. It specifies a dynamic outbound file name based upon an input variable and the timestamp in the format "test_BATCHID_yyyyMMddHHmmss.csv" (e.g. test_1011_20050925153059.csv). This part works as expected.
    The second partner link is supposed to pick up a file on the same FTP server. This inbound filename will be based upon the outbound filename and another timestamp in a format such as "originalfilename.yyyyMMddHHmmss.txt" (e.g. test_1011_20050925153059.csv.20050926091541.txt). I have created a Transform action with a mapping to convert the outbound filename and assign it to the inbound header variable. It concatenates the outbound filename and ".*.txt" within the mapping. The inbound header shows up as test_1011_20050925153059.csv.*.txt in the audit, but the process hangs at the receive activity and the file never gets retrieved. Perhaps the asterisk is being interpreted literally?
    Does anyone know how to specify a wildcard character in an xpath expression in a way that it will be interpreted as a true wildcard? Or is there another way to tell the inbound adapter to look for a dynamic filename using wildcards?

    BPEL patch 1 supports performing a synchronous read using a BPEL invoke activity. The following forum post shows how to configure a read adapter manually.
    Re: Help! Three questions about FileAdapater.
    The subsequent patches of JDeveloper allow such an apdater to be configured automatically.
    ps: This adapter can be used to read a single file only i.e. you cannot use a wild character.

Maybe you are looking for

  • After upgrading to OSX 10.7.4 it says "Service Battery"

    Just upgraded to 10.7.4 and my MacBook Pro (mid 2010) now says "Service Battery". I have reset the SMC, with no results completely discharged then recharget the battery, no results Repaired disk permissions, no results Verified the disk, appears to b

  • Fireworks will not open local files

    I use a Web Page to have students navigate to either web sites or local (c: drive) files for their classes. I cannot get Fireworks to open the local files, but I can create hyperlinks in Dreamweaver and they work fine. I am trying to create a popup m

  • How do I get an ISO Image for Boot Camp?

    I can't use bootcamp because i don't have a Windows 7 ISO Image. Where can i get a Windows 7 ISO Image?

  • You can't open the application "Photos" because it may be damaged or incomplete

    Hi All, When trying to open photos after a restore I receive the error message "You can't open the application "Photos" because it may be damaged or incomplete. I have had a look under the application and the it is empty, the problem is I cannot seem

  • Error Code 801811A3 - Cant Update My Wondows Phone

    Fail to update my Windows Phone and got Error Code 801811A3. Still happen after i follow the auto fix it, and do it manually by following the instruction web help. Any other alternative to solve this error. Im using Nokia Lumia 710 and my laptop ASUS