我使用maven程序集插件创建了一个胖罐。以下是隐藏了一些敏感细节的pom文件: -
<modelVersion>4.0.0</modelVersion>
<groupId>labs.rule</groupId>
<artifactId>labs-engine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Labs Engine</name>
<description>Rule engines @ XXX</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>main.java.labs.RuleEngine</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- distributionManagement entry is for enabling upload to bidstalk maven
repos -->
<repositories>
<repository>
<id>My-maven-repository</id>
<name>My-maven-repository-releases</name>
<url>http://X.Y.Z.W:ZZZ/artifactory/simple/My</url>
</repository>
<repository>
<id>sonatype-forge</id>
<url>https://repository.sonatype.org/content/groups/forge/</url>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>My-maven-repository</id>
<name>My-maven-repository-snapshots</name>
<url>http://X.Y.Z.W:ZZZ/artifactory/simple/My</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-redshift</artifactId>
<version>1.11.31</version>
</dependency>
<dependency>
<groupId>com.applift.commonslib</groupId>
<artifactId>alertslib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.amazon</groupId>
<artifactId>redshift.jdbc41</artifactId>
<version>1.1.13.1013</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
</project>
我可以从eclipse运行代码,但是我需要部署一个胖jar,我在封装阶段在maven中创建了它。
然而,当我尝试使用以下方式运行jar时: -
java -jar target/labs-engine-0.0.1-SNAPSHOT-jar-with-dependencies.jar
它给出了以下例外: -
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://X-Y-Z.com:3306/labs_staging
现在创造胖罐时我缺少什么?请注意: -
修改
输出mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Labs Engine 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ labs-engine ---
[INFO] Deleting /Users/mangat/Documents/workspace/labs-rule-engine/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ labs-engine ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/mangat/Documents/workspace/labs-rule-engine/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ labs-engine ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 8 source files to /Users/mangat/Documents/workspace/labs-rule-engine/target/classes
[WARNING] /Users/mangat/Documents/workspace/labs-rule-engine/src/main/java/labs/RuleEngineAerospikeConnection.java: /Users/mangat/Documents/workspace/labs-rule-engine/src/main/java/labs/RuleEngineAerospikeConnection.java uses unchecked or unsafe operations.
[WARNING] /Users/mangat/Documents/workspace/labs-rule-engine/src/main/java/labs/RuleEngineAerospikeConnection.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ labs-engine ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/mangat/Documents/workspace/labs-rule-engine/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ labs-engine ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ labs-engine ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ labs-engine ---
[INFO] Building jar: /Users/mangat/Documents/workspace/labs-rule-engine/target/labs-engine-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-assembly-plugin:2.4.1:single (make-assembly) @ labs-engine ---
[INFO] Building jar: /Users/mangat/Documents/workspace/labs-rule-engine/target/labs-engine-0.0.1-SNAPSHOT-jar-with-dependencies.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ labs-engine ---
[INFO] Installing /Users/mangat/Documents/workspace/labs-rule-engine/target/labs-engine-0.0.1-SNAPSHOT.jar to /Users/mangat/.m2/repository/labs/rule/labs-engine/0.0.1-SNAPSHOT/labs-engine-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/mangat/Documents/workspace/labs-rule-engine/pom.xml to /Users/mangat/.m2/repository/labs/rule/labs-engine/0.0.1-SNAPSHOT/labs-engine-0.0.1-SNAPSHOT.pom
[INFO] Installing /Users/mangat/Documents/workspace/labs-rule-engine/target/labs-engine-0.0.1-SNAPSHOT-jar-with-dependencies.jar to /Users/mangat/.m2/repository/labs/rule/labs-engine/0.0.1-SNAPSHOT/labs-engine-0.0.1-SNAPSHOT-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.707 s
[INFO] Finished at: 2016-09-12T20:13:32+05:30
[INFO] Final Memory: 43M/379M
[INFO] ------------------------------------------------------------------------
答案 0 :(得分:1)
尝试下一个修补程序。
使用下一个内容添加到项目资源O(logN)
文件中:
META-INF/services/java.sql.Driver
构建之后确保com.mysql.jdbc.Driver
com.mysql.fabric.jdbc.FabricMySQLDriver
文件(它是普通的zip文件,将其重命名为内部)包含具有正确内容的文件。
这不是最好的解决方案,但如果它有帮助我们可以找到一个。