How to fix No Manifest Attribute error in maven? - java

I am trying to use this code below to fix my "Error: No manifest attribute", when I try to run my jar file that has external dependencies instead of it.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Driver</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
However, every time I clean, then compile, then package it and run the jar. It keeps saying:
Error: Could not find or load main class com.harriott.Driver
Caused by: java.lang.ClassNotFoundException: Driver
P.S. I only have one class with a Public static void main method, and it is named Driver:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.harriott</groupId>
<artifactId>UpsDriver</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Driver</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>CommonLogging</artifactId>
<version>1.00</version>
</dependency>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>CommonsNet</artifactId>
<version>1.00</version>
</dependency>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>cwjcafips</artifactId>
<version>1.00</version>
</dependency>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>cwjssefips</artifactId>
<version>1.00</version>
</dependency>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>MortbayJetty</artifactId>
<version>1.00</version>
</dependency>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>JavaxServlet</artifactId>
<version>1.00</version>
</dependency>
<dependency>
<groupId>com.cloakware.cspm.client</groupId>
<artifactId>CSPMClient</artifactId>
<version>1.00</version>
</dependency>
</dependencies>
</project>
This is my java code:
import com.cloakware.cspm.client.CSPMClient;
public class Driver {
/**
* Main entry point.
*
* #param "args[0]", String target alias
*
* #param "args[1]", bypass cache flag. If set to:
*
* "true", the cspm client will call the cspm server system
*
* "false", the cspm client will 1st search the local cache
*#param "args[2]", xmlOption. (Optional) If set to:
*
* "-x", Gives the XML data.
* #return int 0 if successful, 100 if an exception ocurred, otherwise
* documented error codes for the CSPMClient class.
*
*/
public static void main(String[] args) {
try {
CSPMClient testInterface = new CSPMClient();
System.out.println("------------------------------------");
System.out.println(testInterface.getAllCredentials());
//System.out.println(testInterface.retrieveCredentials("emc_grab",true));
System.out.println("------------------------------------");
//get the result
String statusCode = testInterface.getStatusCode();
String userId = testInterface.getUserId();
String password = testInterface.getPassword();
String xmlData = testInterface.getXMLData();
System.out.println("Status Code: " + statusCode);
System.out.println("UsedId: " + userId);
System.out.println("Password: " + password);
System.out.println("XML Data: " + xmlData);
//set the return value
if (statusCode.equals("400")) {
System.out.println("PASSED");
System.exit(0);
} else {
System.out.println("FAILED");
System.exit(Integer.parseInt(statusCode));
}
} catch(Exception e) {
e.printStackTrace();
System.exit(100);
}catch(UnsatisfiedLinkError unsatisfiedLinkError){
System.out.println("UnsatisfiedLinkError>>>>");
System.out.println(unsatisfiedLinkError.getMessage());
}
}
}
I will also get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/cloakware/cspm/client/CSPMClient
at Driver.main(Driver.java:29)
Caused by: java.lang.ClassNotFoundException: com.cloakware.cspm.client.CSPMClient
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

Related

Maven mysql-connector dependency doesnt work

