在Eclipse中使用Java测试Google Cloud Vision的JAR包获取问题
Hey there! I’ve been stuck trying to get Google Cloud Vision working in Eclipse without build tools before—let me share exactly how to fix this, either by going the Maven route (which you’re already considering, smart move!) or even the manual JAR way if you really need it.
How to Get Google Cloud Vision Java Code Compiling in Eclipse
Option 1: Switch to a Maven Project (Recommended)
This is the easiest way since it handles all JAR downloads and dependency management automatically:
- Create a new Maven project in Eclipse
Go toFile > New > Maven Project, check "Create a simple project" (skip archetype selection if you don’t need it), fill in your Group Id and Artifact Id, then finish. - Add the Cloud Vision dependency to
pom.xml
Open thepom.xmlfile in your new project, find the<dependencies>section (add it if it doesn’t exist), and paste this:
Save the file, and Eclipse will automatically pull down all required JARs (including nested dependencies like Google Auth, gRPC, etc.)—no manual downloading required!<dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-vision</artifactId> <version>2.32.0</version> <!-- Grab the latest version from Maven Central if needed --> </dependency> - Move your existing code into the Maven project
Maven expects Java code insrc/main/java—create a package structure matching your test class, then copy your Cloud Vision code into the correct directory. Adjust the package declaration in your Java file to match. - Set up your service account key
Don’t forget to add your Google Cloud service account JSON key to the project, and point to it in your code:
(Pro tip: Put the key inSystem.setProperty("GOOGLE_APPLICATION_CREDENTIALS", "src/main/resources/your-service-key.json");src/main/resourcesso it’s included in the build path automatically.)
Option 2: Manual JAR Download (Not Recommended)
If you really don’t want to use Maven, you’ll need to download all required JARs manually. But fair warning—this is error-prone because Cloud Vision has dozens of dependencies. Here’s the gist:
- Search for
google-cloud-visionon Maven Central, download the main JAR file. - Check the "Dependencies" tab for that artifact, then download every single listed JAR (including transitive dependencies that those JARs rely on).
- In Eclipse, right-click your project >
Build Path > Add External Archives, and select all the downloaded JARs.
Again, this is messy—version conflicts are super likely, so stick with Maven if you can.
内容的提问来源于stack exchange,提问作者gordon613
相关产品推荐
相关产品推荐

