I downloaded the mongo-java-driver-2.11.2.jar file from here -
http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.11.3/
In my example application i have following code -
import com.mongodb.MongoClient;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.ServerAddress;
import java.util.Arrays;
MongoClient mongoclient = new MongoClient("localhost",27017);
DB db = mongoclient.getDB("test1");
I always get this error -
[parsing started RegularFileObject[myfile.java]]
myfile.java:11: class, interface, or enum expected
MongoClient mongoclient = new MongoClient("localhost",27017);
^
myfile.java:12: class, interface, or enum expected
DB db = mongoclient.getDB("test1");▒
^
[parsing completed 26ms]
[total 54ms]
2 errors
I tried various compiling options:
javac myfile.java
since .jar is in same directory.
javac -cp '.:mongo-java-driver-2.11.2.jar' myfile.java
or even the full path to the file
javac -classpath '/home/nimish/HTMLProjects/mongodbJavaIntro/mongo-java-driver-2.11.2-sources.jar' myfile.java -verbose
But to no avail. Can anyone shed any light on this.
You are lacking a class name:
public class myfile { ...
And lacks some basic programming practices. Should name your class MyFile or so
import com.mongodb.MongoClient;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.ServerAddress;
import java.util.Arrays;
public class myfile {
DB db;
public myfile {
initDB();
}
public void initDB() {
MongoClient mongoclient = new MongoClient("localhost",27017);
db = mongoclient.getDB("test1");
}
...
}
Related
I am trying to extend OpenTelemetry java agent and I don't see any indication it is trying to load my jar.
I am running the following cmd:
java -javaagent:../src/main/resources/opentelemetry-javaagent.jar -Dotel.javaagent.configuration-file=../src/main/resources/agent-prp.properties -jar simple-service-1.0-SNAPSHOT-jar-with-dependencies.jar
my config file is (the attributes are working):
otel.javaagent.extensions=/Users/foo/source/simple-service/src/main/resources/span-processor-1.0-SNAPSHOT.jar
otel.resource.attributes=service.name=foooBarr
my extension is:
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.SpanProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class FooSpanProcessor implements SpanProcessor {
private static final ObjectMapper objMapper = new ObjectMapper();
private static final Logger log = LoggerFactory.getLogger(FooSpanProcessor.class);
#Override
public void onStart(Context parentContext, ReadWriteSpan span) {
log.error("fffffffffff");
span.setAttribute("fooToken", FooProperties.INSTANCE.fooToken);
span.setAttribute("service.name", FooProperties.INSTANCE.serviceName);
span.setAttribute("runtime", FooProperties.INSTANCE.javaVersion);
span.setAttribute("tracerVersion", "0.0.1");
span.setAttribute("framework", FooProperties.INSTANCE.frameWork);
span.setAttribute("envs", FooProperties.INSTANCE.environment);
span.setAttribute("metaData", FooProperties.INSTANCE.metadata);
}
#Override
public boolean isStartRequired() {
return true;
}
#Override
public void onEnd(ReadableSpan span) {
}
....
I don't see any indication that my extension is loaded, I don't see any of my parameters on the produced spans. can any body help me?
"otel.javaagent.extensions" is not supported in the config file. add it with -D.
add the span processor to a config call implementing sdkTracerProviderConfigurer
I have the following class to perform PCA on a arff file. I have added the Weka jar to my project but I am still getting an error saying DataSource cannot be resolved and I don't know what to do to resolve it. Can anyone suggest what could be wrong?
package project;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.core.converters.ConverterUtils;
import weka.core.converters.ConverterUtils.DataSource;
import weka.core.converters.TextDirectoryLoader;
import weka.gui.visualize.Plot2D;
import weka.gui.visualize.PlotData2D;
import weka.gui.visualize.VisualizePanel;
import java.awt.BorderLayout;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JFrame;
import org.math.plot.FrameView;
import org.math.plot.Plot2DPanel;
import org.math.plot.PlotPanel;
import org.math.plot.plots.ScatterPlot;
import weka.attributeSelection.PrincipalComponents;
import weka.attributeSelection.Ranker;
public class PCA {
public static void main(String[] args) {
try {
// Load the Data.
DataSource source = new DataSource("../data/ingredients.arff");
Instances data = source.getDataSet();
// Perform PCA.
PrincipalComponents pca = new PrincipalComponents();
pca.setVarianceCovered(1.0);
//pca.setCenterData(true);
pca.setNormalize(true);
pca.setTransformBackToOriginal(false);
pca.buildEvaluator(data);
// Show transform data into eigenvector basis.
Instances transformedData = pca.transformedData();
System.out.println(transformedData);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Below code has an error is at the setup location.Why is this error coming up?? .The error is as follow:
There is an error in the public void Setup().
The error is The method Setup() is undefined for the type jammytestappium.
This was causing harm while executing the code.
My code looks as follows:
package com.example.jamappium;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Driver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.server.handler.FindElement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.sun.jna.platform.win32.SetupApi;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
public class Jammytestappium {
{
AndroidDriver<WebElement> abcd;
#BeforeClass
public void setup()
{
DesiredCapabilities test=new DesiredCapabilities();
test.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,
"com.veronicapps.veronica.simplecalculator");
test.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
"com.veronicapps.veronica.simplecalculator.MainActivity");
test.setCapability(MobileCapabilityType.VERSION, "4.2.2");
test.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator");
abcd = (AndroidDriver) new RemoteWebDriver(new URL(
"http://127.0.0.1:4723/wd/hub"),test);
}
}
Try removing the extra braces after "public class jammytestappium {"
I am trying to add a resource to an Arquillian shrink-wrap archive and to load it via the classpath. However, I did not manage to make it working. I tried using addAsResource() and addAsWebInfResource(). The version below is the one I think should work, but does not. Any solutions?
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
#RunWith(Arquillian.class)
public class ResourceLoadingTest {
#Deployment
public static WebArchive createDeployment() {
WebArchive archive = ShrinkWrap.create(WebArchive.class)
.addAsWebInfResource(new StringAsset("Hello World"),
"classes/test.properties");
System.out.println(archive.toString(true));
return archive;
}
#Test
public void testLoadResource() {
InputStream stream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("/test.properties");
assertNotNull(stream);
}
}
Console output:
411ad6b1-7705-406f-ba05-d7f46ca14966.war:
/WEB-INF/
/WEB-INF/classes/
/WEB-INF/classes/test.properties
I am trying to limit the number of lines each of the Mappers gets.
My code goes like this:
package com.iathao.mapreduce;
import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.lib.NLineInputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.regexp.RESyntaxException;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
public class Main {
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException, RESyntaxException {
try {
if (args.length != 2) {
System.err.println("Usage: NewMaxTemperature <input path> <output path>");
System.exit(-1);
}
Job job = new Job();
job.setJarByClass(Main.class);
job.getConfiguration().set("mapred.max.map.failures.percent", "100");
// job.getConfiguration().set("mapred.map.max.attempts", "10");
//NLineInputFormat. .setNumLinesPerSplit(job, 1);
job.setInputFormatClass(NLineInputFormat.class);
At the last line in the sample (job.setInputFormatClass(NLineInputFormat.class);) I get following error:
The method setInputFormatClass(Class<? extends InputFormat>) in the type Job is not applicable for the arguments (Class<NLineInputFormat>)
Did I somehow get the wrong NLineInputFormat class?
You are mixing the old and the new API.
import org.apache.hadoop.mapred.lib.NLineInputFormat;
import org.apache.hadoop.mapreduce.Job;
According to the "Hadoop : The Definitive Guide"
The new API is in the org.apache.hadoop.mapreduce package (and subpackages). The old API can still be found in org.apache.hadoop.mapred.
If you plan to use the new API, then use the NLineInputFormat from the org.apache.hadoop.mapreduce package.