简体   繁体   English

使用软链接通过-classpath开关导入jar

[英]Importing jar via -classpath switch using a softlink

I think I'm missing something critical related to classpaths, please point me in the right direction, 我认为我缺少与类路径有关的关键信息,请指出正确的方向,

The import statement 进口声明

import com.mongodb.Mongo;

The location of the mongodb jar file I'm trying to import. 我要导入的mongodb jar文件的位置。 This is a softlink (I can 'cd /baseline/'). 这是一个软链接(我可以'cd / baseline /')。

/baseline/mongodb/lib/mongo-java-driver-2.12.2.jar

The location where I'm running my test class 我要运行测试课程的位置

/usernameaccount/Desktop/Tester.java

The javac command javac命令

javac -classpath "/baseline/mongodb/lib/mongo-java-driver-2.12.2.jar" Tester.java 

The error I get says this 我得到的错误是这样的

Tester.java:11: error: package baseline.mongodb.lib does not exist
import baseline.mongodb.lib.Mongo;

What am I missing? 我想念什么? Thanks for your patience 谢谢你的耐心

I think you are mixing two thing. 我认为您正在混淆两件事。 The import statement should include the class location and classpath should point to the location of jar. import语句应包含类位置,而classpath应指向jar的位置。

change 更改

import baseline.mongodb.lib.Mongo;

to

import com.mongodb.Mongo;

and re-run the program. 并重新运行该程序。

By changing the file structure (and thus altering the filepath) I was able to get it to compile and run. 通过更改文件结构(并因此更改了文件路径),我能够将其编译并运行。 Thanks for your help! 谢谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM