[英]How do I reference a file from within my Rails project?
I'm using Rails 5.0.1. 我正在使用Rails 5.0.1。 I have a Java class file in my project located at 我的项目中有一个Java类文件,位于
bin/java/WordToTextConverter.class
How do I reference this class from within a Rails file? 如何从Rails文件中引用此类? For instance, in one of my service classes I have this 例如,在我的一个服务类别中,我有这个
`java -classpath "#{Rails.configuration.java_class_path}" WordToTextConverter ${file_location} #{file_as_text}`
but this is currently failing because I haven't put in the correct path to "WordToTextConverter". 但这当前失败,因为我没有输入“ WordToTextConverter”的正确路径。 What should that path be? 那条路应该是什么?
You can use Rails.root
which would give you the full path of your current Rails application like: 您可以使用Rails.root
,它将为您提供当前Rails应用程序的完整路径,例如:
/some_directory/rails_project/
So this way you can access the bin/
folder or any other you need to work with, so in your case you could try with: 因此,通过这种方式,您可以访问bin/
文件夹或需要使用的任何其他文件夹,因此您可以尝试以下操作:
"#{Rails.root}/bin/java"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.