shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

want use maven-shade-plugin to build a single jar(all libs inside ) ,but throw error Cannot support database type 'MySQL'

Open Gkytbn opened this issue 6 years ago • 6 comments

Bug Report

My project is a jar started by the common main method, which uses shardingsphere to query the data of the sub table

The project runs normally in idea. Once it is packaged as a stand-alone jar (depending on typing into the jar), an error can not support database type 'MySQL' will be reported when it is started.

Which version of ShardingSphere did you use?

4.1.0

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

Execute SQL normally.

Actual behavior

throw error Cannot support database type 'MySQL'.

Reason analyze (If you can)

No problem keeping libs running externally. When merging into a single jar, all the class files will be decompressed and put into my jar, and an error will be reported.

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

The pom.xml are as follows.

 <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-shade-plugin</artifactId>
                            <version>3.2.2</version>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>shade</goal>
                                    </goals>

                                    <configuration>
                                        <minimizeJar>false</minimizeJar>
                                        <transformers>
                                            <transformer
                                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                                <mainClass>com.xxxxx.xxxxx</mainClass>
                                            </transformer>
                                        </transformers>
                                    </configuration>

                                </execution>
                            </executions>
                            <configuration>
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                                <artifactSet>
                                    <excludes>
                                        <exclude>commons-logging:commons-logging</exclude>-->
                                        <exclude>javax.servlet:servlet-api</exclude>
   
                                    </excludes>
                                </artifactSet>


                            </configuration>
                        </plugin>



The error are as follows.

java.lang.UnsupportedOperationException: Cannot support database type 'MySQL'
	at org.apache.shardingsphere.sql.parser.core.parser.SQLParserFactory.newInstance(SQLParserFactory.java:55)
	at org.apache.shardingsphere.sql.parser.core.parser.SQLParserExecutor.towPhaseParse(SQLParserExecutor.java:55)
	at org.apache.shardingsphere.sql.parser.core.parser.SQLParserExecutor.execute(SQLParserExecutor.java:47)
	at org.apache.shardingsphere.sql.parser.SQLParserEngine.parse0(SQLParserEngine.java:79)
	at org.apache.shardingsphere.sql.parser.SQLParserEngine.parse(SQLParserEngine.java:61)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.metadata.ShardingParameterMetaData.getParameterCount(ShardingParameterMetaData.java:36)

Gkytbn avatar May 27 '20 02:05 Gkytbn

话说, 这里要求写英文哦~ 哈哈哈

azraelee avatar May 27 '20 03:05 azraelee

排版弄一下咯

azraelee avatar May 27 '20 03:05 azraelee

English version as you wish

Gkytbn avatar May 27 '20 04:05 Gkytbn

Sorry, the problem is solved。just need marge the file META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration.

The pom file are floower.

  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>
                            <minimizeJar>false</minimizeJar>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.xxxx.xxxx</mainClass>
                                </transformer>

                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>
                                        META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration
                                    </resource>
                                </transformer>
                            </transformers>
                        </configuration>

                    </execution>
                </executions>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <artifactSet>
                        <excludes>
                           
                            <exclude>commons-logging:commons-logging</exclude>-->
                            <exclude>javax.servlet:servlet-api</exclude>
                           
                        </excludes>
                    </artifactSet>


                </configuration>
            </plugin>

Gkytbn avatar May 27 '20 06:05 Gkytbn

Sorry, the problem is solved。just need marge the file META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration.

The pom file are floower.

  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>
                            <minimizeJar>false</minimizeJar>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.xxxx.xxxx</mainClass>
                                </transformer>

                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>
                                        META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration
                                    </resource>
                                </transformer>
                            </transformers>
                        </configuration>

                    </execution>
                </executions>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <artifactSet>
                        <excludes>
                           
                            <exclude>commons-logging:commons-logging</exclude>-->
                            <exclude>javax.servlet:servlet-api</exclude>
                           
                        </excludes>
                    </artifactSet>


                </configuration>
            </plugin>

I have a similar problem when I use sharding-jdbc-spring-namespace (4.1.1 version) Execute SQL.it reminds me Error querying database. Cause: java.lang.UnsupportedOperationException: Cannot support database type 'MySQL'. In fact I do not understand your answer(just need marge the file META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration),

wang7241 avatar Jul 09 '20 04:07 wang7241

Sorry, the problem is solved。just need marge the file META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration.

The pom file are floower.

  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>
                            <minimizeJar>false</minimizeJar>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.xxxx.xxxx</mainClass>
                                </transformer>

                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>
                                        META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration
                                    </resource>
                                </transformer>
                            </transformers>
                        </configuration>

                    </execution>
                </executions>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <artifactSet>
                        <excludes>
                           
                            <exclude>commons-logging:commons-logging</exclude>-->
                            <exclude>javax.servlet:servlet-api</exclude>
                           
                        </excludes>
                    </artifactSet>


                </configuration>
            </plugin>

please ignore my last question,I have solved

wang7241 avatar Jul 09 '20 08:07 wang7241