From the Oracle (Java 8) documentation:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html
Class Path Wild Cards
Class path entries can contain the base name wildcard character (*),
which is considered equivalent to specifying a list of all of the
files in the directory with the extension .jar or .JAR. For example,
the class path entry mydir/* specifies all JAR files in the
directory named mydir. A class path entry consisting of * expands to
a list of all the jar files in the current directory. Files are
considered regardless of whether they are hidden (have names
beginning with '.').
A class path entry that contains an asterisk (*) does not match
class files. To match both classes and JAR files in a single
directory mydir, use either mydir:mydir/* or mydir/*:mydir. The
order chosen determines whether the classes and resources in mydir
are loaded before JAR files in mydir or vice versa.
Subdirectories are not searched recursively. For example, mydir/*
searches for JAR files only in mydir, not in mydir/subdir1,
mydir/subdir2, and so on.
The order in which the JAR files in a directory are enumerated in
the expanded class path is not specified and may vary from platform
to platform and even from moment to moment on the same machine. A
well-constructed application should not depend upon any particular
order. If a specific order is required, then the JAR files can be
enumerated explicitly in the class path.
Expansion of wild cards is done early, before the invocation of a
program's main method, rather than late, during the class-loading
process. Each element of the input class path that contains a
wildcard is replaced by the (possibly empty) sequence of elements
generated by enumerating the JAR files in the named directory. For
example, if the directory mydir contains a.jar, b.jar, and c.jar,
then the class path mydir/* is expanded into
mydir/a.jar:mydir/b.jar:mydir/c.jar, and that string would be the
value of the system property java.class.path.
The CLASSPATH environment variable is not treated any differently
from the -classpath or -cp options. Wild cards are honored in all of
these cases. However, class path wild cards are not honored in the
Class-Path jar-manifest header.
-Terence
On 2024/06/08 12:10:05 Dave Breeze wrote:
> hi
> first thank you for the insights. I did not realise that the wildcard
> was expanded by the shell. I thought this was handled by java itself.
>
> However in my instance the jvm is not being created by a shell but by
> a JNI wrapper. Originally this JNI wrapper included myDir/lib/*.jar in
> the classpath setting - this caused
> org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance to attempt
> to unzip a file of myDir/lib/*.jar - and caused a
> FileNotFoundException.
>
> in response to your update I changed the wrapper to navigate through
> myDir and construct a classpath containing every jar (approx 100
> files). This enabled the embedded Tomcat instance to resolve all
> referenced classes
>
> thanks again
> Dave Breeze
> Linkedin:https://uk.linkedin.com/in/dabreeze
>
> On Fri, 7 Jun 2024 at 15:02, Chuck Caldarale <n8...@gmail.com> wrote:
> >
> >
> > > On Jun 7, 2024, at 08:11, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> > >
> > > On 6/7/24 01:49, Mark Thomas wrote:
> > >> On 06/06/2024 18:48, Dave Breeze wrote:
> > >>> Thanks Mark
> > >>> appreciate that the url was for 8.0
> > >>>
> > >>> With regards to classpath that was my first attempt -
unfortunately it
> > >>> would seem that Tomcat does not support wildcards in the
classpath -
> > >>> for example dirpath/lib/*.jar - at least in version 9.
> > >> The requirements for setting the class path are set by the JVM,
not by Tomcat. If you want all the JARs in a directory to be included in
the class path then you should add dirpath/lib/* to the class path.
> > >
> > > I think you'd have to specifically mention every .jar file in
that directory in the classpath, right? I've never known Java to bother
resolving glob patterns on its own. This is usually the responsibility
of the command shell.
> >
> >
> > As Mark stated, you can use an asterisk appended to a directory
path in the CLASSPATH value to add all of the jars in that directory to
the classpath. (It’s been that way since Java 6.) This works even
without shell expansion. For example,
> >
> > java -cp mylib/* ClassName
> >
> > does use shell expansion, but will fail if there is more than one
file in mylib, since the shell doesn’t generate path separators.
> >
> > These constructs:
> >
> > java -cp .:mylib/* ClassName [works in bash, zsh will complain]
> > java -cp ‘mylib/*’ ClassName
> >
> > do not use shell expansion, since a Linux/UNIX shell is put off by
the colon or apostrophes.
> >
> > - Chuck
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>
--
/Terence M. Bandoian
Software Design and Development
http://www.tmbsw.com/
tere...@tmbsw.com
512.487.5887/