I am new to pig.. and am trying to write a udf function.
So basically here is the problem statement.
I have a dummy data like this..
user_id, movie_id, date_time_stamp
So what I am trying to do is this.
if the transaction is between
9 am and 11 am --> breakfast
and so on
So here is my pig script
REGISTER path/myudfs.jar
in = LOAD 'path/input' USING
PigStorage('\\u001') AS (user:long,movie:long, time:chararray);
result = foreach in GENERATE myudfs.time(time);
STORE result INTO 'path/output/time' using PigStorage(',');
Now myudf.jar java code is like this
public class time extends EvalFunc<String>{
public String exec(Tuple input) throws IOException {
if ((input == null) || (input.size() == 0))
return null;
try{
String time = (String) input.get(0) ;
DateFormat df = new SimpleDateFormat("hh:mm:ss.000");
Date date = df.parse(time);
String timeOfDay = getTimeOfDay(date);
return timeOfDay;
} catch (ParseException e) {
//how will I handle when df.parse(time) fails and throws ParseException?
//maybe:
return null;
}
}
So it takes in the tuple and returns a string... (I am new to java also..)
After this i try to run this script as
pig -f time.pig
It returns an error
2012-11-12 08:33:08,214 [main] INFO
org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to
hadoop file system at: maprfs:///
2012-11-12 08:33:08,353 [main] INFO
org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to
map-reduce job tracker at: maprfs:///
2012-11-12 08:33:08,767 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1069:
Problem resolving class version numbers for class myudfs.time
Some one posted on pig mailing list is that my PIG_CLASSPATH is not set and that i should point it to /path/hadoop/conf
I did that.. so now $echo PIG_CLASSPATH --> /path/hadoop/conf
But i get the same error
Please advise.
Thanks
Edit 1: On looking into the log, the error trace is:
Caused by: java.lang.UnsupportedClassVersionError: myudfs/time : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.pig.impl.PigContext.resolveClassName(PigContext.java:427)
... 27 more
is this like a java issue?
To find the jar version, open the jar using winzip (or similar) and look for manifest.mf. There should be a line in there that says 'Created-By' and this will give the version of java that was used to build the jar.
This needs to be older or equal to the version of java you are using to build your app. If you are doing this at the command line type:
java -version
or in eclipse go to
project(menu) > properties (menu item) > java build path (in list) > libraries (tab)
and take a look at the version that you are using for the JDK/JRE (you may be able to tell this from the directory, if not then go to that directory and do java -version).
Chances are you'll need to update the version of java you have in eclipse.
Related
I have the problem executing the Hadoop command from the PIG command line. The command and the error stack is below
My instructor suspects that it is because HADDOP_HOME and PIG_CLASSPATH are incorrect. I am on the HADOOP version 2.8.0.
So, originally I had HADOOP_HOME as
HADOOP_HOME=<CELLAR_DIRECTORY>/hadoop/2.8.0/
Then I switched the following setup:
HADOOP_HOME=<CELLAR_DIRECTORY>/hadoop/2.8.0/libexec/etc/hadoop
PIG_CLASSPATH is defined as $HADOOP_HOME
Commands I used in pig:
A = LOAD '/Users/anarinsky/Downloads/loaddata1.txt';
B = MAPREDUCE '/Users/anarinsky/workspace/wordcount/target/wordcount-1.jar' STORE A INTO '/Users/anarinsky/Downloads/tempwrite2' LOAD '/Users/anarinsky/Downloads/tempwrite2' AS (word:chararray, count:int) `com.systemskills.hadoop.wordcount.WordCountDriver /wordcountdata /Users/anarinsky/Downloads/pigoptdir`;
Pig Stack Trace
ERROR 2025: Expected leaf of reduce plan to always be POStore. Found PONative
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias B
at org.apache.pig.PigServer.openIterator(PigServer.java:1019)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:747)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:376)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:231)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:206)
at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:66)
at org.apache.pig.Main.run(Main.java:564)
at org.apache.pig.Main.main(Main.java:176)
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.apache.hadoop.util.RunJar.run(RunJar.java:234)
at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
Caused by: org.apache.pig.PigException: ERROR 1002: Unable to store alias B
at org.apache.pig.PigServer.storeEx(PigServer.java:1122)
at org.apache.pig.PigServer.store(PigServer.java:1081)
at org.apache.pig.PigServer.openIterator(PigServer.java:994)
... 13 more
Caused by: org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MRCompilerException: ERROR 2025: Expected leaf of reduce plan to always be POStore. Found PONative
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MRCompiler.compile(MRCompiler.java:321)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher.compile(MapReduceLauncher.java:629)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MapReduceLauncher.launchPig(MapReduceLauncher.java:152)
at org.apache.pig.backend.hadoop.executionengine.HExecutionEngine.launchPig(HExecutionEngine.java:308)
at org.apache.pig.PigServer.launchPlan(PigServer.java:1474)
at org.apache.pig.PigServer.executeCompiledLogicalPlan(PigServer.java:1459)
at org.apache.pig.PigServer.storeEx(PigServer.java:1118)
... 15 more
Alex!
Unfortunately, it's not related to Pig paths (tried it on my configured hadoop cluster) with same result. The error you get refers to the fact that Physical plan compiler has a bug in compile method. So in order to make your attempt work you have two possibilities
Run native MR job using hadoop and after it finishes process it's results in pig
Edit pig source code and compile your own version. You'll need to edit
org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MRCompiler#compile method and replace
for (PhysicalOperator op : leaves) {
if (!(op instanceof POStore)) {
int errCode = 2025;
String msg = "Expected leaf of reduce plan to " +
"always be POStore. Found " + op.getClass().getSimpleName();
throw new MRCompilerException(msg, errCode, PigException.BUG);
}
}
with
for (PhysicalOperator op : leaves) {
if (!(op instanceof POStore) && !(op instanceof PONative)) {
int errCode = 2025;
String msg = "Expected leaf of reduce plan to " +
"always be POStore. Found " + op.getClass().getSimpleName();
throw new MRCompilerException(msg, errCode, PigException.BUG);
}
}
After migration to Java 8, my tool throw the follwing exception if somebody try to run it on earlier Java environments.
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/myapp/MyTool: Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Is there some way to not show this error, and show nice error message with proposition to upgrade Java.
As I understood I should create some small class like:
public class CheckerJavaVersion {
public static void main(String args[]) {
String sVersion = System.getProperty("java.version");
sVersion = sVersion.substring(0, 3);
Float f = Float.valueOf(sVersion);
if (f.floatValue() < (float) 1.8) {
System.out.println("Please upgrate your Java to 1.8 version");
System.exit(1);
}
}
}
and compile it via older compiler. I need some solution how to run this class firstly before the main method of MyToll class starts.
PS. Aplication is packed in jar.
The problem is that the error occurs when the class is loaded, so you'd either have to use a "starter app" which starts the actual application in a separate process or dynamically load the application after the Java version has been checked.
I didn't test it but what might work is something like this:
public static void main(String args[]) {
if( javaVersionOk ) {
Class.forName("actual.mainclass.name").getMethod("actual.main.method.name").invoke();
}
}
The idea is to access the class via its name and thus make the runtime load and initialize it at that time. I'm not sure, however, if you can delay class loading like that in all cases so you'd have to go on from there.
And btw, IIRC there already are applications/libraries that provide this kind of functionality, I just don't rember their names. So a search might be worth your while.
Edit: you might want to have a look at appstart if not for using it then for inspiration.
Another launcher would be Apache Commons Launcher.
Alternatives:
Alternatively you could just provide a launch script for each platform you want to support , call java -version and check the returned version before launching the application.
Another alternative would be to use JNLP/WebStart locally, which allows you to specify a minimum version and which AFAIK even provides for download/upgrade functionality.
This question already has answers here:
How to use "cd" command using Java runtime?
(8 answers)
Closed 9 years ago.
I am trying to run a java file using the terminal but from java. Meaning, I'll run the command using java.
I am trying to execute the command 'cd /Users/apple/Documents/Documents/workspace/UserTesting/src ' that redirects to the following directory and then execute the command 'ls' that lists all the files in the current directory
I am using this method to run the Java file 'NewFile.java'
try {
String line;
Process p = Runtime.getRuntime().exec( "cd /Users/apple/Documents/Documents/workspace/UserTesting/src" );
Process p2 = Runtime.getRuntime().exec( "ls" );
BufferedReader in = new BufferedReader(
new InputStreamReader(p2.getInputStream()) );
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
}
catch (Exception e) {
// ...
}
The output
Directly using the terminal -> It gives 'NewFile.java'
Using this method using Java -> It always give 'bin' and 'src' for whatever command given to p2
Here are several trials
Apples-MacBook-Pro:~ apple$ cd
/Users/apple/Documents/Documents/workspace/UserTesting/src
Apples-MacBook-Pro:src apple$ java NewFile 5 90 35 45 150 3
Reichweite---- nach blase art
3 5 35 45 90 150
Apples-MacBook-Pro:src apple$ java /Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile
Exception in thread "main" java.lang.NoClassDefFoundError:
/Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile
Caused by: java.lang.ClassNotFoundException:
.Users.apple.Documents.Documents.workspace.UserTesting.src.NewFile at
java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Apples-MacBook-Pro:src apple$ java
/Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile.java
Exception in thread "main" java.lang.NoClassDefFoundError:
/Users/apple/Documents/Documents/workspace/UserTesting/src/NewFile/java
Caused by: java.lang.ClassNotFoundException:
.Users.apple.Documents.Documents.workspace.UserTesting.src.NewFile.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Apples-MacBook-Pro:src apple$
Blockquote
So, it seems the problem you're having is that you don't understand why you get different results when you invoke the program in different ways.
Here's what's going on: Runtime.geRuntime().exec() creates a new process, which is a child of the parent. Every process has its own working directory; when you fork a new process, it inherits the working directory of the parent. Invoking cd will then change the working directory of the current process (and this is a shell builtin, but ignore that for now and I'll get to it later).
So what you're doing is this:
Parent
-> create child 1 -> change working directory of child 1
-> create child 2 -> invoke "ls"
Note that child 2 will inherit the working directory of its parent. It won't know anything about the working directory of child 1. So depending on the working directory of the process that is invoking this method (in your case, either the terminal or...I don't know, your JDK install?) you will get different results.
If you want the same results every time, you could do something like this:
Process p = Runtime.getRuntime().exec( "ls /Users/apple/Documents/Documents/workspace/UserTesting/src" );
And if you want to be able to exec your program from anywhere, just use the full path:
Process p = Runtime.getRuntime().exec( "java /Users/apple/Documents/Documents/workspace/UserTesting/NewFile" );
(assuming, of course, that you have already used javac to build NewFile.class in that directory, and that you have the right permissions to execute it.)
Re: cd, as I mentioned before this is a command that's built into your shell. When you invoke the command using exec in this way, it is likely failing. You can check on that by reading standard error using the getErrorStream() method of Process.
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.
I modified a Java code in Eclipse on my laptop with a Windows O.S. Now I have to run the code on a linux O.S. via SSH. I copied all the files and I tried to compile the code. The compilation went well, so there were no errors in the code. Anyway, when I tried to run it, the following errors appeared on the shell:
[ac6411#epigenetic models]$ java TanaModel
Exception in thread "main" java.lang.NoClassDefFoundError: TanaModel (wrong name: models/TanaModel)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Do you know what kind of the problem is?I'm new in Java coding, so I don't know how to solve it. Thank you.
wrong name: models/TanaModel
This means it expected to find TanaModel.class under the models directory, but found it somewhere else (maybe the current directory?). Put the class file in a the models directory, and run it as
java models.TanaModel
Java expects class files to be organized in directories that mirror the package structure you used in your source code.
java.lang.NoClassDefFoundError: TanaModel (wrong name: models/TanaModel) at
What command did you run, I'm guessing java TanaModel ?
Most likely your TanaModel is declared to be in package models;
Try calling it like this:
java models.TanaModel
If it is a Eclipse security issue, this would help.
//Java Code
try
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
try
{
// Insert code here to do required action (get or open file)
}
catch (Exception e)
{
// Insert code to catch exception from trying to do above action
}
}
}
);
}
catch(Exception e)
{
// Insert code to catch failed doPrivileged()
}
When you try to run your program, try calling it like this:
java models.TanaModel