首页 > 编程知识 正文

eclipse大小写转换,idea编译java项目

时间:2023-05-05 09:42:04 阅读:163521 作者:1083

1要组织项目,请先复制项目,然后删除其版本信息。 这可以利用操作系统的检索功能。 原始项目是SVN工程,因此将在此处搜索. SVN。

删除. svn路径下的所有文件,以便项目成为纯本地项目。 这样,您就可以在不更改原始项目的情况下,稍后将此新项目上载到版本控制系统。

2idea导入idea,file-new-projectfromexistingsources,打开“导入项目”对话框,选择要导入的项目,然后选择Eclispe。

然后,采用默认配置即可,单击【下一步】直到完成。

导入后,将显示警告消息。

第一个警告是因为找到了未知的eclipse部署包。 然后检测spring配置文件,并检测最后一个可用的框架。

在idea中配置项目,然后单击“文件-项目结构”

【1】消除无效依赖

module - Dependencies消除无效依赖。

【2】标记相应功能的文件夹

对于非规格的项目文档结构,可能需要手动配置【源代码】、【资源】等文件路径。

【3】依存软件包的构成

Libraries -单击编号添加依存关系包。 在非Maven项目中,通常将依赖包放在WEB-INF的lib文件夹中。 对于Web项目,可能还需要servlet API。 (位于tomcat的lib包下。

idea还将检测依赖包中可能使用的框架,并在右侧列出这些框架。

【4】配置传真

Facets -编号- Web,选择当前项目,然后单击确定。 之后在Web上设定

web.xml文件路径和web文件夹路径:

单击右下角警告框中的Create Artifact以创建项目开发包。

然后,在Artifact的右下角,单击fix-addallmissingdependenciesof“项目名称”totheartifact,将所有项目相关包放入此项目开发包中。

在Facets中配置struts2和Spring框架。 如果有:

【5】tomcat的结构

单击编号- Tomcat Server - Local:

用Depolyment配置已创建的artifact包。 其中Application context是web项目的访问路径前缀。

单击tomcat运行时,报告了错误。

这是因为eclipse将BOM标头字符添加到代码类的开头,并且idea无法解析该字符。 尝试在java Compiler中将编译项更改为eclipse模式,但在编译过程中会收到类似的错误。

下载批量删除BOM标头的工具,删除java代码中的所有BOM标头。

这样处理通常可以通过编译或o(_) (o )来清除

第4.1集spring2. x的问题是旧项目,所以使用的spring版本是2.5。 这通常没有问题,但如果使用的是jdk1.8或更高版本,则会抛出这些错误。

caused by : Java.lang.illegalstateexception : contextnamespaceelement ' component-scan ' anditsparserclass [ org.sporg ] tion.componentscanbeandefinitionparser ] areonlyavailableonjdk 1.5 andhigheratorg.spring framework.context.config.contextnamespacehandler $1. parse (atorg.spase ) cehandlersupport.parse (namespacehandlersupport.Java 336069 ) atorg.spring framework.beans.factory.XML.beandefinitionparserdelegate.parsecustomelement (atorg.spring framework )

stomElement(BeanDefinitionParserDelegate.java:1287) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398) ... 75 more

明明 jdk1.8 比 1.5 高,为什么会这样呢?原来 spring2.5 启动时会检测 jdk 的版本,而版本号是写死在代码里的!无语咯……

我们可以在项目中新建一个 src 文件夹(记得把它标记为源代码文件夹哦),然后把 JdkVersion.java 放在 org.springframework.core 路径下:

新的 JdkVersion.java 代码如下:

package org.springframework.core;/** * @author Deniro Li (lisq037@163.com) * 2017/12/5 */public class JdkVersion { /** * Constant identifying the 1.3.x JVM (JDK 1.3). */ public static final int JAVA_13 = 0; /** * Constant identifying the 1.4.x JVM (J2SE 1.4). */ public static final int JAVA_14 = 1; /** * Constant identifying the 1.5 JVM (Java 5). */ public static final int JAVA_15 = 2; /** * Constant identifying the 1.6 JVM (Java 6). */ public static final int JAVA_16 = 3; /** * Constant identifying the 1.7 JVM (Java 7). */ public static final int JAVA_17 = 4; /** * Constant identifying the 1.8 JVM (Java 8). */ public static final int JAVA_18 = 5; private static final String javaVersion; private static final int majorJavaVersion; static { javaVersion = System.getProperty("java.version"); // version String should look like "1.4.2_10" if (javaVersion.indexOf("1.8.") != -1) { majorJavaVersion = JAVA_18; } else if (javaVersion.indexOf("1.7.") != -1) { majorJavaVersion = JAVA_17; } else if (javaVersion.indexOf("1.6.") != -1) { majorJavaVersion = JAVA_16; } else if (javaVersion.indexOf("1.5.") != -1) { majorJavaVersion = JAVA_15; } else { // else leave 1.4 as default (it's either 1.4 or unknown) majorJavaVersion = JAVA_14; } } /** * Return the full Java version string, as returned by * <code>System.getProperty("java.version")</code>. * * @return the full Java version string * @see System#getProperty(String) */ public static String getJavaVersion() { return javaVersion; } /** * Get the major version code. This means we can do things like * <code>if (getMajorJavaVersion() < JAVA_14)</code>. * * @return a code comparable to the JAVA_XX codes in this class * @see #JAVA_13 * @see #JAVA_14 * @see #JAVA_15 * @see #JAVA_16 * @see #JAVA_17 */ public static int getMajorJavaVersion() { return majorJavaVersion; } /** * Convenience method to determine if the current JVM is at least Java 1.4. * * @return <code>true</code> if the current JVM is at least Java 1.4 * @see #getMajorJavaVersion() * @see #JAVA_14 * @see #JAVA_15 * @see #JAVA_16 * @see #JAVA_17 */ public static boolean isAtLeastJava14() { return true; } /** * Convenience method to determine if the current JVM is at least * Java 1.5 (Java 5). * * @return <code>true</code> if the current JVM is at least Java 1.5 * @see #getMajorJavaVersion() * @see #JAVA_15 * @see #JAVA_16 * @see #JAVA_17 */ public static boolean isAtLeastJava15() { return getMajorJavaVersion() >= JAVA_15; } /** * Convenience method to determine if the current JVM is at least * Java 1.6 (Java 6). * * @return <code>true</code> if the current JVM is at least Java 1.6 * @see #getMajorJavaVersion() * @see #JAVA_16 * @see #JAVA_17 */ public static boolean isAtLeastJava16() { return getMajorJavaVersion() >= JAVA_16; }}至此,spring2.5 与 jdk8 的兼容性问题成功解决。 4.2 hibernate 的问题

运行时,抛 hibernate 错误:

Caused by: java.io.FileNotFoundException: class path resource [hibernate] cannot be resolved to URL because it does not exist at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:163) at org.springframework.core.io.ClassPathResource.getFile(ClassPathResource.java:175) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:660) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 76 more

指的是 hibernate 找不到资源路径。因为 这个项目的 hibernate 资源文件夹下没有文件,而 idea 在开发部署时是不会创建没有包含文件的文件夹的,所以就抛错咯。

手工新建一个无用的 txt 文件即可解决这个问题。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。