Hello, all.

I have been working on this problem myself (digging through archives,
google, etc).

I have a patch (which at least makes the build work for me).  I'm certain
there must be a better way, so would someone mind taking a look at this
patch, please?

I'd appreciate any feedback.  Thanks.


Regards,
Troy



-----Original Message-----
From: Wu, Troy [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 06, 2007 2:31 PM
To: [email protected]
Subject: [mojo-user] Problems with J2ME plugin

Hello, all.

I am new to Maven, and I am having some problems with the J2ME plugin
(sandbox).  Please let me know (privately) if this is the wrong forum for my
question, which follows.

* * *

Here's what I see on my console:

============================
jabs [~/tools/mats/trunk] $ mvn -Dplugin=j2me install
[INFO] Scanning for projects...
[INFO] ---------------------------------------------------------------------
[INFO] Building mats
[INFO]    task-segment: [install]
[INFO] ---------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [j2me:preverify {execution: default}]
[ERROR] error output :
Error preverifying class com.asurion.mats.App
    java/lang/NoClassDefFoundError: java/lang/Object
============================

>From what I can tell, the CLASSPATH for the preverifier is not set properly.

Can someone advise me on how to fix this problem, or direct me to the proper
documentation?


Thank you!
Troy

Index: src/main/java/org/codehaus/mojo/j2me/PreverifyMojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/j2me/PreverifyMojo.java     (revision 4287)
+++ src/main/java/org/codehaus/mojo/j2me/PreverifyMojo.java     (working copy)
@@ -92,10 +92,11 @@
         // build preverify command executable
         validateSdk();
         File binPath = getBinPath( sdkPath );
+               File libPath = getLibPath( sdkPath );
         File cmd = getPreverifyCmd( binPath );

         // build class path
-        String classPath = getClassPath( project );
+        String classPath = getClassPath( project, libPath );

         // get target directory
         String target = project.getBuild().getOutputDirectory();
@@ -175,6 +176,22 @@
         return binPath;
     }

+    private File getLibPath( File sdkPath )
+        throws MojoFailureException
+    {
+        // get the lib path
+        File libPath = new File( sdkPath.getPath() + File.separator + "lib" );
+        log.debug( "libPath = " + libPath );
+
+        // test, if lib path is valid
+        if ( ( libPath.exists() == false ) || ( libPath.isDirectory() == false 
) )
+        {
+            throw new MojoFailureException( "the sdk contains no lib 
directory" );
+        }
+
+        return libPath;
+    }
+
     private File getPreverifyCmd( File binPath )
         throws MojoFailureException
     {
@@ -213,7 +230,7 @@
         return cmd;
     }

-    private String getClassPath( MavenProject project )
+    private String getClassPath( MavenProject project, File libPath )
         throws MojoExecutionException
     {
         try
@@ -225,6 +242,8 @@
             List artifacts = project.getRuntimeClasspathElements();
             for ( int idx = 0; idx < artifacts.size(); idx++ )
             {
+                               log.debug( "  artifact[" + idx + "]: " + 
artifacts.get( idx ) );
+
                 // get next dependency
                 String classpathElement = (String) artifacts.get( idx );

@@ -236,9 +255,57 @@

                 // add path to dependency
                 classPath.append( classpathElement );
+
+                               log.debug( "    classpath element: " + 
classpathElement );
             }

+                       // Adding the required libraries for J2ME...
+                       //   There must be a better way than this...
+                       try
+                       {
+                               if ( false == libPath.isDirectory() )
+                               {
+                                       throw new Exception("J2ME Library Path 
'" + libPath + "' is not a directory.");
+                               }
+
+                               StringBuffer j2lcp = new StringBuffer();
+
+                               final File[] files = libPath.listFiles();
+
+                               for ( int i = 0; i < files.length; i++ )
+                               {
+                                       final File file = files[i];
+
+                                       log.debug("        encountered possible 
JAR: " + file.getPath());
+
+                                       if ( false == file.isFile() ) continue;
+
+                                       final String filename = file.getName();
+
+                                       if ( false == filename.endsWith(".jar") 
) continue;
+
+                                       if ( filename.startsWith("jsr") || 
filename.equalsIgnoreCase("midpapi20.jar") || 
filename.equalsIgnoreCase("cldcapi11.jar") || 
filename.equalsIgnoreCase("wma20.jar") )
+                                       {
+                                               if ( j2lcp.length() > 0 ) 
j2lcp.append(File.pathSeparator);
+
+
+                                               log.debug("    Adding JAR: " + 
file.getPath());
+
+                                               j2lcp.append(file.getPath());
+                                       }
+                               }
+
+                               if ( classPath.length() > 0 ) 
classPath.append(File.pathSeparator);
+
+                               classPath.append(j2lcp.toString());
+                       }
+                       catch ( Exception e )
+                       {
+                               log.error( "J2ME Library classpath error: " + e 
);
+                       }
+
             log.debug( "classpath: " + classPath );
+
             return classPath.toString();
         }
         catch ( DependencyResolutionRequiredException e )

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to