Java 将 Apache POI 添加到 Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20767252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Apache POI to Eclipse
提问by Brent
I am not very good at adding anything to java so this is new to me, after spending hours on the internet I haven't found anything that I can easily understand, can anyone explain a couple things to me.
我不太擅长向java添加任何东西,所以这对我来说是新的,在互联网上花了几个小时后,我没有找到任何我可以轻松理解的东西,谁能向我解释几件事。
If I use Apache POI to create a java file and run the class on another machine will it run without Apache POI, if it won't run can anyone think of another way to write a word document using java.
How do I add the package to Eclipse, I download the Apache POI 3.9 src zip edition. I read that I am suppose to have 3 jar files which are not in the zip file, I tried adding the zip file to eclipse under the package properties "Add External Jar" option with no avail.
如果我使用 Apache POI 创建一个 java 文件并在另一台机器上运行该类,它是否会在没有 Apache POI 的情况下运行,如果它无法运行,任何人都可以想出另一种使用 java 编写 word 文档的方法。
如何将包添加到 Eclipse,我下载了 Apache POI 3.9 src zip 版本。我读到我假设有 3 个 jar 文件不在 zip 文件中,我尝试在包属性“添加外部 Jar”选项下将 zip 文件添加到 eclipse 中,但无济于事。
Any input is appreciated, what I am trying to do is creating a list of names from a text file and sorting that list, removing duplicates, then printing the list to a Word Document in five columns per page, if I could print in columns in a text file that would work to. Lastly, I would like to thank this community, this is an awesome website and has helped me greatly the past couple years.
感谢任何输入,我想要做的是从文本文件创建一个名称列表并对该列表进行排序,删除重复项,然后将列表打印到每页五列的 Word 文档中,如果我可以在列中打印一个可以工作的文本文件。最后,我要感谢这个社区,这是一个很棒的网站,在过去的几年里对我帮助很大。
采纳答案by Gagravarr
Your best bet is to either wait for POI 3.10 beta 3, or just grab the latest source tree from SVN. As of quite recently, Apache POI now ships with an Eclipse project file in the source tree.
您最好的选择是等待 POI 3.10 beta 3,或者只是从 SVN获取最新的源代码树。最近,Apache POI 现在在源代码树中附带了一个 Eclipse 项目文件。
Once you've got a new enough copy of Apache POI, simply fire up Eclipse, choose Filethen Import. Pick Existing Project into Workspacethen select the directory where you POI source tree is. Follow the wizard to complete the project import, then you'll be away!
获得足够新的 Apache POI 副本后,只需启动 Eclipse,File然后选择Import。选择现有项目到工作区,然后选择 POI 源树所在的目录。按照向导完成项目导入,然后你就离开了!
回答by Viktor K.
Yes you need all the dependent jars on every single machine where you want to run your application. You have to add them to your classpath just as you need to do it when you are compiling your code.
是的,您需要在要运行应用程序的每台机器上的所有依赖 jar。您必须将它们添加到您的类路径中,就像您在编译代码时需要这样做一样。
The best way how NOT to manage your dependencies manually is to use a management tool like maven ( http://maven.apache.org/guides/getting-started/index.html). It could take some time to understand how it works (there are lot of good tutorials available - just google for maven) . Anyway it will save you a lot of time in the future. (It can build for you a jar that includes all dependencies with simple "maven install" command)
不手动管理依赖项的最佳方法是使用管理工具,如 maven ( http://maven.apache.org/guides/getting-started/index.html)。可能需要一些时间来理解它是如何工作的(有很多很好的教程可用 - 只需 google for maven)。无论如何,它会在未来为您节省很多时间。(它可以使用简单的“maven install”命令为您构建一个包含所有依赖项的 jar)
There are very good maven plugins for eclipse. They are usually included in newer eclipse versions by default.
Eclipse 有非常好的 Maven 插件。默认情况下,它们通常包含在较新的 eclipse 版本中。
回答by Sumit
You will have to have poi on the other machine, but this shouldn't deter you. You can either just deploy the separate jars with your class file, or export the class file in a jar with the dependent jars.
你必须在另一台机器上有 poi,但这不应该阻止你。您可以仅使用类文件部署单独的 jar,也可以将类文件与依赖的 jar 一起导出到 jar 中。
You should also download the binary distribution not the source distribution, you will find the jars you are looking for in there. And then you can add external jar.
您还应该下载二进制发行版而不是源代码发行版,您会在那里找到您正在寻找的 jar。然后你可以添加外部jar。
Additionally, as mentioned in another answer, if you are going to be doing a fair amount of java development, it might be worthwhile to look into maven.
此外,如另一个答案中所述,如果您打算进行大量的 Java 开发,那么研究 maven 可能是值得的。
Lastly, if you can get away with not writing to a word document, you could forego poi altogether and create a html file that has a 5 column table. You would create the html file the same way you create any text file.
最后,如果您可以避免不写入 Word 文档,您可以完全放弃 poi 并创建一个具有 5 列表的 html 文件。您可以像创建任何文本文件一样创建 html 文件。
Hope that helps.
希望有帮助。