This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>id</groupId>
<artifactId>jbdc_project</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
</project>
I tried to connect to MySQL database:
public class Main {
public static void main(String[] args) {
String url = "jbdc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false";
String user = "root";
String password = "root";
try{
Connection myConn = DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
And i get this error:
java.sql.SQLException: No suitable driver found for jbdc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false
Any ideas on how to fix it?
Got it.
There's a typo in your JDBC URL. It should be 'jdbc' instead of 'jbdc'.
String url = "jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false";

import org.neo4j cannot be resolved?

I am very new to Neo4j and I'd like to get started with an embedded Neo4j in a Java Application. I try to run a HelloWorld Application as follows.
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.neo4j.driver.Result;
import org.neo4j.driver.Transaction;
import org.neo4j.driver.TransactionWork;
import static org.neo4j.driver.Values.parameters;
public class HelloWorldExample implements AutoCloseable
{
private final Driver driver;
public HelloWorldExample( String uri, String user, String password )
{
driver = GraphDatabase.driver( uri, AuthTokens.basic( user, password ) );
}
#Override
public void close() throws Exception
{
driver.close();
}
public void printGreeting( final String message )
{
try ( Session session = driver.session() )
{
String greeting = session.writeTransaction( new TransactionWork<String>()
{
#Override
public String execute( Transaction tx )
{
Result result = tx.run( "CREATE (a:Greeting) " +
"SET a.message = $message " +
"RETURN a.message + ', from node ' + id(a)",
parameters( "message", message ) );
return result.single().get( 0 ).asString();
}
} );
System.out.println( greeting );
}
}
public static void main( String... args ) throws Exception
{
try ( HelloWorldExample greeter = new HelloWorldExample( "bolt://localhost:7687", "neo4j", "password" ) )
{
greeter.printGreeting( "hello, world" );
}
}
}
The Pom code is as follows.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>4.0.1</version>
<name>neo4jtest</name>
<build>
<plugins>
<plugin>
<groupId>1</groupId>
<artifactId>2</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>3.1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>3.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Unfortunately I cannot run the code it raises "Exception in thread "main" java.lang.Error: Unresolved compilation problem: at HelloWorldExample.main(HelloWorldExample.java:46)". Additionally, when hovering over the import lines I see "import org.neo4j cannot be resolved".
Can somebody provide information about this?
As documented, in order to use neo4j's Java driver, you need to specify the appropriate dependency:
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>x.y.z</version>
</dependency>
The latest release version is 4.0.1.
[UPDATE]
Also, your pom.xml file has a lot of other issues. Try something like this instead:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>helloworld</artifactId>
<version>1</version>
<name>neo4jtest</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
</project>
This example POM file uses some dummy groupId, artifactId, and version values for itself (near the top). You should replace them with your own values (not values belonging to neo4j).

Jbehave 0 stories run

I'm new in java and jbehave. I wanted to try BDD with jbehave but seems doing something wrong - test run but step were not executed.
POJO CLASS:
public class Addition {
public int result;
public void addValues(int a,int b){
result=a+b;
}
public int getResult(){
return result;
}
}
STEPS CLASS:
public class AdditionStep {
private Addition calc;
#Given("open calc")
public void openCalc(){
calc=new Addition();
System.out.println("Opened calc");
}
#When("i add $number1 to $number2")
public void addition(#Named("number1")int a,#Named("number2")int b){
calc.addValues(a, b);
}
#Then("outcome is $result")
public void checkSum(#Named("result")int output){
Assert.assertEquals(output, calc.getResult());
System.out.println("Sum is : "+output);
}
}
STORY RUNNER:
public class AdditionStory extends JUnitStories {
#Override
public Configuration configuration(){
return new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).
useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().
withFormats(Format.CONSOLE,Format.TXT));
}
#Override
public InjectableStepsFactory stepsFactory(){
return new InstanceStepsFactory(configuration(),new AdditionStep());
}
#Override
protected List<String> storyPaths() {
return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()),"**/*addition*.story","");
}
}
STORY FILE:
Scenario: Add two valid numbers
Given open calc
When i add 1 to 1
Then outcome is 2`
POM FILE:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JbehaveCalculatorTest</groupId>
<artifactId>JbehaveCalculatorTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jbehave.core.version>4.1</jbehave.core.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>${jbehave.core.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/*.story</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>${jbehave.core.version}</version>
<executions>
<execution>
<id>run-stories</id>
<phase>test</phase>
<configuration>
<!--<scope>test</scope>-->
<includes>
<include>**/stories/*.java</include>
</includes>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My story file placed in src/test/java/Stories/...
OUTPUT:
Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]
(BeforeStories)
(AfterStories)
Generating reports view to 'D:\KnowledgeCentre\Workspace\JbehaveCalculatorTest\target\jbehave' using formats '[stats, console, txt]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending)
Disconnected from the target VM, address: '127.0.0.1:49908', transport: 'socket'
Process finished with exit code 0

Embeded OSGi (Felix) bundle start BundleException : missing requirement

I've got an embeded OSGi framework (Felix).
I'm installing the basic bundles without problem, I can access the Felix webconsole.
But starting libra-commons-osgi-core-wsbundle-1.4.0.war gives me this error :
"org.osgi.framework.BundleException: Unable to resolve hu.libra.commnos.osgi.core.wsbundle [9](R 9.0): missing requirement [hu.libra.commnos.osgi.core.wsbundle [9](R 9.0)] osgi.wiring.package; (osgi.wiring.package=hu.libra.commnos.osgi.core.service) Unresolved requirements: [[hu.libra.commnos.osgi.core.wsbundle [9](R 9.0)] osgi.wiring.package; (osgi.wiring.package=hu.libra.commnos.osgi.core.service)]"
hu.libra.commnos.osgi.core.service bundle is installed and started (Felix webconsole shows bundle as Active and shows the registered service)
hu.libra.commnos.osgi.core.service\META-INF\MANIFEST.MF contains
Export-Package: hu.libra.commons.osgi.core.service;version="1.4.0";uses:="org.osgi.framework"
hu.libra.commnos.osgi.core.wsbundle\META-INF\MANIFEST.MF contains
Import-Package: org.osgi.framework;version="[1.8,2)",javax.servlet,jav
ax.servlet.http,hu.libra.commnos.osgi.core.service
What is the problem? Thank You!
My embeded Framework :
.java
package hu.libra.commons.osgi.core;
import static org.osgi.framework.Constants.FRAGMENT_HOST;
import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN;
import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class LibraOSGiCore {
//LOGGING
private static final Logger log = Logger.getLogger(LibraOSGiCore.class);
//FIELDS
private static final Framework framework;
private static final List<Bundle> bundleList = new LinkedList<>();
//CONSTRUCTORS
static {
try {
//log4j
PropertyConfigurator.configure("log4j.properties");
//config
Map<String, String> config = new HashMap<>();
config.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
setConfig(config);
//framework
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
framework = frameworkFactory.newFramework(config);
framework.start();
}
catch (RuntimeException | BundleException e) {
log.fatal(e, e);
throw new RuntimeException(e);
}
}
//MAIN
public static void main(
String[] args) {
try {
try {
installBundles();
startBundles();
}
catch (IOException | BundleException e) {
log.fatal(e, e);
throw new RuntimeException(e);
}
try {
framework.waitForStop(0);
}
catch (InterruptedException e) {
return;
}
}
finally {
System.exit(0);
}
}
//METHODS - private
private static void setConfig(
Map<String, String> config) {
//TODO use config.xml
config.put("org.osgi.service.http.port", "8181");
//config.put("felix.webconsole.username", "...");
//config.put("felix.webconsole.password", "...");
}
private static Bundle installBundle(
String name,
String postfix,
String ext)
throws IOException,
BundleException {
if (postfix != null) {
postfix = "-" + postfix;
}
else {
postfix = "";
}
String resourceName = name + postfix + "." + ext;
InputStream is;
File file = new File(resourceName);
if (file.exists()) {
is = new FileInputStream(file);
}
else {
is = LibraOSGiCore.class.getResourceAsStream(resourceName);
}
try(InputStream xis = is) {
Bundle bundle = framework.getBundleContext().installBundle("file:/" + name + "." + ext, is);
return bundle;
}
}
private static void installBundles()
throws IOException,
BundleException {
//Felix basic bundles
bundleList.add(installBundle("org.apache.felix.log", "1.0.1", "jar"));
bundleList.add(installBundle("org.apache.felix.configadmin", "1.8.12", "jar"));
bundleList.add(installBundle("org.apache.felix.eventadmin", "1.4.8", "jar"));
bundleList.add(installBundle("org.apache.felix.http.servlet-api", "1.1.2", "jar"));
bundleList.add(installBundle("org.apache.felix.http.api", "3.0.0", "jar"));
//Felix Jetty bundle
bundleList.add(installBundle("org.apache.felix.http.jetty", "3.4.0", "jar"));
//Felix Webconsole bundle
bundleList.add(installBundle("org.apache.felix.webconsole", "4.2.16-all", "jar"));
//Core bundles
bundleList.add(installBundle("libra-commons-osgi-core-service", "1.4.0", "jar"));
bundleList.add(installBundle("libra-commons-osgi-core-wsbundle", "1.4.0", "war"));
}
private static void startBundles()
throws BundleException {
for (Bundle bundle : bundleList) {
if (bundle.getHeaders().get(FRAGMENT_HOST) != null)
continue;
bundle.start();
}
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-osgi-core</artifactId>
<version>1.4.0</version>
<name>Libra Common OSGi Core</name>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Bundle-SymbolicName>hu.libra.commnos.osgi.core</Bundle-SymbolicName>
</instructions>
</configuration>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
</supportedProjectTypes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<dependencies>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.6.1</version>
</dependency>
</dependencies>
</project>
hu.libra.commnos.osgi.core.service pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-osgi-core-service</artifactId>
<version>1.4.0</version>
<name>Libra Common OSGi Core Service Bundle</name>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>hu.libra.commons.osgi.core.service</Bundle-SymbolicName>
<Bundle-Activator>hu.libra.commons.osgi.core.service.Activator</Bundle-Activator>
<Export-Package>hu.libra.commons.osgi.core.service</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
hu.libra.commnos.osgi.core.wsbundle pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-osgi-core-wsbundle</artifactId>
<version>1.4.0</version>
<name>Libra Common OSGi Core Webservice Bundle</name>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>hu.libra.commnos.osgi.core.wsbundle</Bundle-SymbolicName>
<Bundle-Activator>hu.libra.commons.osgi.core.wsbundle.Activator</Bundle-Activator>
<Private-Package>hu.libra.commons.osgi.core.wsbundle</Private-Package>
<Import-Package>
org.osgi.framework,
javax.servlet,
javax.servlet.http,
javax.servlet.*,
javax.servlet.jsp.*,
javax.servlet.jsp.jstl.*,
hu.libra.commnos.osgi.core.service
</Import-Package>
<DynamicImport-Package>
javax.*,
org.xml.sax,
org.xml.sax.*,
org.w3c.*
</DynamicImport-Package>
<Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Web-ContextPath>/libraosgicore</Web-ContextPath>
<Webapp-Context>/libraosgicore</Webapp-Context>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- Libra OSGi Core Service -->
<dependency>
<groupId>hu.libra.commons</groupId>
<artifactId>libra-commons-osgi-core-service</artifactId>
<version>1.4.0</version>
<scope>provided</scope>
</dependency>
<!-- WS -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
</dependencies>
</project>

How to run web application on hadoop and phoenix

I installed hadoop,hbase and phoenix in ubuntu 14 and runed a simple example for connecting phoenix in eclipse. It's work and execute my query.
public static void execute() throws ClassNotFoundException {
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
PreparedStatement ps = null;
try {
connection = DriverManager.getConnection("jdbc:phoenix:localhost");
statement = connection.createStatement();
// Query for table
ps = connection.prepareStatement("select * from dum.user_info where id=25 ");
rs = ps.executeQuery();
System.out.println("Table Values");
while (rs.next()) {
Integer myKey = rs.getInt(1);
String myColumn = rs.getString(2);
System.out.println("\tRow: " + myKey + " = " + myColumn);
System.out.println("" + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5) + " "
+ rs.getString(6) + " " + rs.getString(7));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Now I'd like to run a web application that connect to phoenix.
I installed tomcat and create a web dynamic application, I can run it and view page in browser but when I add execute function, it doesn't work.
public class LoginServlet extends HttpServlet {
private LoginService userValidationService = new LoginService();
private TodoService todoService = new TodoService();
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
phoenixHelper.execute();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(
request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String password = request.getParameter("password");
boolean isUserValid = userValidationService.isUserValid(name, password);
if (isUserValid) {
request.getSession().setAttribute("name", name);
response.sendRedirect("/list-todos.do");
} else {
request.setAttribute("errorMessage", "Invalid Credentials!");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(
request, response);
}
}
}
I faced this error:
java.sql.SQLException: No suitable driver found for jdbc:phoenix:localhost
Can anybody tell me how to run a web application that connect to phoenix?
It's pom.xml.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.in28minutes</groupId>
<artifactId>in28Minutes-first-webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.6.0-HBase-1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<verbose>true</verbose>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.geekcap.javaworld.phoenixexample.PhoenixExample</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Try loading the driver before creating the connection.
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

Categories

Resources