Rebuild .jar file for netbeans platform - java

I have a java project (Netbeans platforms and hibernate for ORM).i use hibernate build entities and add this jar file to my project and it work fine, When I add new table to Database and rebuild entities, it has error. the new entities class is not found though I have checked my code, but I don't find any solutions. Please help me(my table name is menu)
this i my code
for (int i = 0; i < table_row; i++) {
Menu menus = (Menu) items.get(i);
objectData[i][0] = menus.getId();
objectData[i][1] = menus.getTitle();
objectData[i][2] = menus.getLevel();
objectData[i][3] = menus.getParentId();
objectData[i][4] = menus.getClassname();
objectData[i][5] = menus.getCategoryId();
objectData[i][6] = menus.getIcon();
objectData[i][7] = menus.getOrder();
objectData[i][8] = menus.getCreated();
objectData[i][9] = menus.getModified();
}
and this is exception
Classes: loaded=3871 total loaded=3871 unloaded 0
INFO [org.netbeans.core.ui.warmup.DiagnosticTask]: Total memory 4,074,373,120
INFO [null]: Total physical memory 4,074,373,120
SEVERE [global]
java.lang.ClassNotFoundException: com.osstech.dbentities.Menu
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:222)
Caused: java.lang.ClassNotFoundException: com.osstech.dbentities.Menu starting from ModuleCL#302d6b3[com.osstech.Systems] with possible defining loaders [ModuleCL#759d36f1[com.osstech.dbentities]] and declared parents [ModuleCL#7f28abd9[org.netbeans.modules.settings], ModuleCL#fcd0400[org.openide.windows], org.netbeans.MainImpl$BootClassLoader#6db17b38, ModuleCL#561ac555[org.netbeans.api.progress], ModuleCL#52b4e7ec[com.osstech.DataAccess], ModuleCL#759d36f1[com.osstech.dbentities], ModuleCL#2716630b[com.osstech.wraplibrary], ModuleCL#6461d2bf[com.osstech.Utilities], ModuleCL#f27bf78[org.openide.awt]]
at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:224)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.NoClassDefFoundError: com/osstech/dbentities/Menu

Need some code to say anything conclusively. But, seems like you have a menu configured in layer.xml called com.osstech.dbentities.Menu. That is mis-configured. when netbeans tries to instanciate this object, it can't find it.

Related

NoClassDefFound of MasterNotRunning when using janusgraph backend HBase

I am using janusgraph, with storage backend HBase. Currently I am trying to add vertices to the database. The part of the code is
public class Graph {
private static JanusGraph graph = JanusGraphFactory.open("conf/jg.properties");
public static JanusGraph getGraph() {
return graph;
}
public static void addVertex() {
for (int i=0; i<5; i++) {
graph.addVertex("test", i);
}
graph.tx().commit();
}
}
with the main function calls
Graph.addVertex();
The error is
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/MasterNotRunningException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:56)
at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:477)
at org.janusgraph.diskstorage.Backend.getStorageManager(Backend.java:409)
at org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.<init>(GraphDatabaseConfiguration.java:1376)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:164)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:133)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:80)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.MasterNotRunningException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
I am using janusgraph 0.2.0, in maven 0.2.0
and hbase 1.2.0, java 1.8
I set storage-hostname=127.0.0.1 in jg.properties, so is it a dependency error? Where is exactly the MasterNotRunning?
I have found the solution, but still curious.
I search the class MasterNotRunning and found this is in package org.apache.hadoop.hbase and finally make a guess to add org.apache.hbase & hbase-client into dependency. And the error disappears.
However, I still could not find the reason of this error. If some code in dependency jar uses the class MasterNotRunning then it should import the hbase-client jar, then this should be already in the dependency. How can this code pass the compiling and finally throws an exception during the running time.
Just add, I uses export->runnable jar file to get my jar, so all the dependencies should be added into it.

What for do we need ignite.sh script?

