NoClassDefFoundError: sun/tools/native2ascii/Main

1,773 views
Skip to first unread message

Geir Harald Hansen

unread,
Oct 31, 2010, 5:56:13 PM10/31/10
to Lift
To get translated text in UTF-8 working with my Lift application, I'm
trying to set up the SBT native2ascii plugin as described at
http://blog.getintheloop.eu/2010/8/18/native2ascii-plugin-for-sbt

So far I have no luck. Executing the "native2ascii" action in SBT
gives me:
java.lang.NoClassDefFoundError: sun/tools/native2ascii/Main

Indeed, I cannot compile a Java program with "new
sun.tools.native2ascii.Main();" in it, without first adding tools.jar
from the JDK to CLASSPATH, so I figure that's the problem.

Next I tried adding tools.jar as a dependency in project/build/
LiftProject.scala, like so:
val suntools = "sun" % "tools" % "1.6.0" % "system" from
"file://" + Path.fileProperty("java.home") + "/lib/
tools.jar"

When I run the "update" action in SBT it copies tools.jar to
lib_managed/scala_2.8.0/system/, but running "native2ascii" still
fails with the same error.

I also tried setting a classpath in the shell script that launches
SBT, which also did no good.

Some of my setup:
> java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
> cat project/build.properties
[...]
sbt.version=0.7.4
project.version=1.0
def.scala.version=2.7.7
build.scala.versions=2.8.0

I have googled to my wits end. Any suggestions?

Regards,
Geir H. Hansen

Derek Chen-Becker

unread,
Nov 3, 2010, 1:46:51 PM11/3/10
to lif...@googlegroups.com
I found this googling:

http://www.morkeleb.com/2009/04/04/grails-error-starting-suns-native2ascii/

Is JAVA_HOME pointing to a JDK or JRE?


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.


Geir Harald Hansen

unread,
Nov 4, 2010, 8:50:35 AM11/4/10
to lif...@googlegroups.com
JAVA_HOME points to a JDK. I have to add tools.jar to the classpath to use sun.tools.* classes even from Java. I just can't find a way to get sbt to run "native2ascii" with tools.jar on the classpath.

From the Java side, things look like this:
> echo $JAVA_HOME
/usr/lib/jvm/java-6-sun/
> cat Test.java
public class Test {
    public static void main(String args[]) {
        new sun.tools.native2ascii.Main();
        System.out.println("success");
    }
}
> javac Test.java
Test.java:3: package sun.tools.native2ascii does not exist
        new sun.tools.native2ascii.Main();
                                  ^
1 error
> javac -cp $JAVA_HOME/lib/tools.jar Test.java
> java Test
Exception in thread "main" java.lang.NoClassDefFoundError: sun/tools/native2ascii/Main
[..snip stacktrace..]
> java -cp .:$JAVA_HOME/lib/tools.jar Test
success

Derek Chen-Becker

unread,
Nov 4, 2010, 9:46:38 AM11/4/10
to lif...@googlegroups.com
OK, I think I misunderstood the issue you're running into. What about just running the native2ascii tool as an external process? Somethings like:

import sbt.Process._

object n2aUtil {
  def convert (in : String, out : String, encoding : Option[String] = None) : Int = {
    "native2ascii %s %s %s".format(encoding.map("-encoding " + _).getOrElse "", in, out) !
  }
}

Then you can just do something like

n2aUtil.convert("foo.txt", "foo.utf8")
n2aUtil.convert("bar.txt", "bar.utf8", "ISO-8859-4")

Derek

Geir Harald Hansen

unread,
Nov 5, 2010, 10:54:07 AM11/5/10
to lif...@googlegroups.com
On 04.11.2010 14:46, Derek Chen-Becker wrote:
> OK, I think I misunderstood the issue you're running into. What about
> just running the native2ascii tool as an external process? Somethings like:
>
> import sbt.Process._
>
> object n2aUtil {
> def convert (in : String, out : String, encoding : Option[String] =
> None) : Int = {
> "native2ascii %s %s %s".format(encoding.map("-encoding " +
> _).getOrElse "", in, out) !
> }
> }

Running it as an external process works great. Thank you!

Regards,
Geir H. Hansen

Derek Chen-Becker

unread,
Nov 5, 2010, 2:02:53 PM11/5/10
to lif...@googlegroups.com
When you can't beat 'em, figure out some sneaky way to work around 'em ;)


Regards,
Geir H. Hansen

Reply all
Reply to author
Forward
0 new messages