Error when writing to java.nio.file.Path, but not in the IDE

Answered

 

Hi,

 

When the following code is run from Intelli 15.0.3,

 

Path newFile = Paths.get( "output.txt" )

newFile.write( "What the...?" ) 
System.exit(0) 

 

, it populates output.txt as expected.

 

But when the standalone artifact is run, it displays the following error:

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: sun.nio.fs.WindowsPath.write() is applicable for argument types: (java.lang.String) values: [What the...?]
Possible solutions: wait(), wait(long), with(groovy.lang.Closure), size(), init(), first()
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:56)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)

 

This is in Windows.

 

In Linux, we get the same result, but of course with its own implementation,

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: sun.nio.fs.UnixPath.write() is applicable for argument types: (java.lang.String) values: [What the...?]

 

5 comments
Comment actions Permalink

Apparently your command line runner has different settings than IntelliJ's runner. This can be due to all kinds of things. The command line IDEA uses is printed in the console before script output, you can copy it and try running from the command line. Does this work correctly?

0
Comment actions Permalink

Yes, the IDE command line works on the actual command line.  But there is no way, we're going to implement a long, obscure command line like

 

C:\java\bin\java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.2\bin" , etc..., in our scripts.

 

In fact, before we changed the FILE objects to PATH objects, we were able to run the application from the command line, without any special settings, i.e. java -jar appfile.jar.

I'll search through the java.nio.file.Path docs, see if there are environmental recommendations.  Otherwise, we'll just switch back to the standard Java FILE objects.

 

 

 

0
Comment actions Permalink

I think everything is OK with your usage of java.nio.file.Path. It's Groovy language standard library that seems to fail in the command line, namely class named NioGroovyMethods. Please check which Groovy you're using from command line and if it's complete.

0
Comment actions Permalink

We just updated everything to Groovy 2.4.6.  That's the version that Intellij is using now, and it's the one on the command line.

Same result.

 

0
Comment actions Permalink

We can close this.  We went ahead and refactored everything to use File and FileWriter, and will explore the nio Path api at another time.

 

0

Please sign in to leave a comment.