I'm new to ignite and trying to run my simple multi-node computation example. I wrote the following simple application:
try(Ignite ignite = Ignition.start("example-cache.xml")){
IgniteCompute asyncCompute = ignite.compute().withAsync();
for(int i = 0; i < 100; i++) {
int[] a = new int[1];
a[0] = i;
asyncCompute.call(() -> {
out.println(a[0]);
return a[0];
});
}
}
First I ran 3 server nodes with ignite.sh that is supplied with the binary ignite distribution. Each in a different JVM instance.
Then I build this application and run it with the same xml-spring config as the 3 server nodes before.
But actually I got the following exception:
class org.apache.ignite.IgniteCheckedException: com.test.App
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9826)
at org.apache.ignite.internal.processors.job.GridJobWorker.initialize(GridJobWorker.java:432)
at org.apache.ignite.internal.processors.job.GridJobProcessor.processJobExecuteRequest(GridJobProcessor.java:1108)
at org.apache.ignite.internal.processors.job.GridJobProcessor$JobExecutionListener.onMessage(GridJobProcessor.java:1894)
at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1222)
at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:850)
at org.apache.ignite.internal.managers.communication.GridIoManager.access$2100(GridIoManager.java:108)
at org.apache.ignite.internal.managers.communication.GridIoManager$7.run(GridIoManager.java:790)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: com.test.App
at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:692)
at org.apache.ignite.internal.binary.BinaryUtils.doReadClass(BinaryUtils.java:1486)
at org.apache.ignite.internal.binary.BinaryUtils.doReadClass(BinaryUtils.java:1424)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.readClass(BinaryReaderExImpl.java:370)
at org.apache.ignite.internal.binary.BinaryFieldAccessor$DefaultFinalClassAccessor.readFixedType(BinaryFieldAccessor.java:828)
at org.apache.ignite.internal.binary.BinaryFieldAccessor$DefaultFinalClassAccessor.read(BinaryFieldAccessor.java:639)
at org.apache.ignite.internal.binary.BinaryClassDescriptor.read(BinaryClassDescriptor.java:833)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1498)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450)
at org.apache.ignite.internal.binary.BinaryUtils.doReadObject(BinaryUtils.java:1640)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.readObject(BinaryReaderExImpl.java:1124)
at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C2V2.readBinary(GridClosureProcessor.java:2073)
at org.apache.ignite.internal.binary.BinaryClassDescriptor.read(BinaryClassDescriptor.java:823)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1498)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450)
at org.apache.ignite.internal.binary.GridBinaryMarshaller.deserialize(GridBinaryMarshaller.java:298)
at org.apache.ignite.internal.binary.BinaryMarshaller.unmarshal0(BinaryMarshaller.java:99)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82)
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9820)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.test.App
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8459)
at org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:185)
at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:683)
This exception is perfectly clear. But what do we need the ignite.sh script for?
You should either add you App class in classpath for all ignite nodes or
turn on peer-class-loading[1].
[1] https://apacheignite.readme.io/v1.9/docs/zero-deployment#peer-class-loading
You should add your JAR file to the lib/ folder under the Apache Ignite installation folder. Then you can start ignite.sh and all your classes will be automatically loaded.
Alternatively, you can try enabling peer-class-loading as suggested above, and Ignite will load the classes automatically.

Exception is Thrown when Opening the Webcam using com.github.sarxos library

