英文:
How do you get an AWS Java application compile in EC2 instance?
问题
在AWS的EC2实例上编译我的.java文件时遇到了一些问题。我在本地创建文件,那里可以正常运行。然后,我将.java文件移动到我的EC2实例,并尝试使用以下命令进行编译:
javac imageRecognition.java
但是我遇到了如下错误:
imageRecognition.java:5: 错误: 找不到包com.amazonaws.regions
import com.amazonaws.regions.Regions;
^
imageRecognition.java:6: 错误: 找不到包com.amazonaws.services.rekognition
import com.amazonaws.services.rekognition.AmazonRekognition;
我猜这是因为EC2实例上没有这些包,但是我不确定如何下载/放置它们。或者是否需要完全不同的操作。任何帮助将不胜感激。
注:我必须在EC2实例上编译文件,不能在实例上移动可执行的.jar文件或类似文件。
英文:
Been having some trouble trying to get my .java file to compile on an EC2 instance in AWS. I create the file on my local and it runs just fine there. I then move the .java file into my EC2 instance and try to compile it with the following:
javac imageRecognition.java
But I end up with errors like so:
imageRecognition.java:5: error: package com.amazonaws.regions does not exist
import com.amazonaws.regions.Regions;
^
imageRecognition.java:6: error: package com.amazonaws.services.rekognition does not exist
import com.amazonaws.services.rekognition.AmazonRekognition;
I'm assuming it's cause there are no packages on the EC2 instance, but I am unsure how to download/where to put them. Or if there is something completely different I need to do. Any help would be appreciated.
Note: I have to compile it the file on the EC2 instance, I cannot move an executable .jar on the instance or the like.
答案1
得分: 1
如果你打算使用javac,你需要将jar包添加到类路径中,你可以从AWS SDK Java下载该jar包。然而,这是一种非常老旧的做法,你可能会遇到依赖问题,因为它还需要其他库。如果我是你,我会考虑使用类似Maven或者Gradle这样的构建工具来帮助处理这种情况。
英文:
If you are going to use javac you are going to need to have the jar on the classpath which you can download from AWS SDK Java. However this is a really old-school way to do it and you will probably run into dependency hell as it will need other libraries. If I were you I would check out a build tool like Maven or Gradle which helps with this kind of thing.
答案2
得分: 1
似乎你的 EC2 实例中缺少 AWS SDK 包。你可以尝试使用 AWS CodePipeline 功能来进行代码构建和部署。
使用 CodeBuild 来构建代码包,然后使用 CodeDeploy 将可执行文件部署到 EC2 实例中。或者你也可以使用其他的 CI/CD 工具来进行代码构建和部署。
英文:
Looks like AWS SDK package is missing in your EC2 instance. You can try using AWS Code Pipeline feature to get the code build and deploy.
Use Code Build to build the package and Code deploy to deploy the executable file into EC2. Or use any other CI/CD to build and deploy the code.
答案3
得分: 0
最好使用Maven或Gradle。我在这种情况下使用了Maven,并按以下方式添加了AWS依赖项:
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.863</version>
</dependency>
然后只需安装Maven并运行 mvn install
。
英文:
Better use maven or gradle. I used maven in my case for such, and added AWS dependency as follows:
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.863</version>
</dependency>
Then simply install maven and run mvn install
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论