When parsing the typeAliases tag with package as a subtag in the mybatis framework, a parsing error occurs. I used jdk9 as a development environment - mybatis

Environment Configure
jdk9
mybatis v3.5.4
MacOS
Description
When I was studying Mybatis, I encountered confusing questions. The configuration in question is as follows:
<configuration>
<typeAliases>
<package name="com.xxx.entity" />
</typeAliases>
</configuration>
The code to start mybatis is as follows:
// the var of CONFIG_LOCATION is the url for mybatis configure
Reader config = Resources.getResourceAsStream(CONFIG_LOCATION);
SqlSessionFactory sqlSessioinFactory = new SqlSessionFactoryBuilder().build(config);
When parsing the typeAliases tag, if the subtag is package, an exception will be thrown:
Error building SqlSession.
The error may exist in SQL Mapper Configuration
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.nio.file.InvalidPathException: Nul character not allowed: com/akamonk/ruixun/entity/Cart.class/����5+ " # $ %
at org.mybatis#3.5.4/org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.mybatis#3.5.4/org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.mybatis#3.5.4/org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at s2.project/com.akamonk.ruixun.listener.ContextLoader.initContext(ContextLoader.java:39)
at s2.project/com.akamonk.ruixun.listener.ContextLoader.main(ContextLoader.java:59)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.nio.file.InvalidPathException: Nul character not allowed: com/akamonk/ruixun/entity/Cart.class/����5+ " # $ %
at org.mybatis#3.5.4/org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
at org.mybatis#3.5.4/org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)
at org.mybatis#3.5.4/org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
... 3 more
Caused by: java.nio.file.InvalidPathException: Nul character not allowed: com/akamonk/ruixun/entity/Cart.class/����5+ " # $ %
at java.base/sun.nio.fs.UnixPath.checkNotNul(UnixPath.java:91)
at java.base/sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:81)
at java.base/sun.nio.fs.UnixPath.<init>(UnixPath.java:69)
at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:280)
at java.base/jdk.internal.module.Resources.toSafeFilePath(Resources.java:138)
at java.base/jdk.internal.module.Resources.toFilePath(Resources.java:97)
at java.base/jdk.internal.module.ModuleReferences$ExplodedModuleReader.find(ModuleReferences.java:384)
at java.base/jdk.internal.loader.BuiltinClassLoader$2.run(BuiltinClassLoader.java:408)
at java.base/jdk.internal.loader.BuiltinClassLoader$2.run(BuiltinClassLoader.java:403)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/jdk.internal.loader.BuiltinClassLoader.findMiscResource(BuiltinClassLoader.java:402)
at java.base/jdk.internal.loader.BuiltinClassLoader.findResources(BuiltinClassLoader.java:333)
at java.base/java.lang.ClassLoader.getResources(ClassLoader.java:1457)
at org.mybatis#3.5.4/org.apache.ibatis.io.VFS.getResources(VFS.java:171)
at org.mybatis#3.5.4/org.apache.ibatis.io.DefaultVFS.list(DefaultVFS.java:105)
at org.mybatis#3.5.4/org.apache.ibatis.io.DefaultVFS.list(DefaultVFS.java:153)
at org.mybatis#3.5.4/org.apache.ibatis.io.VFS.list(VFS.java:200)
at org.mybatis#3.5.4/org.apache.ibatis.io.ResolverUtil.find(ResolverUtil.java:220)
at org.mybatis#3.5.4/org.apache.ibatis.type.TypeAliasRegistry.registerAliases(TypeAliasRegistry.java:130)
at org.mybatis#3.5.4/org.apache.ibatis.type.TypeAliasRegistry.registerAliases(TypeAliasRegistry.java:125)
at org.mybatis#3.5.4/org.apache.ibatis.builder.xml.XMLConfigBuilder.typeAliasesElement(XMLConfigBuilder.java:164)
at org.mybatis#3.5.4/org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)
... 5 more
At this time, the content of module-info.java is as follows
open module mybatis.test {
requires org.mybatis;
requires java.sql;
}
There is a strange phenomenon, when I remove the module-info.java from the project, mybatis will not have problems when parsing typeAliases.Therefore, my bold guess is caused by JDK9. But I don't know how to solve it and the specific cause of the problem

Related

Adding custom handler to jetty throws ClassNotFoundException

