setting classpath for repl

17 views
Skip to first unread message

chrisichris

unread,
Jan 24, 2013, 11:29:25 AM1/24/13
to yeti...@googlegroups.com
I somehow do not manage to add a jar to the classpath for the repl.

Neither via the java -cp property nor the yeti one

>java -cp "lib\unmanaged\ant-1.8.2.jar" -jar lib/unmanaged/yeti.jar
Yeti 0.9.7+ REPL.

> import org.apache.tools.ant.Project
> new Project()
1:1: Unknown class: org.apache.tools.ant.Project

Yeit -cp:

C:\programmierung\myprojects\yeti\ybuilder>java -jar lib/unmanaged/yeti.jar -cp "lib\unmanaged\ant-1.8.2.jar"
Yeti 0.9.7+ REPL.

> import org.apache.tools.ant.Project
> new Project()
java.lang.NoClassDefFoundError: org/apache/tools/ant/Project
        at code.apply(<>)
        at yeti.lang.compiler.eval._1(eval.yeti:96)
        at yeti.lang.compiler.eval.execClass(eval.yeti:74)
        at yeti.lang.compiler.eval$evaluateYetiCode$._0(eval.yeti:468)
        at yeti.lang.compiler.eval$evaluateYetiCode$.apply(eval.yeti:444)
        at yeti.lang.Fun2_.apply(Unknown Source)
        at yeti.lang.compiler.yeti.repl(yeti.yeti:58)
        at yeti.lang.compiler.yeti.main(yeti.yeti:206)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Project
        at java.lang.ClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at yeti.lang.compiler.Loader.loadClass(CodeWriter.java:80)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 8 more


Madis

unread,
Jan 24, 2013, 9:56:42 PM1/24/13
to yeti...@googlegroups.com

On Thu, 24 Jan 2013, chrisichris wrote:

> I somehow do not manage to add a jar to the classpath for the repl.
> Neither via the java -cp property nor the yeti one
>
> >java -cp "lib\unmanaged\ant-1.8.2.jar" -jar lib/unmanaged/yeti.jar

The java tool ignores -cp when -jar is given.

> Yeti 0.9.7+ REPL.
>
> > import org.apache.tools.ant.Project
> > new Project()
> 1:1: Unknown class: org.apache.tools.ant.Project
>
> Yeit -cp:
>
> C:\programmierung\myprojects\yeti\ybuilder>java -jar lib/unmanaged/yeti.jar -cp
> "lib\unmanaged\ant-1.8.2.jar"

That's weird.

$ java -jar yeti.jar -cp /usr/share/ant/lib/ant.jar
Yeti 0.9.7+ REPL.

> import org.apache.tools.ant.Project
> new Project()
org.apache.tools.ant.Project@5f787338 is ~org.apache.tools.ant.Project

$ cp /usr/share/ant/lib/ant.jar test
$ java -jar yeti.jar -cp test/ant.jar

Still works.

I would suspect that url forming for URLClassLoader is somehow broken with
windows paths? The code is in c/eval.yeti around line 176.

urls = array [];
for classPath do p:
s = strReplace '\' '/' new File(p)#getAbsolutePath();
push urls new java.net.URL("file://\(
if s `strEnds?` '/' or s `strEnds?` '.jar' then s
else "\(s)/" fi)")
done;
cl := new java.net.URLClassLoader(urls, cl) as ~ClassLoader

Maybe you can debug this, I don't have windows at hand at the moment.

> Yeti 0.9.7+ REPL.
>
> > import org.apache.tools.ant.Project
> > new Project()
> java.lang.NoClassDefFoundError: org/apache/tools/ant/Project
> Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Project

chrisichris

unread,
Jan 25, 2013, 3:10:28 AM1/25/13
to yeti...@googlegroups.com, ma...@cyber.ee

The java tool ignores -cp when -jar is given.

Thanks for that info (and sorry for not checking it before)
 
I would suspect that url forming for URLClassLoader is somehow broken with
windows paths? The code is in c/eval.yeti around line 176.

     urls = array [];
     for classPath do p:
         s = strReplace '\' '/' new File(p)#getAbsolutePath();
         push urls new java.net.URL("file://\(
             if s `strEnds?` '/' or s `strEnds?` '.jar' then s
             else "\(s)/" fi)")
     done;
     cl := new java.net.URLClassLoader(urls, cl) as ~ClassLoader


Replacing the java.net.URL construction with new File(p is string)#toURI()#toURL() does the trick on my side: 

                urls = 
                    classPath
                    |> map do p: new File(p is string)#toURI()#toURL() done 
                    |> array;
                cl := new java.net.URLClassLoader(urls, cl) as ~ClassLoader



I also tried to do some extra-homework and support wildcard jar pathes like the java tool to include all jars in a directory (ie. lib/unmanaged/*)

                //expand classPath 
                urls = classPath
                    |> concatMap do p:
                        if strEnds? p "/*" 
                            or strEnds? p (File#separator^"*") then
                            
                            listDirectory false p
                            |> filter (.file?)
                            |> filter ((strEnds? ".jar").(.name))
                            |> map (.path)
                        
                        else
                            [p]
                        fi
                    done
                    |> map do p: new File(p is string)#toURI()#toURL() done 
                    |> array;
                cl := new java.net.URLClassLoader(urls, cl) as ~ClassLoader

but then I get an exception:

>java -jar C:\programmierung\yeti\yeti\yeti.jar -cp "lib\unmanaged\*"
Don't know what to do with `lib\unmanaged\ant-junit-1.8.2.jar'

Any would be nice but is no must from my side.

A final thing I found is that the asm files generated by ant show up in git status maybe you could add them to  .gitignore 
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   c/eval.yeti
#       modified:   util/asm-3.1-reader-np.patch
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       asm-3.1-p1r.jar 

Thanks for your fast repsonse and the hint giving me the opportunity that I can myself try somethig in the code-base (it is a realy amazing peace of software),
Christian

Madis

unread,
Jan 25, 2013, 9:39:24 AM1/25/13
to yeti...@googlegroups.com

On Fri, 25 Jan 2013, chrisichris wrote:

> I would suspect that url forming for URLClassLoader is somehow broken with
> windows paths? The code is in c/eval.yeti around line 176.
>
> � � �urls = array [];
> � � �for classPath do p:
> � � � � �s = strReplace '\' '/' new File(p)#getAbsolutePath();
> � � � � �push urls new java.net.URL("file://\(
> � � � � � � �if s `strEnds?` '/' or s `strEnds?` '.jar' then s
> � � � � � � �else "\(s)/" fi)")
> � � �done;
> � � �cl := new java.net.URLClassLoader(urls, cl) as ~ClassLoader
>
>
> Replacing the java.net.URL construction with new File(p is string)#toURI()#toURL() does the trick
> on my side:�
> � � � � � � � � urls =�
> � � � � � � � � � � classPath
> � � � � � � � � � � |> map do p: new File(p is string)#toURI()#toURL() done�
> � � � � � � � � � � |> array;
> � � � � � � � � cl := new java.net.URLClassLoader(urls, cl) as ~ClassLoader

Is simple new File(p is string)#toURL() also working (both with jar files
and directories containing .class files)?

chrisichris

unread,
Jan 25, 2013, 10:42:35 AM1/25/13
to yeti...@googlegroups.com, ma...@cyber.ee

Is simple new File(p is string)#toURL() also working (both with jar files
and directories containing .class files)?

Yes is working with both jar and class-dir. However File#toURL() is deprectated and the javadoc recommends toURI()#toURL() (This time I did read it :) 
Reply all
Reply to author
Forward
0 new messages