I'm trying to detect my webcam using com.github.sarxos library. This is the download link to the library.
import com.github.sarxos.webcam.Webcam;
public class DetectWebcamExample {
public static void main(String[] args) {
Webcam webcam = Webcam.getDefault();
if (webcam != null) {
System.out.println("Webcam: " + webcam.getName());
} else {
System.out.println("No webcam detected");
}
}
}
But every time I run the program it throws an Exception like this.
Exception in thread "main" java.lang.NoClassDefFoundError:org/slf4j/LoggerFactory
at com.github.sarxos.webcam.Webcam.<clinit>(Webcam.java:97)
at com.github.sarxos.webcam.Webcam.<clinit>(Webcam.java:97)
at webcam.WebCam.main(WebCam.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
Java Result: 1
Can you please tell me what is the wrong with the Code or Library?
I have added the Library (Which I downloaded in the link given above as a .zip file) to the Library folder in Netbeans. Are there any libraries that I should Add???
You didn't add the third-party dependencies of the library, in the dl link there should be libs file containing (slf4j-api-1.7.2.jar, bridj-0.6.2.jar), add those .jars into your project and it should work. The exception is simply saying it cannot find the classes, that is needed to run the library as they are contained different .jar file

Error using apache -common-validator --java.lang.NoClassDefFoundError: org/apache/commons/digester/Rule

I am using following jars-
commons-validator-1.4.0 ; commons.logging-1.2 ; commons.digester-1.8 ;commons.beanutils-1.8.3
commons.collections-3.2.1
but keeps on getting same error at line -
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Rule
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:216)
This is the code i am writing -
InputStream in = this.getClass().getResourceAsStream("validator-name-required.xml");
// Create an instance of ValidatorResources to initialize from an xml file.
ValidatorResources resources = new ValidatorResources(in);
Please help its been a day i am stuck into this error !! Thanks in advance
Finally i am able to do this. I have used the following jars -
commons-beanutils-1.8.3.jar
commons-collections-3.2.1.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
commons-validator-1.4.0.jar
and this works :)
Its look like that "org.apache.commons.digester.Rule" class was not found, Version 2.1 of digester have Rule.class, download this version and try.

GlassFish 3: how do you change the (default) logging format?

