About whether a Java reference jar supports wildcard characters

Source: Internet
Author: User

Java references jar execution Commands:

JAVA-CP.: Mysql-connector-java-5.1.24.jar:jdom-1.1.jar javacptest

Description

-CP like-classpath, it is the path to the other classes that the specified class runs on, usually the class library, the jar package, the full path to the jar package, the semicolon ";" Partition on the window, and the semicolon ":" Partition on Linux. Wildcard characters are not supported and all jar packages need to be listed with a little "." Represents the current path.

about whether the jar supports wildcard characters, online answers a lot, but some people say that support, some people say not support, I test results: not supported, testing code (using the 2 jar Self-downloaded after the classpath):

public class Javacptest {

public static void Main (string[] args) {

try {

Class<?> clazz=class.forname ("Com.mysql.jdbc.Driver");

System.out.println (Clazz);

Class<?> clazz2=class.forname ("Org.jdom.adapters.AbstractDOMAdapter");

System.out.println (CLAZZ2);

} catch (Exception e) {

E.printstacktrace ();

}

}

}

Execution: java-cp.: Mysql-connector-java-5.1.24.jar:jdom-1.1.jar javacptest

Class Com.mysql.jdbc.Driver

Class Org.jdom.adapters.AbstractDOMAdapter

Execution: java-cp.:*. Jar Javacptest

Java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

At Java.net.urlclassloader$1.run (urlclassloader.java:366)

At Java.net.urlclassloader$1.run (urlclassloader.java:355)

At java.security.AccessController.doPrivileged (Native Method)

At Java.net.URLClassLoader.findClass (urlclassloader.java:354)

At Java.lang.ClassLoader.loadClass (classloader.java:425)

At Sun.misc.launcher$appclassloader.loadclass (launcher.java:308)

At Java.lang.ClassLoader.loadClass (classloader.java:358)

At JAVA.LANG.CLASS.FORNAME0 (Native Method)

At Java.lang.Class.forName (class.java:190)

At Javacptest.main (javacptest.java:4)

Therefore, a jar package reference does not support wildcard characters

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

About whether a Java reference jar supports wildcard characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.