I am trying to inject a custom handler to jetty.
I have written the handler in my application code which is packaged as a war.
package com.foo.bar
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.eclipse.jetty.server.Request
import org.eclipse.jetty.server.handler.AbstractHandler
// scalastyle:off println
class CustomJettyHandler extends AbstractHandler {
override def handle(target: String, baseRequest: Request,
request: HttpServletRequest, response: HttpServletResponse): Unit = {
println("This is a custom jetty handler")
}
}
// scalastyle:on println
I have then injected this handler in the jetty.xml file:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
........
........
<Call name="insertHandler">
<Arg>
<New id="CustomJettyHandler" class="com.foo.bar.CustomJettyHandler"/>
</Arg>
</Call>
........
I am now running jetty in standalone mode. Note that I am passing the location where CustomJettyHandler.class resides to jetty-start.jar.
java -server -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -jar lib/jetty-start.jar OPTIONS=All --lib=lib/* --lib=webapps/root/WEB-INF/classes/com/foo/bar/* etc/jetty.xml etc/jetty-jmx.xml --debug
In my application logs, I can see jetty loading my custom handler to its classpath but then eventually failing because of ClassNotFoundException. Can someone point out where could this be going wrong?
.......
rawlibref = webapps/root/WEB-INF/classes/com/foo/bar/*
expanded = webapps/root/WEB-INF/classes/com/foo/bar/*
getPaths('webapps/root/WEB-INF/classes/com/foo/bar/*')
Using relative path pattern: glob:**/webapps/root/WEB-INF/classes/com/foo/bar/*
Found [webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class] /Users/...path_to_application.../webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class
Adding classpath component: /Users/...path_to_application.../webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class
.......
.......
.......
URLClassLoader.url[33] = file:/Users/...path_to_application.../webapps/root/WEB-INF/classes/com/foo/bar/CustomJettyHandler.class
Loaded 34 URLs into URLClassLoader
class org.eclipse.jetty.xml.XmlConfiguration - 9.4.24.v20191120
Command Line Args: /var/folders/z5/dmt38gq54kxcrrzpgvbl5m_c0000gp/T/start_6046998329479549547.properties /Users/...path_to_application.../etc/jetty.xml /Users/...path_to_application.../etc/jetty-jmx.xml
2020-05-27 14:46:13.676:INFO::main: Logging initialized #477ms to org.eclipse.jetty.util.log.StdErrLog
2020-05-27 14:46:13.934:INFO:oeju.TypeUtil:main: JVM Runtime does not support Modules
2020-05-27 14:46:14.007:WARN:oejx.XmlConfiguration:main: Config error at <Call name="insertHandler"><Arg>| <New id="CustomJettyHandler" class="com.foo.bar.CustomJettyHandler"/>| </Arg></Call> java.lang.ClassNotFoundException: com.foo.bar.CustomJettyHandler in file:///Users/...path_to_application.../etc/jetty.xml
2020-05-27 14:46:14.007:WARN:oejx.XmlConfiguration:main:
java.security.PrivilegedActionException: java.lang.ClassNotFoundException: com.foo.bar.CustomJettyHandler
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
at org.eclipse.jetty.start.Main.start(Main.java:491)
at org.eclipse.jetty.start.Main.main(Main.java:77)
Caused by:
java.lang.ClassNotFoundException: com.foo.bar.CustomJettyHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:64)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:1028)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1539)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.access$500(XmlConfiguration.java:369)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$AttrOrElementNode.getList(XmlConfiguration.java:1768)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$AttrOrElementNode.getList(XmlConfiguration.java:1744)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.call(XmlConfiguration.java:919)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:512)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:454)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:354)
at org.eclipse.jetty.xml.XmlConfiguration.lambda$main$0(XmlConfiguration.java:1874)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
at org.eclipse.jetty.start.Main.start(Main.java:491)
at org.eclipse.jetty.start.Main.main(Main.java:77)
Where did you get this command line from?
java -server \
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog\
-jar lib/jetty-start.jar\
OPTIONS=All \
--lib=lib/* \
--lib=webapps/root/WEB-INF/classes/com/foo/bar/* \
etc/jetty.xml \
etc/jetty-jmx.xml \
--debug
That's not valid for use with Jetty 9.x's start.jar
Some advice
don't use XML directly on the java command line, that's the responsibility of the start.jar and the jetty-home module system (order is SUPER IMPORTANT).
Your choices of etc/jetty.xml and etc/jetty-jmx.xml is an incomplete list of xmls. (you are missing all dependent XML files)
don't edit the standard Jetty XML files, leave them be, otherwise you'll complicate upgrades later. Use XML to inject your behavior instead (see below for example)
OPTIONS is not supported by Jetty 9.x (that's old school Codehaus / Jetty 6 behavior)
Your usage of --lib= is discouraged, it only supports fully qualified paths to jars or directories with exploded class trees (not relative paths, no globs supported).
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog is a harsh way of setting up logging. Create a jetty-logging.properties files and make sure it's present on the classpath.
Example contents of jetty-logging.properties
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=INFO
#org.eclipse.jetty.deploy.LEVEL=DEBUG
Do this instead.
Create an injection based XML for your new handler.
my-handler.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="insertHandler">
<Arg>
<New id="CustomJettyHandler" class="com.foo.bar.CustomJettyHandler" />
</Arg>
</Call>
</Configure>
Next create your jetty-base directory properly (for jetty's start.jar)
# Create your "jetty-base" directory
$ mkdir /path/to/myjettybase
$ cd /path/to/myjettybase
# Establish the basic files / directories / modules that you want to use
# You can find the configuration in start.ini or start.d/*.ini
$ java -jar /path/to/jetty-home/start.jar --add-to-start=http,jmx,deploy,ext,resources
# Copy your custom handler JAR into place
$ cp /path/to/my-handlers.jar /path/to/myjettybase/lib/ext/
# Copy your custom handler XML into place
$ cp /path/to/my-handler.xml /path/to/myjettybase/etc/
# Ensure that the custom handler XML is loaded into the jetty instance at the right point in the XML load order by declaring it to be used in a custom INI
$ mkdir start.d
$ echo "etc/my-handler.xml" >> start.d/my-handlers.ini
# Copy your jetty-logging.properties into place
$ cp /path/to/my-jetty-logging.properties /path/to/myjettybase/resources/jetty-logging.properties
# verify that your configuration looks sane (including the server classpath)
$ cd /path/to/myjettybase
$ java -jar /path/to/jetty-home/start.jar --list-config
# run your instance
$ cd /path/to/myjettybase
$ java -jar /path/to/jetty-home/start.jar
But that's not all, seeing as you seem to want to use jetty-home from a maven-style project (or project layout), you can do that too!
An example project showing this can be found at ...
https://github.com/jetty-project/servlet-error-page-handling
That maven project is also a valid jetty-base directory suitable for execution by a jetty-home archive somewhere else on your machine.

Argument does not begin with '--' error while executing Apache Beam WordCount example from Eclipse in java

I'm trying to execute the example WordCount(Java code) from Eclipse as specified in
https://cloud.google.com/dataflow/docs/quickstarts/quickstart-java-eclipse#run-the-wordcount-example-pipeline-on-the-cloud-dataflow-service
While executing through RunConfiguration, getting below error in Eclipse console.
Exception in thread "main" java.lang.IllegalArgumentException: Argument '-output=gs://bucket-for-beam/stage-folder/output-file-prefix' does not begin with '--'
at org.apache.beam.repackaged.beam_sdks_java_core.com.google.common.base.Preconditions.checkArgument(Preconditions.java:191)
at org.apache.beam.sdk.option[s.PipelineOptionsFactory.parseCommandLine(PipelineOptionsFactory.java:1423)
at org.apache.beam.sdk.options.PipelineOptionsFactory.access$200(PipelineOptionsFactory.java:110)
at org.apache.beam.sdk.options.PipelineOptionsFactory$Builder.as(PipelineOptionsFactory.java:294)
at com.gcp.dataflow.examples.WordCount.main(WordCount.java:190)][1]
I've created a bucket, named 'bucket-for-beam' folder,named 'stage-folder':
- and -- are different. You have specified the first one on the arguments tab. It expects the second one.
For me it was due to a space in between the different option of the commands

How to Launch Spring batch using CommandLineJobRunner without java configuration instead of XML

I have a job definition in a java configuration file. When I try and run the job from gradle task, I get IOException parsing XML Document from class path. How do I run a job using CommandLineJobRunner without XML configuration?
Gradle
task executeJob(type: JavaExec) {
main = 'org.springframework.batch.core.launch.support.CommandLineJobRunner'
classpath = sourceSets.test.runtimeClasspath
args = ["--job_path", "C:\\dev\\git\\ncf-bulk-order\\src\\main\\java\\com\\shelter\\NCFBulkOrder\\Jobs\\NCFBulkOrderConfig.java",
"--job_id", "Response",
"--next",
"--customParam", "value"]
}
StackTrace
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [--job_path]; nested exception is java.io.FileNotFoundException: class path resource [--job_path] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:290)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:565)
Caused by: java.io.FileNotFoundException: class path resource [--job_path] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
... 14 common frames omitted
The CommandLineJobRunner expects either the XML file or the Java configuration class containing the Spring application context where your job is defined. Here is an example with a Java config class:
java -cp your/class/path \
org.springframework.batch.core.launch.support.CommandLineJobRunner \
com.example.MyJobConfiguration \
myJob
So in your command, you don't need to pass the --job_path flag.

MyBatis: Error when adding a 'bind' inside of 'foreach'

I'm using MyBatis for handling SQL queries. Here is my problematic piece of code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.foo.Foo">
...
<insert id="insert" parameterType="com.foo.FooParam">
<foreach collection="bars" item="bar" separator=" ">
<bind name="inFavorites" value="bar.sectionId == '_favorites'" />
<foreach collection="bar.bars2" item="bar2" index="index" separator=" ">
...
</foreach>
</foreach>
</insert>
...
</mapper>
Intelij shows the following error when validiting the xml:
Error:(24, 74) Element type "bind" must be declared.
Error:(28, 19) The content of element type "foreach" must match "(include|trim|where|set|foreach|choose|if)".
And when i put a compiled module as an osgi package in a jetty server (mvn compiles it w/o errors and warnings) I'm getting the following error:
lineNumber: 28; columnNumber: 19; The content of element type "foreach"
must match "(include|trim|where|set|foreach|choose|if)".
So Ok, I get this. I cannot add a 'bind' element inside of a 'foreach'.
But why, if http://mybatis.org/dtd/mybatis-3-mapper.dtd says otherwise?
<!ELEMENT foreach (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
bind inside foreach is allowed since version 3.2.3. You are obviously using an older version.
dtd file is not downloaded from the internet but the version packaged in mybatis jar is used.

java classpath wildcard behaviour

I've used the java -classpath wildcard expansion feature previously and successfully. I'm currently experiencing a strange problem with it.
The wildcard is supposed to expand to every jar in the named folder. Here's a quote from Oracle:
Class path entries can contain the basename wildcard character *,
which is considered equivalent to specifying a list of all the files
in the directory with the extension .jar or .JAR. For example, the
class path entry foo/* specifies all JAR files in the directory
named foo. A classpath entry consisting simply of * expands to a
list of all the jar files in the current directory.
This is a link to Oracle doc on Java 6 on the subject of classpath.
The behaviour I am seeing contradicts this. Here are 3 runs. The first explicitly names the jar and so it works. The others use a wildcard and fail. Why? This matters to me because I rely on wildcards (elsewhere) and so an understanding of this unexpected behaviour is important to me.
#!/bin/bash
printf "The EV is...\n"
echo $CLASSPATH
printf "The working directory is...\n"
pwd
printf "Directory listing...\n"
ls
printf "END of directory listing.\n"
printf "Test with named jar.\n"
java -javaagent:../sizeof/sizeof.jar -classpath ./testsizeof.jar info.zqxj.test.Tester
printf "Test with star.\n"
java -javaagent:../sizeof/sizeof.jar -classpath * info.zqxj.test.Tester
printf "Test with dot slash star.\n"
java -javaagent:../sizeof/sizeof.jar -classpath ./* info.zqxj.test.Tester
The output:
The EV is...
The working directory is...
/home/b/Documents/workspace/testsizeof
Directory listing...
bin run.sh src testsizeof.jar
END of directory listing.
Test with named jar.
40
Test with star.
Exception in thread "main" java.lang.NoClassDefFoundError: run/sh
Caused by: java.lang.ClassNotFoundException: run.sh
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: run.sh. Program will exit.
Test with dot slash star.
Exception in thread "main" java.lang.NoClassDefFoundError: //run/sh
Caused by: java.lang.ClassNotFoundException: ..run.sh
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: ./run.sh. Program will exit.
Solution, double quote the classpath argument. Example: -classpath "*" This is necessary on the command line as well as inside a bash script.
A subsequent addendum:
Furthermore, note that -classpath "~/folder/*" fails but -classpath ~/folder/"*" is good. Quote the wildcard but do not quote the ~. It seems that you need the operating system to interpret ~ but you need to quote the * wildcard because you want to pass it to java for expansion in Java-fashion.
Note also that you should not ask java to expand *.jar because that will have an unintended result. The Java spec says that the correct wildcard is just the * alone.