0

I'm new to intellij idea and maven, and we recently added/used it to build a legacy java project. The original developers have left the company and I haven't used java in 20 years and didn't use these tools, and frankly it was in college (things have changed). We got the project building, and dependencies are resolved, and it has a pom.xml file now, and it generates a jar file according to the artifactId and version in the pom file, in the target dir, and it's 18 kb. However, the original jar file has not rebuilt, and I can see it in a higher project dir and it's 5049 kb. That 5049 kb jar file is what was living on the server (*and it's not rebuilding). We are updating the server name/cred in a file that, and I'm concerned that the 5049 kb file needs to rebuild to reflect the modified cred ini file. I'm not sure if it makes a difference, but this is the project dir structure:

*ServiceNow
   DbCred.ini
   ServiceNowTask

   SourceCode

   ServiceNowTAsk
    src
       main>java>Task>ServiceNowTask>old java files to build
    target
      ServiceNowTAsk-1-snapshot.jar (new date, 18 kb)
    .classpath
    .project
    pom.xml
    ServiceNowTask.iml
    ServiceNowTask.jar (old date, 5049 kb)

(read this, ServiceNow is the main dir, with DbCred and ServiceNowTask under it, and under ServiceNowTask is SourceCode, and under that is ServiceNowTask, src, target, ServiceNowTask.iml, ServiceNowTask.jar. etc.) There are other ServiceNow projects at the level of ServiceNowTask, and each contains java files with main, so I think they need to be built separately to create the separate jar files.

The pom file looks like this (do I need to add ServiceNowTask.jar to the pom file?):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>Task</groupId>
  <artifactId>ServiceNowTask</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>ServiceNowTask</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <java.version>18</java.version>
      <maven.compiler.source>18</maven.compiler.source>
      <maven.compiler.target>18</maven.compiler.target>
  </properties>

  <dependencies>
  
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.3</version>
    </dependency>
    <dependency>
      <groupId>com.googlecode.json-simple</groupId>
      <artifactId>json-simple</artifactId>
      <version>1.1.1</version>
   </dependency>
      <dependency>
          <groupId>org.ini4j</groupId>
          <artifactId>ini4j</artifactId>
          <version>0.5.4</version>
      </dependency>

  </dependencies>
</project>

My question is, how do I get it to rebuild all jar files, specifically that 5049 kb one that isn't rebuilding?

Update I changed the pom file to this but there are errors:

[ERROR] Malformed POM C:\Users\xxx\OneDrive - Company, Inc\Documents\2022\Java\ServiceNow\ServiceNowTask\SourceCode\ServiceNowTask\pom.xml: Unrecognised tag: 'packaging' (position: START_TAG seen ...</version>\r\n              <packaging>... @11:26)  @ C:\Users\xxx\OneDrive - Company, Inc\Documents\2022\Java\ServiceNow\ServiceNowTask\SourceCode\ServiceNowTask\pom.xml, line 11, column 26
[FATAL] 'groupId' is missing. @ line 2, column 102
[FATAL] 'artifactId' is missing. @ line 2, column 102
[FATAL] 'version' is missing. @ line 2, column 102
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project [unknown-group-id]:[unknown-artifact-id]:[unknown-version] (C:\Users\xxx\OneDrive - Company, Inc\Documents\2022\Java\ServiceNow\ServiceNowTask\SourceCode\ServiceNowTask\pom.xml) has 4 errors
[ERROR]     Malformed POM C:\Users\xxx\OneDrive - Company, Inc\Documents\2022\Java\ServiceNow\ServiceNowTask\SourceCode\ServiceNowTask\pom.xml: Unrecognised tag: 'packaging' (position: START_TAG seen ...</version>\r\n              <packaging>... @11:26)  @ C:\Users\xxx\OneDrive - Company, Inc\Documents\2022\Java\ServiceNow\ServiceNowTask\SourceCode\ServiceNowTask\pom.xml, line 11, column 26 -> [Help 2]
[ERROR]     'groupId' is missing. @ line 2, column 102
[ERROR]     'artifactId' is missing. @ line 2, column 102

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

    <build>
        <plugins>
            <plugin>
              <groupId>Task</groupId>
              <artifactId>ServiceNowTask</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <packaging>jar</packaging>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>
  <name>ServiceNowTask</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <java.version>18</java.version>
      <maven.compiler.source>18</maven.compiler.source>
      <maven.compiler.target>18</maven.compiler.target>
  </properties>

  <dependencies>
  
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.3</version>
    </dependency>
    <dependency>
      <groupId>com.googlecode.json-simple</groupId>
      <artifactId>json-simple</artifactId>
      <version>1.1.1</version>
   </dependency>
      <dependency>
          <groupId>org.ini4j</groupId>
          <artifactId>ini4j</artifactId>
          <version>0.5.4</version>
      </dependency>

  </dependencies>
</project>
Michele
  • 3,617
  • 12
  • 47
  • 81
  • Run `mvn package` either in the Terminal or from the Maven tool window in the IDE? – CrazyCoder Sep 12 '22 at 19:22
  • I have run maven package under lifecycle in the Maven are to the right. That's what creates the jar file that is named according to the pom file, but it isn't updating the 5049 kb jar file. – Michele Sep 12 '22 at 19:23
  • 1
    No one knows how that file was built. Maven/IntelliJ IDEA is not supposed to update it. You can try creating an artifact with all the dependencies included in the jar per https://www.jetbrains.com/help/idea/artifacts.html and see if it works. – CrazyCoder Sep 12 '22 at 19:24
  • 1
    If you want Maven to build the artifact with all the dependent jars unpacked inside it, see https://stackoverflow.com/questions/16222748/building-a-fat-jar-using-maven. – CrazyCoder Sep 12 '22 at 19:28
  • So far I did what's at the jetbrains artifacts link, and rebuilt, and did the artifact step, and package under maven, and it didn't change the jar file size to reflect that 5049 kb that the old one was...still 18 kb. No new one appeared either, that I can see. – Michele Sep 12 '22 at 19:48
  • 1
    You may want to hire a consultant to get your build environment fixed correctly. The money will be very well spent. – Thorbjørn Ravn Andersen Sep 12 '22 at 19:54
  • Default artifact generated by IntelliJ IDEA will match the Maven configuration. You can create a new custom artifact with the dependencies included. – CrazyCoder Sep 12 '22 at 20:02
  • @CrazyCoder - it's giving errors with the pom file format with the changes in that stackoverflow question. Any ideas? See update above. – Michele Sep 12 '22 at 20:16
  • You removed some required tags as explained in the error message. They were present in your original pom.xml. – CrazyCoder Sep 12 '22 at 20:18

0 Answers0