The question originated from here: http://www.java.net/forum/topic/glassfish/glassfish/configuring-glassfish-logging-format - without an answer.
The default GlassFish 3 logging format is very annoying, much too long.
[#|2012-03-02T09:22:03.165+0100|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=113;_ThreadName=AWT-EventQueue-0;| MESSAGE... ]
This is just a horrible default IMO. The docs just explain all the fields, but not how to change the format: http://docs.oracle.com/cd/E18930_01/html/821-2416/abluk.html
Note, that I deploy SLF4J along with my webapp which should pick up the format as well.
How do you change the logging format?
FYI:
The links here are outdated: Install log formater in glassfish...
The question here hasn't been answered: How to configure GlassFish logging to show milliseconds in timestamps?...
The posting here resulted in nothing: http://www.java.net/forum/topic/glassfish/glassfish/cant-seem-configure-...
It looks like GlassFish logging configuration is an issue of its own. Can anybody help?
The solution seems to be the first SO posting here: Install log formater in glassfish
I've hacked together a simple log formatter (adjust at will):
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
public class JBossAS7LikeFormatter extends SimpleFormatter
{
private final String nl = System.getProperty("line.separator");
private final DateFormat df = new SimpleDateFormat("HH:mm:ss,SSS");
#Override
public synchronized String format(LogRecord lr)
{
StringBuffer sb = new StringBuffer();
// time only
Date dt = new Date();
dt.setTime(lr.getMillis());
sb.append(df.format(dt));
sb.append(" ");
// level (longest is "WARNING" = 7 chars, space fill for level output)
String level = lr.getLevel().getName();
int numSpaces = 7 - level.length();
sb.append(level);
for ( int i = 0 ; i < numSpaces + 1 ; i++ )
{
sb.append(" ");
}
// package
sb.append("[");
sb.append(lr.getSourceClassName());
sb.append("] ");
// thread (name?)
sb.append("(");
sb.append(lr.getThreadID());
sb.append(") ");
// message
sb.append(formatMessage(lr));
sb.append(nl);
// optional stack trace
if ( lr.getThrown() != null )
{
try
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
lr.getThrown().printStackTrace(pw);
pw.close();
sb.append(sw.toString());
}
catch ( Exception e )
{
}
}
return sb.toString();
}
}
It even fixes the double newline problem on Windows machines.
I got this to work by putting the JAR into domain/lib/ext at first, but for newer tries, whatever the reason is, I only keep getting a ClassNotFoundException now:
Mrz 08, 2012 9:39:14 AM com.sun.enterprise.admin.launcher.GFLauncherLogger info
Information: Successfully launched in 5 msec.
Launching GlassFish on Felix platform
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:55)
Caused by: java.lang.NoClassDefFoundError: com/sun/enterprise/server/logging/UniformLogFormatter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.util.logging.LogManager.getFormatterProperty(LogManager.java:1048)
at java.util.logging.StreamHandler.configure(StreamHandler.java:76)
at java.util.logging.StreamHandler.<init>(StreamHandler.java:94)
at java.util.logging.ConsoleHandler.<init>(ConsoleHandler.java:88)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at java.util.logging.LogManager$3.run(LogManager.java:419)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.logging.LogManager.loadLoggerHandlers(LogManager.java:405)
at java.util.logging.LogManager.initializeGlobalHandlers(LogManager.java:1076)
at java.util.logging.LogManager.access$1100(LogManager.java:148)
at java.util.logging.LogManager$RootLogger.getHandlers(LogManager.java:1157)
at java.util.logging.Logger.log(Logger.java:521)
at com.sun.logging.LogDomains$1.log(LogDomains.java:372)
at java.util.logging.Logger.doLog(Logger.java:543)
at java.util.logging.Logger.log(Logger.java:587)
at com.sun.enterprise.server.logging.LogManagerService.postConstruct(LogManagerService.java:354)
at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:78)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:229)
at com.sun.enterprise.v3.server.AppServerStartup.doStart(AppServerStartup.java:145)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:136)
at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.start(GlassFishImpl.java:79)
at com.sun.enterprise.glassfish.bootstrap.GlassFishDecorator.start(GlassFishDecorator.java:63)
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishImpl.start(OSGiGlassFishImpl.java:69)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:117)
... 6 more
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.server.logging.UniformLogFormatter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 53 more
Completed shutdown of GlassFish runtime
Command start-domain failed.
The DAS was stopped.
I saw the new format for a few tries, but the it stopped to work - strange.
I've attached the JAR as is in my original GlassFish forum post. I've basically just used my ZIP tool and renamed it to JAR, but this shouldn't be a problem (?). If anybody gets it to work (again) please let me know.
Note: I'm using the GlassFish plugin to start/stop the server, don't know if this could be an issue.
Please continue any discussions in the GlassFish forum here: http://www.java.net/forum/topic/glassfish/glassfish/configuring-glassfish-logging-format
PS: sorry I needed to post the stack trace here as the GF forum is somewhat broken.
UPDATE:
Extending java.util.logging.SimpleFormatter did the trick. GlassFish now produces log entries like:
12:13:02,400 INFO [com.sun.enterprise.web.WebContainer] (1) WEB0172: Virtual server [server] loaded default web module []
12:13:07,700 INFO [org.hibernate.validator.util.Version] (1) Hibernate Validator 4.2.0.Final
12:13:08,919 WARNING [null] (1) Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor#1a53cab6].
12:13:08,920 WARNING [null] (1) JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor#1a53cab6] from index [0]
12:13:08,920 WARNING [null] (1) JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer#2f740f7e] from index [1]
Again, on Windows: no double newlines.
The default logging format can be changed as per the post above. The NoClassDefFoundError reported above can be avoided by extending java.util.logging.Formatter rather than the com.sun.enterprise.server.logging.UniformLogFormatter.
To summarize:
Implement a custom formatter which extends java.util.logging.Formatter
Copy the jar containing custom formatter to domain/lib/ext
Specify the log formatter in logging.properties, eg.
com.sun.enterprise.server.logging.GFFileHandler.formatter=com.myformatter.CustomFormatter
You need to supply your own logging implementation since there doesn't seem to be a way to change glassfish's. SLF4J is just a facade and doesn't actually do any logging, it forwards it to the logger that is present on your classpath.
What I've done in my app is replace the entire glassfish logging with logback following this post. http://hwellmann.blogspot.com/2010/12/glassfish-logging-with-slf4j-part-2.html
Following all the guides and failing, what finally got this to work for me in GF 3.1.2.2 was to update the correct property in logging.properties as explained above:
com.sun.enterprise.server.logging.GFFileHandler.formatter=com.myformatter.CustomFormatter
All guides I've seen have talked about updating the "handlers" property, but this was not neccessary. The property above is the only property I've changed.
Oh; and my custom formatter extends SimpleFormatter.
Since GlassFish 7.0.0-M8 you can switch the formatter as you wish for any handler used. In a simplest case you can use SimpleFormatter and set some custom format for it.
Also the GlassFish documentation improved.

Categories