gpt4 book ai didi

java - 在java中导入文件

转载 作者:行者123 更新时间:2023-12-01 13:47:59 24 4
gpt4 key购买 nike

package com.teamsite.client;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Hashtable;
import com.interwoven.cssdk.common.CSClient;
import org.apache.commons.lang.StringUtils;
import com.interwoven.cssdk.access.CSUser;
import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.common.CSException;
import com.interwoven.cssdk.filesys.CSAreaRelativePath;
import com.interwoven.cssdk.workflow.CSExternalTask;
import com.interwoven.cssdk.workflow.CSTask;
import com.interwoven.cssdk.workflow.CSURLExternalTask;
import com.interwoven.cssdk.workflow.CSWorkflow;
import java.util.logging.*;

public class ApplicationEdition implements CSURLExternalTask{

private static String userid;
private static String cssdkconfigfile;
private String applicationName;
private String applicationEditionPath;
private static CSClient csClient;

public static final String KEY_TARGET_TASK_NAME = "target_task_name";
private String transitionComment = "Auditing for deployed files ";
private String transition = "";

public static String getCssdkconfigfile() {
return cssdkconfigfile;
}

public static void setCssdkconfigfile(String cssdkconfigfile) {
ApplicationEdition.cssdkconfigfile = cssdkconfigfile;
}

private static CSClient getCsClient() {
return csClient;
}

private static void setCsClient(CSClient csClient) {
ApplicationEdition.csClient = csClient;
}
private static String getUserid() {
return userid;
}

private static void setUserid(String userid) {
ApplicationEdition.userid = userid;
}

private String getApplicationName() {
return applicationName;
}

private void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}

private String getApplicationEditionPath() {
return applicationEditionPath;
}

private void setApplicationEditionPath(String applicationEditionPath) {
this.applicationEditionPath = applicationEditionPath;
}

@Override
public void execute(CSClient client, CSExternalTask currentTask, Hashtable params) throws CSException {

String userId = client.toString();
String cssdkconfigfile = "D:\\iw-home\\TeamSite\\cssdk\\cssdk.cfg";
setUserid(userId);
setCssdkconfigfile(cssdkconfigfile);
String targetTaskName = currentTask.getVariable(KEY_TARGET_TASK_NAME);

CSUser thisTaskOwner = currentTask.getOwner();
String thisTaskOwnerAddress = thisTaskOwner.getEmailAddress();

String branchName = currentTask.getArea().getBranch().getName();
CSAreaRelativePath[] files = currentTask.getFiles();
String Area = currentTask.getArea().getName();
System.err.println("*********************************************************");
System.err.println("Target task name"+targetTaskName);
System.err.println("Task owner's address"+thisTaskOwnerAddress);
System.err.println("Area name"+Area);
System.err.println("*********************************************************");
} private static CSTask getTaskByName(CSWorkflow job, String name) throws CSException {
if (name == null) {
return null;
}
CSTask[] tasks = job.getTasks();
for (int i=0; i<tasks.length; i++) {
if (name.equals(tasks[i].getName())) {
return tasks[i];
}
}
return null;
}

public static void showFiles(String string1,String string2,String string3 ) {
try {
File filename = new File ("C:\\temp\\ApplicationEditions_dynamic.txt");

BufferedWriter writer = new BufferedWriter(new FileWriter(filename,true));
writer.write(string1+"\n");
writer.write(string2+"\n");
writer.write(string3+"\n");
writer.newLine();
writer.close();
}


catch (Exception e)
{
System.out.println("Error occurred due to branch, refer output file");
}
finally {


}
} }

在此代码中,以下文件被导入到该源文件中

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Hashtable;
import com.interwoven.cssdk.common.CSClient;
import org.apache.commons.lang.StringUtils;
import com.interwoven.cssdk.access.CSUser;
import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.common.CSException;
import com.interwoven.cssdk.filesys.CSAreaRelativePath;
import com.interwoven.cssdk.workflow.CSExternalTask;
import com.interwoven.cssdk.workflow.CSTask;
import com.interwoven.cssdk.workflow.CSURLExternalTask;
import com.interwoven.cssdk.workflow.CSWorkflow;

这里的源文件位于“package com.teamsite.client”位置。因此,从位置 com.intergrind.cssdk.common.CSClient 导入的其他文件应该具有到“com”文件夹的公共(public)路径,并且在“com”目录中应该有“interwelted”目录,并且在该目录中应该有其他目录.
但是当我检查服务器上的目录时,除了团队站点之外我没有看到任何其他目录。这段代码运行良好,没有任何问题。
那么,这些其他文件是如何导入到这里的呢?我们的环境有点复杂,但文件仍然需要位于导入路径中。我们有保存 jar 的存储库。

谢谢

最佳答案

当类加载器寻找一个类时,例如com.interwelve.cssdk.workflow.CSExternalTask​​,它扫描整个类路径,寻找像 com/intervowen/cssdk/workflow 这样的目录分支。上述声明还涵盖了类路径上可能存在的分解 jar 。

类路径通常包含比可运行的 jar 文件更多的目录。显然,您的 jar 预计不会包含以 com.* 开头的包中包含的所有类,因此可以从类路径上的任何位置导入这些类。

关于java - 在java中导入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20202611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com