I cam across the following Logger definition in my Java code and noticed that the following LoggerFactory uses the .create() method. I tried to locate good documentation to explain the difference between LoggerFactory.getLogger(getClass()) and LoggerFactory.create(getClass()) but seem to have difficulties figuring out what exactly they do differently.
The package supporting the imports is called: javautils-lib-3.0.jar.
import utils.log.ILogger;
import utils.log.Log;
import utils.log.LogLevel;
import utils.log.Logger;
import utils.log.LoggerFactory;
public static final ILogger LOG = LoggerFactory.create(LoggedExperiment.class);
Was wondering whether anyone would be able to point me in the right direction?
Have a great day.
M
Related
I'm making a Java Spring project in IntelliJ as an exercise and I don't understand a file configuration error I'm having.
Please look at my project directory layout as described in this screenshot:
The three most important files here are the Main & GameConfig classes, and the game.properties file. Or, to use their full package directory names, "console/src/main/java/academy.learnprogramming.console.Main", "core/src/main/java/academy.learnprogramming.config.GameConfig" and core/src.resources.config.game.properties
When I run project, the Main class tries to run the following code:
package academy.learnprogramming.console;
import academy.learnprogramming.MessageGenerator;
import academy.learnprogramming.NumberGenerator;
import academy.learnprogramming.config.GameConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
private static final Logger log = LoggerFactory.getLogger(com.sun.tools.javac.Main.class);
public static void main(String[] args) {
log.info("Guess the number");
//== create the context first ==
ConfigurableApplicationContext context
= new AnnotationConfigApplicationContext(GameConfig.class);
// rest of code, which we never get to because of an error with the above line
When I try to create ConfigurableApplicationContext, I am trying to call the GameConfig class from the Core package. But I get this runtime error instead:
Exception in thread "main"
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class
[academy.learnprogramming.config.GameConfig]; nested exception is
java.io.FileNotFoundException: class path resource
[config/game.properties] cannot be opened because it does not exist
I do not understand why it thinks GameConfig does not exist, or how to fix it. No solutions I have found seem to have the precise answer for this. I have gotten a configuration comparison from someone whose code is identical to mine, but neither of us understand why their version works and mine does not.
For comparison's sake, the GameConfig class has the following code:
package academy.learnprogramming.config;
import academy.learnprogramming.GuessCount;
import academy.learnprogramming.MaxNumber;
import academy.learnprogramming.MinNumber;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
#Configuration
#ComponentScan(basePackages = "academy.learnprogramming")
#PropertySource("classpath:config/game.properties")
public class GameConfig {
//rest of GameConfig code here...
While game.properties is as simple as this:
game.maxNumber = 100
game.guessCount = 10
game.minNumber = 0
I can't find a question similar to this, nor do other websites point out what's going on. Does anyone have any idea why this error might be happening? Any advice would be invaluable
I'm currently going through the book GWT in Action 2nd Edition and its example code. In chapter 5 under the discussions on ClientBundle usage they have example code where there is an interface that extends com.google.gwt.rpc.client.RpcService. When I loaded this example project into my Eclipse IDE, the code shows red as the package com.google.gwt.rpc does not exist. This is most likely because I'm using GWT 2.7 and the book was written back in GWT 2.5. I attempted to look into the JavaDoc to see when it was removed, and what its replacement should be, but the only JavaDoc is for the latest, and downloads for 2.5 from the website returns no page found (404) errors. My IDE is suggesting that I change the requested interface to com.google.gwt.user.client.rpc.RemoteService but without knowing if this is the correct replacement, it seems a bit odd.
The code example they provide is as follows:
package com.manning.gwtia.ch05.client.cssresource;
import java.util.HashMap;
import java.util.List;
import com.google.gwt.rpc.client.RpcService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("CSSResourceService")
public interface ResourceService extends RpcService {
List<String> getThemes();
HashMap<String, String> getTheme(String name);
}
Does anyone know what the proper replacement interface for RpcService and maybe also tell me in which version it was removed?
com.google.gwt.rpc was an experiment aimed at replacing RPC from com.google.gwt.user. It didn't met expectations and was ultimately removed in 2.7. So yes, use RemoteService, like you should have actually always done.
I'm trying to setup an application that runs on OSGi internally and have tried using the tutorial here, but I get the error "The method getBundleContext() is undefined for the type Framework" all the time. As far as I can tell, I'm using the right library, but it's not specified in the mentioned article, so I'm not 100% sure. I've also tried the examples on Apache's website, here, which results in the same issue. Code below:
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class Main {
public static void main(String[] args) throws BundleException {
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
Framework framework = frameworkFactory.newFramework(config);
framework.start();
// Throws error that it cannot find method getBundleContext()
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();
installedBundles.add(context.installBundle("file:org.apache.felix.shell-1.4.2.jar"));
installedBundles.add(context.installBundle("file:org.apache.felix.shell.tui-1.4.1.jar"));
for (Bundle bundle : installedBundles) {
bundle.start();
}
}
}
The only thing that makes sense is that either I'm using the wrong libraries, or the libraries have changed and the method I'm attempting to call has since been deprecated out in the last 4 years. Anyone know how I can fix this?
I doubt it makes much of a difference, but in case it does, I'm using Bndtools for Eclipse to create this project.
Found the issue. Apparently, the import of osgi.core that was in the Bndtools' project build path was out of date, preventing the code from accessing the correct version of the framework libraries. Updating that fixed the issue.
Additional side-note; Since I'm using Bndtools, I was adding this to the project build path via the bnd.bnd file's build tab. This, however, was not grabbing the correct version of osgi.core, so I had to go under source and add the version=latest in order to force it to get the latest version available, so the line now appears as: osgi.core;version=latest where it was previously just osgi.core under the -buildpath: section.
I'm using NetBeans 6.9.1 with Java SE.
I'm working on a project called Autocorrect with code in 2 folders, src and tests. In order to access private fields and methods, I'm trying to put my test files in the same package as my source files:
edu.brown.cs32.dtadams.<package>
Example:
package edu.brown.cs32.dtadams.trie;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.List;
/* A generic class for testing methods in the "edu.brown.cs32.dtadams.trie" package
*
* #author Dominic Adams
* #version 1.0 2/13/13
*/
public class TrieTest {
...[TESTS]...
}
I've been told that even though TrieTest is in a different root folder than the rest of the package it's in, NetBeans should recognize it as being in the same one. However, TrieTest doesn't seem to recognize any of the files from its own package. When I added
"import edu.brown.cs32.dtadams.SQTrie"
to the imports, I got back these two errors:
- cannot find symbol: ...[info]...
- Import From The Same Package
So TrieTest recognizes that it's in a package of the same name as SQTrie, but NetBeans doesn't equate the two packages.
Does anyone have an idea as to what might cause this problem? Or any more information on how NetBeans handles packages across multiple folders?
To restrict method access to the same package use the package private access modifier
, which means put nothing in front of your method (no private/public/protected). Private is much stronger and restricts usage to the class itself.
This access modifier is also often used for unit tests to avoid over exposing the tested methods.
I'm learning JavaCV, and I found a really nice example online here in C++
http://aishack.in/tutorials/an-introduction-to-contours/
However, Eclips can't detect any of the functions that start with cv. like cvCreateImage(), even if the method is static. I'm at a loss for what to do here. Other Java tutorials for javacv also use these methods.
Thanks a lot in advance!
I found out why it didn't work - you have to add some static references at the top. This is what I added if anyone else is stuck
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;