Jar не может найти основной классJAVA

Программисты JAVA общаются здесь
Anonymous
Jar не может найти основной класс

Сообщение Anonymous »

Я сгенерировал жирную банку с IntelliJ, и по какой -то причине она не может найти основной класс, выводя ошибку: < /p>
HappyBirthdayWisher\build\libs>java -jar HappyBirthdayWisher-1.0-SNAPSHOT.jar
Error: Could not find or load main class org.example.Main
Caused by: java.lang.ClassNotFoundException: org.example.Main

HappyBirthdayWisher\build\libs>java -cp HappyBirthdayWisher-1.0-SNAPSHOT.jar org.example.Main
Error: Could not find or load main class org.example.Main
Caused by: java.lang.ClassNotFoundException: org.example.Main
< /code>
, хотя, когда я проверял файлы в банке, он ясно существует:
изображение моего Main.class в файле jar < /p>
Вот мой манифест: < /p>
Manifest-Version: 1.0
Main-Class: org.example.Main
< /code>
Я бы очень признателен за любую помощь! > https://jmp.sh/s/rpgx1pmdjhu8rwij4v68
edit: Также вот исходный основной файл
package org.example;

import io.github.cdimascio.dotenv.Dotenv;
import org.apache.poi.ss.usermodel.*;
import org.example.email.EmailSender;
import org.example.entity.Employee;
import org.example.mappings.TemplateMappings;
import org.example.thymeleaf.ThymeleafTemplateEngine;
import org.example.utils.AzureBlobUtils;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import javax.mail.MessagingException;
import java.io.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

public static void main(String[] args) throws MessagingException {
Dotenv dotenv = Dotenv.load();
String employeeInfoFileName = "birthdayWisherFiles/Employee Sample Data.xlsx";
String imageOrderFileName = "birthdayWisherFiles/logicFiles/birthday_image_order.txt";
String emailSentLogFileName = "birthdayWisherFiles/logicFiles/email_sent_log.txt";
String imageCounterFileName = "birthdayWisherFiles/logicFiles/image_counter.txt";
String birthDateColumn = "Birth Date";
String fullNameColumn = "Full Name";
String emailColumn = "Email";
// Azure Blob Storage SAS Token URL
String azureBlobUrl = dotenv.get("AZURE_BLOB_URL");
// Get today's month and day
MonthDay todayMonthDay = MonthDay.now();
Month currentMonth = todayMonthDay.getMonth();
try {
// Get the birthday havers of the day
List employees = getTodaysBirthdayHavers(azureBlobUrl,employeeInfoFileName, birthDateColumn, fullNameColumn, emailColumn, todayMonthDay);
// Fetch and save image order if needed
List imageFileNames = getOrUpdateImageOrder(imageOrderFileName, azureBlobUrl, currentMonth);
System.out.println("Employees with birthdays today: " + employees);
if (employees.isEmpty()) {
System.out.println("No birthdays today.");
return;
}
if (imageFileNames.isEmpty()) {
System.out.println("No images found in Azure Blob Storage.");
return;
}
// Initialize Thymeleaf template engine
TemplateEngine templateEngine = ThymeleafTemplateEngine.initializeTemplateEngine();
// Load or initialize the image counter
int[] imageCounter = loadImageCounter(azureBlobUrl,imageCounterFileName);

// Save into the list to later log it to a file
List emailsSent = new ArrayList();
// Send email to each employee
for (Employee employee : employees) {
// Get image for employee according to the current image order
String selectedImage = getImageForEmail(imageFileNames, imageCounter);
//increment the counter after getting the image
incrementImageCounter(imageCounter,imageFileNames);
String fileNameWithoutExtension = selectedImage.substring(selectedImage.lastIndexOf("/") + 1, selectedImage.lastIndexOf("."));
String templateName = determineTemplate(fileNameWithoutExtension);
// Create the Thymeleaf context and render the appropriate template
assert azureBlobUrl != null;
String selectedImageURl = AzureBlobUtils.getAzureBlobImageUrl(azureBlobUrl,selectedImage);
Context context = ThymeleafTemplateEngine.createContext(selectedImageURl,employee.getFullName());
String htmlContent = ThymeleafTemplateEngine.renderTemplate(templateEngine, templateName, context);

String recipient = employee.getEmail();
String subject = "Happy Birthday, " + employee.getFullName() + "!";

// Send the email
EmailSender.sendEmail(recipient, subject, htmlContent);

// add to the list the emails with a timestamp
saveEmailSentToList(employee.getFullName(),recipient,selectedImage, emailsSent);
}
// Append the list to file
appendEmailSentListToFile(azureBlobUrl,emailSentLogFileName, emailsSent);
// Save the updated image counter
saveImageCounterToFile(azureBlobUrl,imageCounterFileName, imageCounter[0]);

} catch (IOException e) {
e.printStackTrace();
}
}
//Excel stuffs
private static List getTodaysBirthdayHavers(String blobURL, String filePath, String birthDateColumn,
String fullNameColumn, String emailColumn, MonthDay todayMonthDay) throws IOException {
try (InputStream inputStream = AzureBlobUtils.getFileInputStream(blobURL, filePath);
Workbook workbook = WorkbookFactory.create(inputStream)) {

Sheet sheet = workbook.getSheetAt(0); // Get the first sheet
if (sheet == null) {
System.out.println("No sheets found in the workbook.");
return new ArrayList();
}

int birthDateColumnIndex = findColumnIndex(sheet, birthDateColumn);
int fullNameColumnIndex = findColumnIndex(sheet, fullNameColumn);
int emailColumnIndex = findColumnIndex(sheet, emailColumn);

if (birthDateColumnIndex == -1 || fullNameColumnIndex == -1 || emailColumnIndex == -1) {
System.out.println("One or more required columns not found.");
return new ArrayList();
}

return getMatchingEmployees(sheet, birthDateColumnIndex, fullNameColumnIndex, emailColumnIndex, todayMonthDay);
}
}

private static int findColumnIndex(Sheet sheet, String targetColumn) {
Row headerRow = sheet.getRow(0);
if (headerRow == null) {
return -1;
}

for (Cell cell : headerRow) {
if (cell.getCellType() == CellType.STRING && targetColumn.equals(cell.getStringCellValue())) {
return cell.getColumnIndex();
}
}

return -1;
}

private static List getMatchingEmployees(Sheet sheet, int birthDateColumnIndex, int fullNameColumnIndex, int emailColumnIndex, MonthDay todayMonthDay) {
List employees = new ArrayList();

for (int rowIndex = 1; rowIndex

Подробнее здесь: https://stackoverflow.com/questions/794 ... main-class

Вернуться в «JAVA»