2012-01-25 172 views
2

我一直在试图设置一个程序,为我的应用程序发送推送通知。首先我用 这个教程 http://mobiforge.com/developing/story/programming-apple-push-notification-servicesJavaApns log4j.apache错误iPhone推送通知

从这我学会了如何让我的设备的令牌。 我尝试了以下教程的其余部分,但在最后被困住了,它告诉我要下载一个名为PushMeBaby的类,并更改一些代码行并运行它。但是我甚至无法编译这个应用程序。它给了我错误:

运行目的地我的Mac 64位对于运行方案'PushMeBaby'无效。

经过数小时的试图弄清楚这一点,我决定切换到一个新的教程,因为我找不到解决这个问题的方法。

这使我java和一定的Java类名为JavaApns http://code.google.com/p/javapns/

中序安装此库,并得到它的工作,你需要满足一些要求 这里就是我认为问题出现。第三要求告诉我还可以下载和安装其他两个库:

bcprov-jdk15-146.jar 的log4j-1.2.15.jar

第一个库工作正常,因为没有错误。然而,log4是一个压缩文件,每当我尝试解压缩它时,它都会给我提供错误“发生意外错误(28)”因此,我只是进入zip文件,只解压缩库而不是整个文件(no错误)。然后,我把两个库+ JavaAPNS到我的项目,并运行它

[我的代码]

import javapns.Push; 
import javapns.communication.exceptions.CommunicationException; 
import javapns.communication.exceptions.KeystoreException; 


public class test { 
    public static void main(String[] args) { 

    try { 
     Push.alert("Hello World!", "MyCertificate.p12", "MyPassword",false, "MyDevicetoken"); 
    } catch (CommunicationException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (KeystoreException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 


     } 
} 

最后,这给我的错误是: /////////// ////////////////////////////////////////////////// ////////////////////

log4j:WARN No appenders could be found for logger (javapns.notification.Payload). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 

/////////////////////// ////////////////////////////////////////////////// ////////

我去了到链接logging.apache.org/log4j/1.2/faq.html#noconfig,但它并没有真正解释如何解决问题。所以,如果你有任何想法或建议(或者你想建议一个更好的图书馆/教程),我将不胜感激!

回答

1

从同link你去:

Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?

This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration. log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system. Knowing the appropriate location to place log4j.properties or log4j.xml requires understanding the search strategy of the class loader in use. log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments.

另外:

Why can't log4j find my properties file in a J2EE or WAR application?

The short answer: the log4j classes and the properties file are not within the scope of the same classloader.

The long answer (and what to do about it): J2EE or Servlet containers utilize Java's class loading system. Sun changed the way classloading works with the release of Java 2. In Java 2, classloaders are arranged in a hierarchial parent-child relationship. When a child classloader needs to find a class or a resource, it first delegates the request to the parent.

Log4j only uses the default Class.forName() mechanism for loading classes. Resources are handled similarly. See the documentation for java.lang.ClassLoader for more details.

So, if you're having problems, try loading the class or resource yourself. If you can't find it, neither will log4j. ;)

+0

我已经看过这些,我真的不明白他们好...从我的理解,你需要装入log4j.properties和log4j.xml文件进项目,但我找不到他们的zip文件 –

+0

@ A.sharif你必须_create_一个log4j.properties文件才能工作。 [这](http://www.mkyong.com/logging/log4j-log4j-properties-examples/)网站有几个例子可供你开始使用。 –

0

上JavaPNS的 “Troubleshooting” 页面介绍,您可以启用日志记录编程。你做不是需要用配置文件设置整个Log4j系统。