Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribute log4jna in Maven central #6

Closed
ernieKovak opened this issue Sep 5, 2014 · 14 comments · Fixed by #39
Closed

Distribute log4jna in Maven central #6

ernieKovak opened this issue Sep 5, 2014 · 14 comments · Fixed by #39

Comments

@ernieKovak
Copy link

The jna.jar and platform.jar that are included in the log4jna-1.3zip archive appear to be JNA v3.2.7 artifacts, but the Win32EventLogAppender has code that depends on JNA v4.1.

Specifically, line 238:

if (Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath))

Platform v3.2.7 returns void from that method, which leads to runtime errors:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: com.sun.jna.platform.win32.Advapi32Util.registryCreateKey(Lcom/sun/jna/platform/win32/WinReg$HKEY;Ljava/lang/String;)Z
at org.apache.log4jna.nt.Win32EventLogAppender.registerEventSource(Unknown Source)
at org.apache.log4jna.nt.Win32EventLogAppender.registerEventSource(Unknown Source)
at org.apache.log4jna.nt.Win32EventLogAppender.append(Unknown Source)
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
at org.apache.log4j.Category.callAppenders(Category.java:206)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.info(Category.java:666)
... redacted...
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

@ernieKovak
Copy link
Author

Disregard... bad assumption. The included artifacts are okay, it was my installed jars that are the older version.

Sorry!
Ernie

@ernieKovak
Copy link
Author

Are the log4jna artifacts hosted in a maven repo somewhere, so I could just add the dependency to my pom? I couldn't find one....

@dblock
Copy link
Owner

dblock commented Sep 5, 2014

There's no log4jna in Maven, I would love it if someone took care of that (mavenize build, push to maven central ...), contributors welcome.

@dblock dblock changed the title Version inconsistency in log4jna zip Distribute log4jna in Maven central Sep 5, 2014
@gusehr
Copy link

gusehr commented Mar 25, 2015

Just a suggestion: If you are interested about change the project building, take a look first at Gradle (https://www.gradle.org/). It uses the "task" concept like Ant and the building script is a Groovy script (no XML programming).

See ya.

@Pfingst
Copy link

Pfingst commented Jan 15, 2016

I did set up a Maven build for the Java piece - I needed to make EventId customizable rather than 4096 every time, so I added that to the Java class - but I can't build the Windows DLL because the src zip is missing "version.rc.template".

I don't think it will be that hard to "Mavenize" the Windows DLL build via the Maven antrun plugin - you can pretty much copy and paste the ant tasks, and I had the "mc" task working through Maven.

Packaging the whole thing so that it is usable may be a different problem. One distribution containing the JAR and DLL? One each? I'm a C# developer relatively new to Java and Maven, so I'm still experimenting.

@dblock
Copy link
Owner

dblock commented Jun 30, 2016

See #9 that was a working maven conversion. Next step is probably #10.

@claudiow
Copy link
Contributor

claudiow commented Jul 4, 2016

We have maven hosting set up on Sonatype. https://issues.sonatype.org/browse/OSSRH-23287.

I will work on this and CI #10 simultaneously.

@claudiow
Copy link
Contributor

Your user and a new user Log4JNACI have been added to org.dblock at Sonatype to deploy to maven Central.

I will change the setting.xml file to use Log4JNACI for Maven.

@claudiow
Copy link
Contributor

claudiow commented Jul 12, 2016

There are a few tasks before we are ready for Maven Cenetral.

CI:

  • Complete writing and testing of .yml files
  • Change appveyor.yml to do deploy of the SNAPSHOTS to Sonatype Maven SNAPSHOT repository
  • Complete site with full usage and project documentation
  • Rewrite README.md to be more complete based on OSHI????

Code clean up and update:

  • Clean up Javadoc.
  • Rename the git tree to log4jna-XXX for demo, build, artifacts, doc,, etc. Make it consistent with most other projects in maven central like OSHI is doing
  • Clarify usage of Application and Log (They are used interchangeably in the code and FAQ and Issues) See next comment.

@claudiow
Copy link
Contributor

I noticed that #3 refers to the location of the log in the EventLogger tree as Application, but the code expects a parameter called log and I think that it should be application

Some of the log4j.xml examples in the discussions use application and ti should be log we need to align this in the code

As I see it:

EventViewer  
  |--> Windows  Logs 
        |--> Application 
              |--> Your-Source-Name` 

Is a catch all location if you are not using:

EventViewer  
  |--> Applications and Services Logs 
        |--> Your-Application-Name 
              |--> Your-Source-Name` 

I also would like to change the code in Win32EventAppender::registerEventSource to be more proactive and change the dll location and source values if the Log4j2 configuration changes.
This will allow the user to move the dll to wherever they like and modify the configuration without fiddling with the registry. (Assuming that you have administrative permissions.)

Right now the code only tries to create the key and if it fails gives up, I might be wrong, but I think that if we try to change a value the code will fail because Advapi32Util.registryCreateKey will return false because the key already exists.

This is how it looks:

    private static HANDLE registerEventSource(String server, String source, String application, String eventMessageFile,
            String categoryMessageFile) {
        String eventSourceKeyPath = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\" + application + "\\" + source;
        if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath)) {
            // Test dll location, and source here and change the values if they differ from the current ones
        } else {
            if (Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath)) {
                Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "TypesSupported", 7);
                Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "CategoryCount", 6);
                Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "EventMessageFile",
                        eventMessageFile);
                Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath,
                        "CategoryMessageFile", categoryMessageFile);
            }
        }

        HANDLE h = Advapi32.INSTANCE.RegisterEventSource(server, source);
        if (h == null) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }

        return h;
    }

BTW Is there any reason for this to be static?

@dblock
Copy link
Owner

dblock commented Jul 12, 2016

I don't have strong opinions about any of this above, it has been a while since I looked at this.

claudiow added a commit to claudiow/log4jna that referenced this issue Jul 13, 2016
… update

of dll location
Form dblock#23#issuecomment-232184331 Deleted seting-security.xml
@claudiow claudiow mentioned this issue Jul 13, 2016
@claudiow
Copy link
Contributor

claudiow commented Aug 8, 2016

I'm ready to rel;ease.
I will:

  1. Create a branch log4jna-2.0-RC in github.com/dblock/log4jna .
  2. Set next release number to 2.0.1 as there are small fixes and documentation issues for a quick follow up
  3. Build and release from the branch
  4. Test from Sonatype release repository and promote to Central

@dblock
Copy link
Owner

dblock commented Aug 8, 2016

@claudiow Go for it!

@claudiow
Copy link
Contributor

claudiow commented Aug 8, 2016

Done, It took some work. I will update the documentation with what I found.

@claudiow claudiow mentioned this issue Aug 8, 2016
@dblock dblock closed this as completed in #39 Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants