Screenshot.png shows how I have set up Netbeans.  I think you can see
everything.

I normally use the *import* org.apache.logging.log4j.Logger and *import*
org.apache.logging.log4j.LogManager.  The Log4j2 module-info.class file
exports *org.apache.logging.log4j*.

I have committed a version of the test case with the word logging deleted.
And then returned it to what I think is correct in the subsequent commit.
I have tried it every way, with and without the classpath entries. BTW
adding a jar to both the modulepath and classpath has been a bit hit and
miss (ignoring adding log4j-api.jar if it is already on the modulepath) so
I used a Library entry for the module path and explicitly added the jars to
the classpath.

Adding the classpath entries with
*import* org.apache.logging.log4j.Logger
*import* org.apache.logging.log4j.LogManager

means the editor finds the classes Logger and LogManager as you would
expect.
The Compile File error message is that it cannot find the module log4j.api.
https://github.com/cosmiczoo/Log4j2TestCase latest commit is as close as I
can get.


On Wed, 3 Oct 2018 at 11:15, Geertjan Wielenga
<geertjan.wiele...@googlemail.com.invalid> wrote:

> I also see this on https://logging.apache.org/log4j/2.0/download.html:
>
> To use Log4j 2 in your application make sure that both the API and Core
> jars are in the application’s classpath. Add the dependencies listed below
> to your classpath.
>
>
>    1. log4j-api-2.11.1.jar
>    2. log4j-core-2.11.1.jar
>
>
>
> In short, we need instructions for how exactly to set up the project to
> match the environment that you have.
>
> Gj
>
>
>
>
>
> On Wed, Oct 3, 2018 at 12:11 PM Geertjan Wielenga <
> geertjan.wiele...@googlemail.com> wrote:
>
>> Shouldn't the import statements be this:
>>
>> import org.apache.log4j.LogManager;
>> import org.apache.log4j.Logger;
>>
>> ...and not this:
>>
>> import org.apache.logging.log4j.LogManager;
>> import org.apache.logging.log4j.Logger;
>>
>> ...if you're using log4j-1.2-api-2.11.1.jar?
>>
>> Gj
>>
>>
>> On Wed, Oct 3, 2018 at 11:56 AM Emma Atkinson <emma.atkins...@gmail.com>
>> wrote:
>>
>>> I cannot find a way to make this work, I hope you can help.  I should be
>>> happy to be pointed to an existing answer
>>>
>>> *The Problem*
>>> I have a very simple Java application demonstrating the problem I am
>>> having with using the latest Log4j2 V2.11.1 as a module (log4j.api) and
>>> building it in Netbeans.  The example compiles, builds and runs when I use
>>> the classpath, but cannot compile the module-info.java file when I use the
>>> modulepath. I have uploaded the code and Netbeans files at the following
>>> link:
>>>
>>> https://github.com/cosmiczoo/Log4j2TestCase
>>>
>>> Log4j2 V2.11.1 is a Multi-release JAR (MR-JAR).  The module-info.class
>>> file is in log4j-api-2.11.1.jar under the folder META-INF/versions/9, which
>>> seems correct.
>>>
>>> The Netbeans editor can see the module log4j.api because it appears in
>>> the drop-down menu of completion suggestions and does not have wiggly red
>>> line under it.  My simple test program has a module-info.java file that
>>> requires log4j.api and nothing else.  This bit works as I would expect.
>>>
>>>
>>> I have located an unanswered question on StackOverflow asking a similar
>>> question
>>> https://stackoverflow.com/questions/50568139/netbeans-java-9-modules-log4j-2-11-module-not-found
>>>
>>>
>>> *To Reproduce My Test *
>>>
>>> I *Clean* the project.  It completes successfully.
>>> I then use a RMB option to *Compile File* the module-info.java file.
>>> This generates an error pointing to the line *requires log4j.api* in my
>>> module-info.java.
>>>
>>> <path-to>/Log4j2TestCase/src/module-info.java:7: error: module not
>>> found: log4j.api
>>>     requires log4j.api;
>>> 1 error
>>> ZipFileIndex clearCache failed
>>> <path-to>/Log4j2TestCase/nbproject/build-impl.xml:1131: The following
>>> error occurred while executing this line:
>>> <path-to>/Log4j2TestCase/nbproject/build-impl.xml:358: Compile failed;
>>> see the compiler error output for details.
>>>     at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1425)
>>>     at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1133)
>>>     at
>>> org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:120)
>>>     at
>>> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
>>>
>>> and so on.  Please let me know if you want more.
>>>
>>> I have tried building this program under JDK-9, JDK-10 and JDK-11.  My
>>> Netbeans runs on JDK-10.  I am learning how to migrate to modules by trial,
>>> error and reading.  I may have made an error, but if I have, I don't know
>>> where.
>>>
>>> Thanks in anticipation
>>>
>>> Emma
>>>
>>>
>>>
>>>

Reply via email to